-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (37 loc) · 871 Bytes
/
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
package main
import (
"strconv"
"github.com/labstack/echo"
"github.com/labstack/echo/middleware"
)
var CF Config
var mssql MssqlDB
func init() {
// initial Config
CF.GetByENV()
mssql = MssqlDB{db: NewMssql()}
}
func main() {
e := echo.New()
// middleware
CustomMiddle(e)
// routes
e.GET("/", GetProfileHandler)
e.GET("/test", func(c echo.Context) error {
if mssql.ExistUsername("burnhee444") {
// if mssql.ExistUsername("sjtoday") {
return c.String(200, "ok")
}
return c.String(200, "not found.")
})
// server start
e.Logger.Fatal(e.Start(":" + strconv.Itoa(CF.Port)))
}
func CustomMiddle(e *echo.Echo) {
e.Use(middleware.Recover())
e.Use(middleware.Secure())
e.Use(middleware.CORSWithConfig(middleware.CORSConfig{
AllowOrigins: []string{"*"},
AllowMethods: []string{echo.GET, echo.HEAD, echo.PUT, echo.POST, echo.DELETE},
}))
}