-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
65 lines (53 loc) · 1.25 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
65
package main
import (
"flag"
"fmt"
"net/http"
"os"
"runtime"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
"github.com/labstack/gommon/log"
"github.com/yangbinnnn/messenger/g"
"github.com/yangbinnnn/messenger/handler"
)
// 0.0.2 use echo
// 0.0.3 refactor handler and sender.mail
// 0.0.4 add weixin group msg
const (
VERSION = "0.0.4"
)
func prepare() {
runtime.GOMAXPROCS(runtime.NumCPU())
}
func main() {
prepare()
version := flag.Bool("v", false, "show version")
cfg := flag.String("c", "cfg.json", "config path")
flag.Parse()
if *version {
fmt.Println(VERSION)
os.Exit(0)
}
g.Parse(*cfg)
app := echo.New()
app.Logger.SetLevel(log.ERROR)
app.Debug = g.Config().Debug
app.Use(middleware.Logger())
addr := g.Config().Http.Listen
if addr == "" {
return
}
h := &handler.Handler{}
h.Prepre()
app.GET("/version", func(c echo.Context) error {
return c.String(http.StatusOK, VERSION)
})
app.GET("/healthy", func(c echo.Context) error {
return c.String(http.StatusOK, "OK")
})
app.Match([]string{"GET", "POST"}, "/sender/mail", h.SendMail)
app.Match([]string{"GET", "POST"}, "/sender/wechat", h.SendWeChat)
app.Match([]string{"GET", "POST"}, "/sender/wechat/create", h.NewChatGroup)
log.Fatal(app.Start(addr))
}