-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
135 lines (118 loc) · 3.28 KB
/
main.go
File metadata and controls
135 lines (118 loc) · 3.28 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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main
import (
"errors"
"fmt"
"github.com/gin-gonic/gin"
swaggerFiles "github.com/swaggo/files"
ginSwagger "github.com/swaggo/gin-swagger"
C "github.com/ycyun/Cube-API/controller"
//Cube "github.com/ycyun/Cube-API/cube/action"
Dashboard "github.com/ycyun/Cube-API/dashboard/action"
"github.com/ycyun/Cube-API/docs"
Glue "github.com/ycyun/Cube-API/glue/action"
Mold "github.com/ycyun/Cube-API/mold/action"
PCS "github.com/ycyun/Cube-API/pcs/action"
UTILS "github.com/ycyun/Cube-API/utils"
"log"
"time"
)
// @title Cube API
// @version 1.0
// @description This is a Cube-API server.
// @termsOfService https://ablecloud.io/
// @contact.name API Support
// @contact.url https://www.ablecloud.io/support
// @contact.email ycyun@ablecloud.io
// @license.name Apache 2.0
// @license.url https://www.apache.org/licenses/LICENSE-2.0.html
// @ssshost 10.211.55.11:8080
// @BasePath /api/v1
// @Schemes http https
// @securityDefinitions.basic None
// @externalDocs.description ABLECLOUD
// @externalDocs.url https://www.ablecloud.io
func main() {
// 시간대 설정
location, err := time.LoadLocation("Asia/Seoul")
if err != nil {
panic(err)
}
// Set the timezone for the current process
time.Local = location
c := C.Init()
c.LoadConfig()
//c.StatusRegister(Mold.MonitorStatus)
c.StatusRegister(Glue.Monitor)
//c.StatusRegister(Dashboard.Monitor)
c.StatusRegister(PCS.Monitor)
c.StatusRegister(Cube.Hosts.Update)
c.StatusRegister(Cube.NICs.Update)
c.StatusRegister(Cube.Disks.Update)
c.StatusRegister(C.SaveConfig)
go c.Start()
APIPort := "8080"
docs.SwaggerInfo.Schemes = []string{"http", "https"}
docs.SwaggerInfo.Host = UTILS.GetLocalIP().String() + ":" + APIPort
log.SetFlags(log.LstdFlags | log.Lshortfile)
r := gin.Default()
//gin.SetMode(gin.DebugMode)
gin.SetMode(gin.ReleaseMode)
r.ForwardedByClientIP = true
err = r.SetTrustedProxies(nil)
if err != nil {
c.AddError(err)
}
r.Use(gin.Logger())
// Recovery 미들웨어는 panic이 발생하면 500 에러를 씁니다.
r.Use(gin.Recovery())
v1 := r.Group("/api/v1")
{
v1.GET("/neighbor", c.GetNeighbor)
v1.GET("/neighbor/info", c.GetNeighborInfo)
v1.POST("/neighbor", c.PutNeighbor)
v1.PUT("/neighbor", c.PutNeighbor)
v1.DELETE("/neighbor", c.DeleteNeighbor)
cube := v1.Group("/cube")
{
cube.GET("/hosts", Cube.Hosts.Get)
cube.GET("/test", Cube.Hosts.Get)
cube.GET("/nics", Cube.NICs.Get)
cube.GET("/disk", Cube.Disks.Get)
}
glue := v1.Group("/glue")
{
glue.GET("/", Glue.GetGlueStatus)
glue.GET("/auth", Glue.GetGlueAuth)
glue.GET("/auth/:username", Glue.GetGlueAuth)
glue.GET("/auths", Glue.GetGlueAuths)
}
mold := v1.Group("/mold")
{
mold.GET("", Mold.GetStatus)
mold.GET("/ccvm", Mold.GetCCVMInfo)
}
pcs := v1.Group("/pcs")
{
pcs.GET("", PCS.GetStatus)
pcs.GET("/resources", PCS.GetResource)
}
dashboard := v1.Group("/dashboard")
{
dashboard.GET("", Dashboard.GetStatus)
}
//v1.Any("/version", Cube.Version)
v1.GET("/err", c.Error)
v1.DELETE("/err", c.DeleteError)
v1.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
}
err = r.Run(":" + APIPort)
if err != nil {
c.AddError(err)
}
c.Stop()
fmt.Println("end")
}
func errorMaker() {
c := C.Init()
c.AddError(errors.New(time.Now().String()))
}