inobox
使用的开源项目
使用
import
go get -u github.com/inoth/inobox
示例
详细内容查看:example
package main
import (
"github.com/gin-gonic/gin"
"github.com/inoth/inobox"
logzap "github.com/inoth/inobox/component/logger/log_zap"
"github.com/inoth/inobox/register/config"
"github.com/inoth/inobox/server/httpsvr"
"github.com/inoth/inobox/server/httpsvr/middleware"
"github.com/inoth/inobox/server/httpsvr/res"
)
func main() {
reg := inobox.New(
config.ConfigWithLocal("config"),
logzap.LoggerWithZap,
httpsvr.HttpWithGin(
func(hgs *httpsvr.HttpGinServer) {
router := hgs.Engine()
router.GET("", func(c *gin.Context) {
res.OK(c, "ok", map[string]interface{}{
"server_name": hgs.Name(),
"app_name": config.GetString("app_name"),
})
})
},
),
httpsvr.Http2WithGin(
httpsvr.SetHttp2Name("gin2"),
func(hgs *httpsvr.Http2GinServer) {
router := hgs.Engine()
router.Use(
middleware.Cors(),
middleware.Recovery(),
middleware.LoggerAndTrace(),
)
},
func(hgs *httpsvr.Http2GinServer) {
router := hgs.Engine()
router.GET("", func(c *gin.Context) {
//! Failed to push: feature not supported
// if push := c.Writer.Pusher(); push != nil {
// if err := push.Push("/ping", nil); err != nil {
// logger.Warnf("Failed to push: %v", err)
// }
// }
res.OK(c, "ok", map[string]interface{}{
"server_name": hgs.Name(),
"app_name": config.GetString("app_name"),
})
})
},
))
reg.Run()
}
component
// 配置,default path: ./config
config.ConfigWithLocal()
// logger && zap
logzap.LoggerWithZap
// redis
redis.CacheWithRedis
// mysql && gorm
mysql.DBWithGormMysql
server
// http && gin
httpsvr.HttpWithGin()
// http2 && gin
httpsvr.Http2WithGin()
// udp
udpsvr.UdpWithUdp()
获取启动
inobox.New()
inobox.Default()