-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
53 lines (39 loc) · 1.3 KB
/
main.go
File metadata and controls
53 lines (39 loc) · 1.3 KB
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
import (
"flag"
"os"
"path/filepath"
"time"
"github.com/alecthw/sub-server/handler"
"github.com/alecthw/sub-server/log"
ginzap "github.com/gin-contrib/zap"
"github.com/gin-gonic/gin"
"github.com/go-resty/resty/v2"
"go.uber.org/zap"
)
var (
workDir string
host string
subconvUrl string
managedConfigPrefix string
)
func init() {
dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
flag.StringVar(&workDir, "dir", dir, "The wroking directory. Default executable file directory.")
flag.StringVar(&host, "host", ":8080", "Http server bind host. Default \":8080\"")
flag.StringVar(&subconvUrl, "subcnv", "http://127.0.0.1:25500", "subconverter server bind host. Default \"http://127.0.0.1:25500\"")
flag.StringVar(&managedConfigPrefix, "mcp", "", "Set MANAGED-CONFIG for surge and surfboard. If emty, MANAGED-CONFIG will not be set. Default \"\"")
flag.Parse()
gin.SetMode("release")
}
func main() {
client := resty.New()
handler.Init(workDir, subconvUrl, managedConfigPrefix, client)
r := gin.New()
r.Use(ginzap.Ginzap(log.Logger, time.RFC3339, true))
r.Use(ginzap.RecoveryWithZap(log.Logger, true))
zap.S().Infow("main")
r.GET("/provider/:provider", handler.ProviderHandler)
r.GET("/:uuid/:file", handler.SubscribeHandler)
_ = r.Run(host)
}