1 Star 0 Fork 0

Wsage/go-framework

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
run_httpserver_simple.go 832 Bytes
一键复制 编辑 原始数据 按行查看 历史
王少奇 提交于 2021-08-02 16:37 . 新增 转发http的实现
package main
import (
"fmt"
v1http "gitee.com/scottq/go-framework/src/v1/httpserver"
v1log "gitee.com/scottq/go-framework/src/v1/log"
"os"
"path/filepath"
)
func main() {
name := "example"
logPath := fmt.Sprintf("./runtime/logs/%s.log", filepath.Base(os.Args[0]))
logger := v1log.NewZapLog(name, logPath, nil)
httpServer, err := v1http.NewHttpServer("", ":8080")
if err != nil {
logger.Error("run http server error:%s" + err.Error())
return
}
//添加logger
httpServer.AddLogger(logger)
//注册简单的控制器
httpServer.RouteGet("/v1", Index, nil)
//自定义health
httpServer.RouteGet(v1http.HealthUrl, Health, nil)
logger.Fatal(httpServer.Run().Error())
}
//http router
func Index(ctx *v1http.Ctx) {
ctx.Write([]byte("Hello"))
}
func Health(ctx *v1http.Ctx) {
ctx.Write([]byte("SERVICE OK"))
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/scottq/go-framework.git
git@gitee.com:scottq/go-framework.git
scottq
go-framework
go-framework
v1.1.25

搜索帮助