/
main.go
53 lines (44 loc) · 916 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
package main
/*
echo web frame curd operator
*/
import (
"log"
"strings"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
var Cfg *SvcCfg
func init() {
Cfg = &SvcCfg{}
}
func main() {
e := echo.New()
e.Logger.SetLevel(4)
// Middleware
e.Use(middleware.Logger())
e.Use(middleware.Recover())
// Routes
e.GET("/remotelog/list", GetLogList)
e.GET("/remotelog/list/:id", GetLogData)
e.POST("/remotelog/log/list", CreateLogList)
e.POST("/remotelog/log/detail", CreateLogDetail)
/*
//save routers to file
data, err := json.MarshalIndent(e.Routes(), "", " ")
if err != nil {
fmt.Println(err)
}
ioutil.WriteFile("routes.json", data, 0644)
*/
//load cfg
Parse("./echo.yaml", Cfg)
log.Println(Cfg)
if strings.EqualFold(Cfg.Http, "") {
log.Fatal("cfg load err")
}
//init pub
InitPub(Cfg.Nsq_tcp)
// Start server
e.Logger.Fatal(e.Start(Cfg.Http)) //":8080"
}