-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
84 lines (62 loc) · 2.33 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
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/airdb/sailor/dbutil"
"github.com/airdb/sailor/deployutil"
"github.com/airdb/sailor/faas"
"github.com/airdb/sls-bbhj/internal/app"
"github.com/airdb/sls-bbhj/internal/controller"
"github.com/airdb/sls-bbhj/internal/repository/mysql"
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/go-chi/render"
_ "github.com/swaggo/http-swagger/example/go-chi/docs" // docs is generated by Swag CLI, you have to import it.
)
const project = "bbhj"
// @title Airdb Serverlesss Example API
// @version 0.0.1
// @description 宝贝回家小程序后端, 遵循 restful api 规范.
// @termsOfService https://airdb.github.io/terms.html
// @contact.name APIs Support
// @contact.url https://work.weixin.qq.com/kfid/kfc02343d9ba414880a?sence=swagger
// @contact.email [email protected]
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @info.x-logo.url: http://www.apache.org/licenses/LICENSE-2.0.html
// @host service-iw6drlfr-1251018873.sh.apigw.tencentcs.com
// @BasePath /test/mina
// @schemes https
func main() {
log.Println("start serverless:", deployutil.GetDeployStage(), os.Environ())
app.InitApp()
mysqlRepo, err := mysql.GetFactoryOr(dbutil.WriteDefaultDB())
if err != nil {
log.Panic(err)
}
mux := chi.NewRouter()
mux.Use(middleware.Logger)
mux.Use(render.SetContentType(render.ContentTypeJSON))
// p := filepath.Join("/", deployutil.GetDeployStage(), "/", project)
p := fmt.Sprintf("/%s", project)
mux.Route(p, func(r chi.Router) {
r.Get("/version", faas.HandleVersion)
r.Get("/wechat/check_session", controller.CheckSession)
categoryController := controller.NewCategoryController(mysqlRepo)
r.Mount("/v1/category", categoryController.Routes())
lostController := controller.NewLostController(mysqlRepo)
r.Mount("/v1/lost", lostController.Routes())
r.Get("/v1/lost:uploadPresignedUrl", lostController.GetUploadPresignedURL)
rescueController := controller.NewRescueController(mysqlRepo)
r.Mount("/v1/rescue", rescueController.Routes())
passportController := controller.NewPassportController(mysqlRepo)
r.Post("/v1/passport:login", passportController.Login)
})
if os.Getenv("RUN_MODE") == "local" {
http.ListenAndServe(":3333", mux)
} else {
faas.RunTencentChiWithSwagger(mux, project)
}
}