-
Notifications
You must be signed in to change notification settings - Fork 99
/
main.go
64 lines (52 loc) · 1.04 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
63
64
package main
import (
"flag"
"fmt"
"net"
"net/http"
"github.com/eolinker/eosc/log"
"github.com/eolinker/go-common/autowire"
"github.com/eolinker/go-common/cftool"
"github.com/eolinker/go-common/permit"
"github.com/eolinker/go-common/server"
)
var (
version string
confPath string
)
func init() {
flag.StringVar(&confPath, "c", "config.yml", "`config` file path for server ")
}
type ServerConfig struct {
Port int `yaml:"port"`
}
func main() {
doCheck()
flag.Parse()
cf := new(ServerConfig)
cftool.Register(fmt.Sprintf("root:%s", confPath), cf)
cftool.ReadFile(confPath)
ser := server.CreateServer()
err := autowire.CheckComplete()
if err != nil {
log.Fatal("check autowired:", err)
return
}
if cf.Port == 0 {
log.Fatal("need port")
}
ln, err := net.Listen("tcp", fmt.Sprintf(":%d", cf.Port))
if err != nil {
log.Fatal(err)
return
}
srv := ser.Build()
for access, paths := range srv.Permits() {
permit.AddPermitRule(access, paths...)
}
err = http.Serve(ln, srv)
if err != nil {
log.Fatal(err)
return
}
}