-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (47 loc) · 877 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
yaml "gopkg.in/yaml.v2"
"github.com/whomm/hrproxy/httptool"
)
//限流item
type Limit struct {
Path string
Qps float64
Code int
Msg string
}
//配置
type Conf struct {
Listen string
Backservices string
Limitlist []Limit
}
var conffile = flag.String("c", "", "confige file like def.yaml")
func main() {
flag.Parse()
if len(*conffile) < 1 {
flag.PrintDefaults()
os.Exit(1)
}
confbytes, err := ioutil.ReadFile(*conffile)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
conf := Conf{}
err = yaml.Unmarshal(confbytes, &conf)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
serv := httptool.NewServer(conf.Listen, conf.Backservices)
for _, i := range conf.Limitlist {
serv.Handler(i.Path, i.Qps, i.Code, i.Msg, nil)
}
fmt.Println("start success")
serv.ListenAndServe()
}