数据上报
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

38 lines
962 B

package dbHelper
import (
"fmt"
"github.com/gin-gonic/gin"
"log"
"net/http"
"time"
)
type RouterFunc struct {
relativePath string //相对路由 如/gzm/data/upload
funcType string // 方法类型 如 post ,get
fun func(c *gin.Context) //方法
}
type ApiServerHelper struct {
Port uint16
RoutFun map[string]RouterFunc
}
func (the *ApiServerHelper) Initial() {
router := gin.Default()
for name, routerFunc := range the.RoutFun {
switch routerFunc.funcType {
case http.MethodGet:
router.GET(routerFunc.relativePath, routerFunc.fun)
case http.MethodPost:
router.GET(routerFunc.relativePath, routerFunc.fun)
default:
log.Printf("不支持的 [%s]方法类型 %s", routerFunc.relativePath, routerFunc.funcType)
continue
}
log.Printf("注册路由 %s,监听地址=%s", name, routerFunc.relativePath)
}
router.Run(fmt.Sprintf("0.0.0.0:%d", the.Port))
time.Sleep(time.Second * 1)
}