/
server.go
51 lines (39 loc) · 1008 Bytes
/
server.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
// Author: yangzq80@gmail.com
// Date: 2021-03-16
package server
import (
"github.com/gin-contrib/static"
"github.com/gin-gonic/gin"
"github.com/yusys-cloud/ai-tools/conf"
"github.com/yusys-cloud/ai-tools/server/web"
"github.com/yusys-cloud/go-jsonstore-rest/rest"
)
type Server struct {
cf *conf.Conf
}
func NewServer(cf *conf.Conf) *Server {
return &Server{cf}
}
func (s *Server) Start() {
s.startApiServer()
}
func (s *Server) startApiServer() {
if s.cf.Mode == "pro" {
gin.SetMode(gin.ReleaseMode)
}
engine := gin.Default()
//Needed in order to disable CORS for local development
if s.cf.Mode == "dev" {
engine.Use(web.DisableCors())
//config := cors.DefaultConfig()
//config.AllowAllOrigins = true
//engine.Use(cors.New(config))
}
engine.Use(static.Serve("/", static.LocalFile("./ui", false)))
s.ConfigHandles(engine)
rs := rest.NewJsonStoreRest(s.cf.Path)
rs.DisableCors = true
rs.ConfigHandles(engine)
ConfigUserHandles(engine)
engine.Run(":" + s.cf.Port)
}