-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (38 loc) · 1.05 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"fmt"
"github.com/sethvargo/go-limiter"
"github.com/sethvargo/go-limiter/memorystore"
"log"
"net/http"
"time"
"wildlife-challenge/handlers"
"wildlife-challenge/middleware"
)
func main() {
// If you are reading this I'm really sorry
// This repo is pretty messy code and not really how I code usually.
// I had to both learn go on the go (heh) and implement a dsp in a day. Also generics when pls.
s, s2 := configLimiters()
http.Handle("/bid", middleware.Wrap(&handlers.BidHandler{}, []limiter.Store{s, s2}))
http.Handle("/imp", &handlers.ImpHandler{})
fmt.Println("Starting server...")
log.Fatal(http.ListenAndServe(":8080", nil))
}
func configLimiters() (limiter.Store, limiter.Store) {
s, err := memorystore.New(&memorystore.Config{
Tokens: 5,
Interval: time.Minute * 1,
})
if err != nil { // TODO: should use github.com/hashicorp/go-multierror
log.Fatal(err)
}
s2, err := memorystore.New(&memorystore.Config{
Tokens: 10,
Interval: time.Minute * 3,
})
if err != nil {
log.Fatal(err)
}
return s, s2
}