-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
106 lines (86 loc) · 3.03 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package main
import (
"embed"
"github.com/retail-ai-inc/beanqui/internal/redisx"
. "github.com/retail-ai-inc/beanqui/internal/routers"
"github.com/spf13/viper"
"io/fs"
"log"
"net/http"
)
var (
port string = ":9090"
)
func init() {
viper.AddConfigPath("./")
viper.SetConfigName("env")
viper.SetConfigType("json")
if err := viper.ReadInConfig(); err != nil {
log.Fatalln(err)
}
//Initialize configuration information
if err := viper.Unmarshal(&redisx.BqConfig); err != nil {
log.Fatalf("viper unmarshal err:%+v \n", err)
}
}
//go:embed ui
var folder embed.FS
func main() {
//flag.StringVar(&port, "port", ":9090", "port")
//flag.Parse()
// init http server
router := NewRouter()
// FS static files
router.File("/", HeaderRule(func(ctx *BeanContext) error {
fd, err := fs.Sub(folder, "ui")
if err != nil {
log.Fatalf("static files error:%+v \n", err)
}
http.FileServer(http.FS(fd)).ServeHTTP(ctx.Writer, ctx.Request)
return nil
}))
router.Get("/ping", HeaderRule(ping))
router.Get("/schedule", MigrateMiddleWare(NewSchedule().List))
router.Get("/queue/list", MigrateMiddleWare(NewQueue().List))
router.Get("/queue/detail", MigrateMiddleWare(NewQueue().Detail))
router.Get("/logs", MigrateMiddleWare(NewLogs().List))
router.Get("/log", MigrateMiddleWare(NewLog().List))
router.Get("/redis", MigrateMiddleWare(NewRedisInfo().Info))
router.Get("/redis/monitor", MigrateMiddleWare(NewRedisInfo().Monitor))
router.Post("/login", HeaderRule(NewLogin().Login))
router.Get("/clients", MigrateMiddleWare(NewClient().List))
router.Get("/dashboard", MigrateMiddleWare(NewDashboard().Info))
router.Get("/event_log/list", MigrateMiddleWare(NewEventLog().List))
router.Get("/event_log/detail", MigrateMiddleWare(NewEventLog().Detail))
router.Post("/event_log/delete", MigrateMiddleWare(NewEventLog().Delete))
router.Post("/event_log/edit", MigrateMiddleWare(NewEventLog().Edit))
router.Post("/event_log/retry", MigrateMiddleWare(NewEventLog().Retry))
router.Get("/user/list", MigrateMiddleWare(NewUser().List))
router.Post("/user/add", MigrateMiddleWare(NewUser().Add))
router.Post("/user/del", MigrateMiddleWare(NewUser().Delete))
router.Post("/user/edit", MigrateMiddleWare(NewUser().Edit))
router.Get("/googleLogin", NewLogin().GoogleLogin)
router.Get("/callback", NewLogin().GoogleCallBack)
router.Get("/dlq/list", MigrateMiddleWare(NewDlq().List))
log.Printf("server start on port %+v", port)
if err := http.ListenAndServe(port, router); err != nil {
log.Fatalln(err)
}
}
func ping(ctx *BeanContext) error {
// clientId := r.Header.Get("Client-Id")
// clientSecret := r.Header.Get("Client-Secret")
//
// if clientId == "" || clientSecret == "" {
// w.WriteHeader(http.StatusUnauthorized)
// return
// }
// if clientId != viper.GetString("auth.clientId") || clientSecret != viper.GetString("auth.clientSecret") {
// w.WriteHeader(http.StatusUnauthorized)
// _, _ = w.Write([]byte("No permission"))
// return
// }
ctx.Writer.WriteHeader(http.StatusOK)
_, _ = ctx.Writer.Write([]byte("pong"))
return nil
}