代码拉取完成,页面将自动刷新
package rui
import (
"fmt"
"net/http"
"path"
"github.com/go-playground/validator/v10"
"gitee.com/ruige_fun/util/rlog"
"github.com/julienschmidt/httprouter"
)
type application struct {
router *httprouter.Router //路由器
all []RouterItem //所有请求信息
logLevel int //日志打印等级
routerGroup //分组路由器
vd *validator.Validate //验证器
}
// New 新建一个服务
// logLevel 日志打印等级:调试 0;信息 1;警告 2;错误 3;恐慌 4;不打印 5
func New(logLevel int) Application {
app := application{
router: httprouter.New(),
all: make([]RouterItem, 0, 10),
logLevel: logLevel,
routerGroup: routerGroup{
prevPath: "/",
handlers: make([]func(Context), 0, 10),
app: nil,
},
}
app.routerGroup.app = &app
return &app
}
func (app *application) Group(urlPath string) RouterGroup {
return &routerGroup{
prevPath: path.Join(app.routerGroup.prevPath, urlPath),
handlers: app.routerGroup.handlers,
app: app,
}
}
func (app *application) Run(host string, port uint) (err error) {
rlog.InfoP(rlog.ModelNoPath, "启动服务", getLocationIP("http", host, port))
return http.ListenAndServe(fmt.Sprint(host, ":", port), app.router)
}
func (app *application) RunTLS(host string, port uint, certFile string, keyFile string) error {
rlog.InfoP(rlog.ModelNoPath, "启动服务", getLocationIP("https", host, port))
return http.ListenAndServeTLS(fmt.Sprint(host, ":", port), certFile, keyFile, app.router)
}
// OpenValidator 开启验证器
// 具体的验证规则,请查看:https://pkg.go.dev/github.com/go-playground/validator/v10#hdr-Multiple_Validators
func (app *application) OpenValidator() {
app.vd = validator.New()
}
type RouterItem struct {
URL string `json:"url"` //请求路径
Method string `json:"method"` //请求方法
CodeRow string `json:"code_row"` //注册代码行
}
func (app *application) AllHandleFunc() []RouterItem {
return app.all
}
func (app *application) PrintAllRequest() {
fmt.Println("所有请求信息打印开始===================================================================================")
list := app.AllHandleFunc()
for _, d := range list {
fmt.Printf("%-12s %-40s %s\n", d.Method, d.URL, d.CodeRow)
}
fmt.Println("所有请求信息打印结束===================================================================================")
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。