-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
41 lines (31 loc) · 850 Bytes
/
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
package main
import (
"fmt"
"log"
"net/http"
"simple-rate-limiting/config"
"simple-rate-limiting/redisratelimit"
)
var rdb *redisratelimit.Client
var env config.Environment
func init() {
env = config.InitEnvironment()
log.Printf("InitEnvironment::%+v\n", env)
conf := redisratelimit.Config{
Address: env.RedisAddress,
Password: env.RedisPassword,
DB: env.RedisDB,
DialTimeOutSeconds: env.RedisDialTimeOutSeconds,
PoolSize: env.RedisPoolSize,
}
rdb = redisratelimit.NewClient(conf)
}
func main() {
mux := http.NewServeMux()
mux.HandleFunc("/", helloHandler)
log.Printf("Listening on :%d", env.PortNumber)
http.ListenAndServe(fmt.Sprintf(":%d", env.PortNumber), limit(mux))
}
func helloHandler(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello World!"))
}