系统资源及路由配置

2019-08-15  本文已影响0人  funcx
package main

import (
    "log"

    "github.com/gin-gonic/gin"
)

func main() {
    engin := gin.Default()
    router := Engin(engin)
    router("学生", "查询", "/student", func(ctx *gin.Context) {
        ctx.String(200, "hah")
    })
    router("学生1", "查询1", "/student1", func(ctx *gin.Context) {
        ctx.String(200, "hah")
    })
    engin.Run(":9000")
}

func Engin(router *gin.Engine) func(resName, oper, relativePath string, handlers ...gin.HandlerFunc) {
    return func(resName, oper, relativePath string, handlers ...gin.HandlerFunc) {
        IniHandle(router, relativePath, handlers...)
        IniResource(resName, oper, relativePath)
    }
}

// 配置系统资源
func IniResource(resName, oper, relativePath string) {
    log.Println("系统资源:", resName, oper, relativePath)
}

// 配置和资源操作
func IniHandle(engin *gin.Engine, relativePath string, handlers ...gin.HandlerFunc) {
    engin.POST(relativePath, handlers...)
}
上一篇下一篇

猜你喜欢

热点阅读