-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
53 lines (46 loc) · 1.37 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
package main
import (
"flag"
"fmt"
"github.com/funceasy/gateway/middleware"
"github.com/funceasy/gateway/router"
"github.com/gin-gonic/gin"
"os"
)
func main() {
var env *string
env = flag.String("env", "dev", "run env")
flag.Parse()
fmt.Println(*env)
port := os.Getenv("FUNCEASY_GATEWAY_SERVICE_PORT")
if port == "" {
port = ":8082"
} else {
port = ":" + port
}
proxyHost := "localhost:8001"
r := gin.Default()
r.Use(middleware.ErrorHandler)
r.Use(middleware.Authentication(*env))
r.Use(middleware.GetCRDClient(*env))
r.Use(middleware.DataSourceAuthentication(*env))
r.Use(middleware.DataSourceService(*env))
config := r.Group("/config")
config.GET("/", router.GetConfig)
function := r.Group("/function")
function.POST("/call/:id", router.FunctionCall(*env, proxyHost, "POST"))
function.GET("/call/:id", router.FunctionCall(*env, proxyHost, "GET"))
function.GET("/instance/:id", router.GetFunctionCR)
function.POST("/create/:id", router.CreateFunctionCR)
function.PUT("update/:id", router.UpdateFunctionCR)
function.DELETE("/delete/:id", router.DeleteFunctionCR)
function.GET("/logs/:id", router.FunctionLogs)
dataSource := r.Group("/dataSource")
dataSource.POST("/create", router.CreateDataSource)
dataSource.POST("/update", router.UpdateDataSource)
dataSource.DELETE("/:id", router.DeleteDataSource)
err := r.Run(port)
if err != nil {
panic(err)
}
}