bootstrap

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = fx.Module("bootstrap",
	fx.Provide(
		NewLogger,

		NewDB,
		NewSentry,
		NewApplication,
	),
)

Module exports dependency

Functions

func GetMessage

func GetMessage(code int) string

func GlobalErrorMiddleware

func GlobalErrorMiddleware() gin.HandlerFunc

func LoadConfig

func LoadConfig[T any](yamlFile string) (*T, error)

LoadConfig 从指定的YAML文件中加载配置信息

func NewHttpServer

func NewHttpServer(app *Application, logger *AppLogger) *http.Server

func NewInstance added in v0.0.2

func NewInstance[T any]() *T

create instance and load default values which defined in the struct definition

func SaveConfig

func SaveConfig[T any](cfg *T, yamlFile string) error

SaveConfig 将配置信息保存到指定的YAML文件中

func SetErrorInfo

func SetErrorInfo(ei map[int]string)

Types

type AppLogger

type AppLogger struct {
	*slog.Logger // Logger instance

	Params LoggerParams // Parameters for the logger
}

func NewLogger

func NewLogger(cfg types.AppConfig, lc fx.Lifecycle) *AppLogger

type AppSentry added in v0.0.2

type AppSentry struct {
	Params types.AppSentryConfig
}

func NewSentry added in v0.0.2

func NewSentry(cfg types.AppConfig, lc fx.Lifecycle, logger *AppLogger) (*AppSentry, error)

func (*AppSentry) CaptureException added in v0.0.2

func (*AppSentry) CaptureException(err error)

CaptureException 捕获异常并发送到sentry

func (*AppSentry) CaptureRequest added in v0.0.2

func (*AppSentry) CaptureRequest(r *http.Request)

CaptureRequest 捕获请求并发送到sentry

func (*AppSentry) ReportEvent added in v0.0.2

func (sty *AppSentry) ReportEvent(event_id types.UserDefinedEvent, eventMessage string, payLoad map[string]interface{})

// ReportCustomEvent 上报定制事件

func (*AppSentry) SetExtra added in v0.0.2

func (*AppSentry) SetExtra(key string, value interface{})

func (*AppSentry) SetTag added in v0.0.2

func (*AppSentry) SetTag(key, value string)

func (*AppSentry) SetUser added in v0.0.2

func (*AppSentry) SetUser(id string)

type Application

type Application struct {
	// Configuration
	Config types.AppSysConfig
	// contains filtered or unexported fields
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

func NewApplication

func NewApplication(cfg types.AppConfig, lc fx.Lifecycle, sty *AppSentry, logger *AppLogger) *Application

func (*Application) RunServer

func (app *Application) RunServer(logger *AppLogger) error

type DBParams

type DBParams types.AppDBConfig

func NewDBParams

func NewDBParams(dbtype string, dbhost string, dbport int, dbdatabase string, dbuser string, dbpassword string) DBParams

func (DBParams) GetConnectionString

func (param DBParams) GetConnectionString() (string, error)

type DBToolKit

type DBToolKit sqlx.DB

func NewDB

func NewDB(cfg types.AppConfig) (*DBToolKit, error)

type LoggerParams

type LoggerParams types.AppLogConfig

func (*LoggerParams) CloseLogFile added in v0.0.2

func (lp *LoggerParams) CloseLogFile()

func (*LoggerParams) CreateLogWriter added in v0.0.2

func (lp *LoggerParams) CreateLogWriter(filename string) io.Writer

type Result

type Result struct {
	Code    int         `json:"code"`    // 状态码
	Message string      `json:"message"` // 响应消息
	Data    interface{} `json:"data"`    // 响应数据
}

Result 表示统一响应的JSON格式

func NewQuickResult

func NewQuickResult(code int, data interface{}) Result

func NewResult

func NewResult(code int, message string, data interface{}) Result

func (Result) Fail

func (result Result) Fail(c *gin.Context)

func (Result) OK

func (result Result) OK(c *gin.Context)

接口执行正常 需要返回数据 data

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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