-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
62 lines (53 loc) · 1.22 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package main
import (
"flag"
"github.com/EE-Tools/ApiProxy/proxy"
_ "github.com/EE-Tools/goauth/models/db"
"log"
"net/http"
"time"
)
// listen http port
var port = flag.String("port", "8080", "http serve port")
var mode = flag.String("mode", "debug", "project run mode,default is debug")
var initLogFolder = flag.String("log", "", "project log folder")
func init() {
flag.Parse()
}
// entry point.
func main() {
// startup info.
log.Println("run mode is", *mode)
log.Println("startup and listen", *port)
// init log
proxy.InitAccessLogger(*initLogFolder)
// declare work handler
hlist := []proxy.Handler{
// print debug log handler
&proxy.DebugHandler{},
&proxy.OauthCheckHandler{},
&proxy.ProxyHandler{},
}
// register handler
s := &http.Server{
Addr: ":" + *port,
Handler: &DefaultHandleChain{
HandleList: hlist,
},
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
log.Fatal(s.ListenAndServe())
}
type DefaultHandleChain struct {
HandleList []proxy.Handler
}
func (this *DefaultHandleChain) ServeHTTP(w http.ResponseWriter, r *http.Request) {
for _, handle := range this.HandleList {
run := handle.ServeHTTP(w, r)
if !run {
break
}
}
}