inobox

package module
v0.9.3 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 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:
  init        拉取模板新建项目
  version
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()

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