app

package
v0.0.0-...-eb6e4a7 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvLocal 本地环境
	EnvLocal = "local"
	// EnvDev 开发环境
	EnvDev = "dev"
	// EnvTest 测试环境
	EnvTest = "test"
	// EnvProd 生产环境
	EnvProd = "prod"
)

Variables

View Source
var (
	Conf = &Config{}
)
View Source
var DB *gorm.DB

DB 数据库全局变量

View Source
var Redis *redis.Client

Functions

func Error

func Error(c *gin.Context, err *errno.Error)

Error 错误返回

func ErrorParamInvalid

func ErrorParamInvalid(c *gin.Context, err error)

ErrorParamInvalid 参数错误

func HealthCheck

func HealthCheck(c *gin.Context)

HealthCheck will return OK if the underlying BoltDB is healthy. At least healthy enough for demoing purposes.

func InitBasicDB

func InitBasicDB(driver, dsn string) *gorm.DB

InitBasicDB init basic db

func InitDB

func InitDB() *gorm.DB

InitDB init dbs

func InitRedis

func InitRedis() *redis.Client

InitRedis redis

func IsDev

func IsDev() bool

IsDev 是否为开发环境

func IsLocal

func IsLocal() bool

IsLocal 是否本地环境

func IsProd

func IsProd() bool

IsProd 是否生产环境

func IsTest

func IsTest() bool

IsTest 是否测试环境

func NewReverseProxy

func NewReverseProxy(targetHost string) (*httputil.ReverseProxy, error)

NewReverseProxy takes target host and creates a reverse proxy

func ProxyGinHandler

func ProxyGinHandler(targetHost string) gin.HandlerFunc

ProxyGinHandler handles the http request using proxy

func ProxyRequestHandler

func ProxyRequestHandler(targetHost string) func(http.ResponseWriter, *http.Request)

ProxyRequestHandler handles the http request using proxy

func RootDir

func RootDir() (rootPath string)

RootDir 运行根目录

func RouteNotFound

func RouteNotFound(c *gin.Context)

RouteNotFound 未找到相关路由

func SetDefaultConf

func SetDefaultConf(v *viper.Viper)

func Success

func Success(c *gin.Context, data any)

Success 成功返回

func SuccessNil

func SuccessNil(c *gin.Context)

SuccessNil 成功返回,无数据

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App global app

func New

func New(opts ...Option) *App

New create a app globally

func (*App) Run

func (a *App) Run() error

Run start app

func (*App) Stop

func (a *App) Stop() error

Stop stops the application gracefully.

type Config

type Config struct {
	Env        string
	Name       string
	DfsUrl     string
	Mode       string
	LogLevel   string
	LogDir     string
	JwtSecret  string
	JwtTimeout int64
	Debug      bool
	Proxy      bool // 是否开启代理 http://[host]/ws -> ws://[host]
	HTTP       ServerConfig
	Websocket  ServerConfig
}

type DBConfig

type DBConfig struct {
	Default orm.Config
}

type Option

type Option func(o *options)

func WithEndpoint

func WithEndpoint(endpoints ...*url.URL) Option

func WithID

func WithID(id string) Option

func WithName

func WithName(name string) Option

func WithServer

func WithServer(srv ...transport.Server) Option

type RedisConfig

type RedisConfig struct {
	Default redis2.Config
}

type Response

type Response struct {
	Code int    `json:"code"`
	Msg  string `json:"msg"`
	Data any    `json:"data"`
}

Response api的返回结构体

type ServerConfig

type ServerConfig struct {
	Network      string
	Addr         string
	ReadTimeout  time.Duration
	WriteTimeout time.Duration
}

Jump to

Keyboard shortcuts

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