inobox

package module
v0.9.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

inobox

使用的开源项目
使用
控制台程序
go install github.com/inoth/inobox/cmd/inobox@version
$ inobox help
inobox 的一些工具整合

Usage:
  inobox [command]
Available Commands:
  help        Help about any command
  init        init a project (not yet realized)
  rand        gen random string
  version

Flags:
  -h, --help   help for inobox
import
go get -u github.com/inoth/inobox
示例

详细内容查看:example

import (
    "github.com/gin-gonic/gin"
    "github.com/inoth/inobox"
    "github.com/inoth/inobox/component/logger"
    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"
    "github.com/inoth/inobox/server/wssvr"
    "github.com/inoth/inobox/utils"
)

func main() {
    reg := inobox.New(
        config.ConfigWithLocal("config"),
        logzap.LoggerWithZap,
        wssvr.WebsocketServer(wssvr.SetWsConfig()),
        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"),
                    })
                })
                router.GET("ws", func(c *gin.Context) {
                    uid := utils.RandString(16)
                    client, err := wssvr.NewClient(uid, "", wssvr.WsSvc, c.Writer, c.Request)
                    if err != nil {
                        res.ErrBadRequest(c)
                        return
                    }
                    client.Start()
                    logger.Infof("client:%s connect server.", client.ClientId)
                })
                router.GET("join", func(c *gin.Context) {
                    uid := c.Query("uid")
                    rid := c.Query("rid")
                    wssvr.WsSvc.JoinRoom(uid, rid)
                    res.OK(c, "ok")
                })
                router.GET("exit", func(c *gin.Context) {
                    uid := c.Query("uid")
                    rid := c.Query("rid")
                    wssvr.WsSvc.ExitRoom(uid, rid)
                    res.OK(c, "ok")
                })
            },
        ),
        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) {
                    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()
    // websocket
    wssvr.WebsocketServer(wssvr.SetWsConfig())
获取启动
    // 创建注册器
    inobox.New()
    // 使用默认注册器
    inobox.Default()

Documentation

Index

Constants

View Source
const Version string = "v0.9.0"

Variables

This section is empty.

Functions

func Default

func Default(opts ...register.RegisterOption) *register.Register

func New

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL