-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (54 loc) · 1.92 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
package main
import (
"github.com/linxlib/fw"
"github.com/linxlib/fw/middlewares"
"github.com/linxlib/fw_example/controllers"
middlewares2 "github.com/linxlib/fw_example/middlewares"
"github.com/linxlib/fw_example/models"
"github.com/sirupsen/logrus"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"time"
)
//go:generate go run github.com/linxlib/astp/astpg -o gen.json
var _ controllers.HelloController
func main() {
//os.Setenv("FW_DEV", "false")
s := fw.New()
s.Use(middlewares.NewServerDownMiddleware("111"))
s.Use(middlewares.NewWebsocketMiddleware())
s.Use(middlewares.NewWebsocketHubMiddleware())
var logger = logrus.New()
s.Provide(logger)
s.Use(middlewares.NewLoggerMiddleware(logger))
//s.Use(middlewares.NewResponseRewriteMiddleware())
s.Use(middlewares.NewRecoveryMiddleware(&middlewares.RecoveryOptions{
NiceWeb: true,
Console: true,
}, nil))
s.Use(middlewares.NewBasicAuthMiddleware())
// connect mysql
db, err := gorm.Open(mysql.Open("root:root@tcp(10.10.0.16:3306)/wanshengserver?charset=utf8mb4&parseTime=True&loc=Local"), &gorm.Config{})
if err != nil {
panic(err)
}
dbmid := middlewares2.NewMySQLMiddleware(db)
s.Use(dbmid)
s.Use(middlewares2.NewRedisMiddlewareWithUrl("redis://10.10.0.16:6379/1"))
s.Use(middlewares.NewCorsMiddleware(middlewares.Config{
AllowOrigins: []string{"http://www.example.com:5500"},
AllowMethods: []string{"POST", "HEAD", "OPTIONS"},
AllowHeaders: []string{"Origin", "Content-Length", "Content-Type"},
AllowCredentials: false,
MaxAge: 12 * time.Hour,
}))
s.RegisterRoute(new(controllers.HelloController))
s.RegisterRoute(new(controllers.WebsocketHubController))
s.RegisterRoute(new(controllers.BasicAuthController))
s.RegisterRoute(new(controllers.RedisController))
s.RegisterRoute(new(controllers.CorsController))
db.AutoMigrate(new(models.AdminUser))
s.RegisterRoute(controllers.NewUserCrud2Controller(db))
s.Map(dbmid.GetDB())
s.Run()
}