-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (43 loc) · 1.01 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
package main
import (
"net"
"net/http"
"os"
"runtime"
"github.com/zjx20/hcfy-gemini/cjsfy"
"github.com/zjx20/hcfy-gemini/config"
"github.com/zjx20/hcfy-gemini/hcfy"
"github.com/zjx20/hcfy-gemini/util/middleware"
"github.com/go-chi/chi/v5"
log "github.com/sirupsen/logrus"
)
func init() {
log.SetLevel(config.GetLogLevel())
log.SetOutput(os.Stdout)
log.SetFormatter(&log.TextFormatter{
DisableColors: runtime.GOOS == "windows",
FullTimestamp: true,
TimestampFormat: "2006-01-02 15:04:05",
})
config.AddConfigChangeCallback(func() {
log.SetLevel(config.GetLogLevel())
})
}
func main() {
if noConf := os.Getenv("NO_CONFIG_FILE"); noConf == "" {
config.Init()
}
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Use(middleware.Recover)
r.Post("/api/hcfy", hcfy.Handle)
r.Post("/api/cjsfy", cjsfy.Handle)
l, err := net.Listen("tcp", ":7458")
if err != nil {
log.Fatalln(err)
}
log.Infof("Server listening at %s", l.Addr())
if err = http.Serve(l, r); err != nil {
log.Fatalln(err)
}
}