app

package module
v1.22.6 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: MIT Imports: 23 Imported by: 111

README

App Starter

Go project version issues Go Report Card Source graph License

Delete tag

$ git tag -d v0.4.0
Deleted tag 'v0.4.0' (was f74dcae)

$ git push origin :v0.4.0
To https://github.com/lishimeng/app-starter.git
 - [deleted]         3.3.0.1492

Documentation

Index

Constants

View Source
const (
	Disable = iota
	Enable
)

Variables

View Source
var WithDefaultCallback = func(configName string) (f func(loader etc.Loader)) {
	return func(loader etc.Loader) {
		loader.SetFileSearcher(configName, ".").SetEnvPrefix("").SetEnvSearcher()
	}
}

Functions

func GetCache added in v1.4.0

func GetCache() (c cache.C)

func GetMqtt added in v1.10.0

func GetMqtt() (session mqtt.Session)

func GetNamedOrm added in v1.6.9

func GetNamedOrm(aliaName string) *persistence.OrmContext

func GetOrm

func GetOrm() *persistence.OrmContext

func GetRedis added in v1.21.15

func GetRedis() (c *redis.Client)

func GetWebServer added in v1.12.6

func GetWebServer() (s *server.Server)

func InjectEnv added in v1.21.22

func InjectEnv(key, value string)

InjectEnv key, value

func InjectEnvStr added in v1.21.22

func InjectEnvStr(s string)

InjectEnvStr key=value

func Query added in v1.6.6

func Query(h func(ctx persistence.OrmContext) (err error)) (err error)

func QueryPage added in v1.12.6

func QueryPage[Model any, Dto any](pager *SimplePager[Model, Dto]) (err error)

QueryPage 单表分页查询(默认pageNo=1 pageSize=10)

func Transaction added in v1.6.6

func Transaction(h func(ctx persistence.TxContext) error) (err error)

Types

type Application

type Application interface {
	Start(buildHandler func(ctx context.Context, builder *ApplicationBuilder) error, onTerminate ...func(string)) error
}

func New

func New() (instance Application)

type ApplicationBuilder added in v1.2.1

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

func (*ApplicationBuilder) ComponentAfter added in v1.2.1

func (h *ApplicationBuilder) ComponentAfter(component func(context.Context) (err error)) *ApplicationBuilder

func (*ApplicationBuilder) ComponentBefore added in v1.2.1

func (h *ApplicationBuilder) ComponentBefore(component func(context.Context) (err error)) *ApplicationBuilder

func (*ApplicationBuilder) EnableCache added in v1.4.0

func (h *ApplicationBuilder) EnableCache(redisOpts cache.RedisOptions, cacheOpts cache.Options) *ApplicationBuilder

func (*ApplicationBuilder) EnableDatabase added in v1.2.1

func (h *ApplicationBuilder) EnableDatabase(config persistence.BaseConfig,
	models ...interface{}) *ApplicationBuilder

func (*ApplicationBuilder) EnableDatabaseLog added in v1.12.6

func (h *ApplicationBuilder) EnableDatabaseLog() *ApplicationBuilder

EnableDatabaseLog 打开orm log输出

func (*ApplicationBuilder) EnableDatabaseView added in v1.21.11

func (h *ApplicationBuilder) EnableDatabaseView(views ...interface{}) *ApplicationBuilder

func (*ApplicationBuilder) EnableMqtt added in v1.10.0

func (h *ApplicationBuilder) EnableMqtt(options ...mqtt.ClientOption) *ApplicationBuilder

func (*ApplicationBuilder) EnableOrmLog added in v1.7.3

func (h *ApplicationBuilder) EnableOrmLog() *ApplicationBuilder

func (*ApplicationBuilder) EnableStaticWeb added in v1.2.1

func (h *ApplicationBuilder) EnableStaticWeb(assetFile func() http.FileSystem) *ApplicationBuilder

func (*ApplicationBuilder) EnableTokenValidator added in v1.9.0

func (h *ApplicationBuilder) EnableTokenValidator(builder TokenValidatorBuilder) *ApplicationBuilder

EnableTokenValidator 验证Token,使用RedisTokenValidator前需要enableCache

func (*ApplicationBuilder) EnableVueHistoryPlugin added in v1.12.6

func (h *ApplicationBuilder) EnableVueHistoryPlugin(whiteList ...string) *ApplicationBuilder

EnableVueHistoryPlugin 页面路径使用index.html替换

func (*ApplicationBuilder) EnableWeb added in v1.2.1

func (h *ApplicationBuilder) EnableWeb(listen string, components ...server.Component) *ApplicationBuilder

func (*ApplicationBuilder) HealthyHandler added in v1.5.0

func (h *ApplicationBuilder) HealthyHandler(handler func() int) *ApplicationBuilder

func (*ApplicationBuilder) LoadConfig added in v1.2.1

func (h *ApplicationBuilder) LoadConfig(config interface{}, callback func(etc.Loader)) (err error)

func (*ApplicationBuilder) PrintVersion added in v1.7.3

func (h *ApplicationBuilder) PrintVersion() *ApplicationBuilder

func (*ApplicationBuilder) ReadyHandler added in v1.5.0

func (h *ApplicationBuilder) ReadyHandler(handler func() int) *ApplicationBuilder

func (*ApplicationBuilder) SetMonitorPrefix added in v1.5.0

func (h *ApplicationBuilder) SetMonitorPrefix(prefix string) *ApplicationBuilder

func (*ApplicationBuilder) SetWebLogLevel added in v1.3.3

func (h *ApplicationBuilder) SetWebLogLevel(lvl string) *ApplicationBuilder

type BasePager added in v1.12.6

type BasePager struct {
	Total     int `json:"total"`
	TotalPage int `json:"totalPage"` // 总页数
	PageSize  int `json:"pageSize"`  // 页面大小
	PageNum   int `json:"pageNum"`   // 页号
	More      int `json:"more"`      // 是否有下一页
}

func (*BasePager) Offset added in v1.12.6

func (p *BasePager) Offset() int

func (*BasePager) SetTotal added in v1.21.12

func (p *BasePager) SetTotal(count int64) int

type OperatorChangeInfo added in v1.10.15

type OperatorChangeInfo struct {
	OperatorInfo
	UpdateOperator int `gorm:"column:moperator"`
}

OperatorChangeInfo 不可与 OperatorInfo 同时使用

type OperatorInfo added in v1.10.15

type OperatorInfo struct {
	CreateOperator int `gorm:"column:coperator"`
}

type Pager added in v1.1.3

type Pager[Dto any] struct {
	BasePager
	Data []Dto `json:"items,omitempty"`
}

type PagerResponse added in v1.1.3

type PagerResponse struct {
	Response
}

type Pk added in v1.9.11

type Pk struct {
	// ID
	Id int `gorm:"primaryKey;autoIncrement;column:id"`
}

type Pk64 added in v1.22.1

type Pk64 struct {
	Id int64 `gorm:"primaryKey;autoIncrement;column:id"`
}

Pk64 主键为 bigint / bigserial 时使用;不可与 Pk 同时使用

type Response added in v1.1.3

type Response struct {
	Code    int         `json:"code,omitempty"`
	Success string      `json:"success,omitempty"`
	Message string      `json:"message,omitempty"`
	Status  interface{} `json:"status,omitempty"`
}

type ResponseWrapper added in v1.11.4

type ResponseWrapper struct {
	Response
	Data any `json:"data,omitempty"`
}

type SimplePager added in v1.12.6

type SimplePager[DbModel any, Dto any] struct {
	Pager[Dto]
	DataSet      []DbModel
	Transform    func(src DbModel, dst *Dto)
	OrderExp     []string // GORM order expressions, e.g. "id desc"
	QueryBuilder func(tx persistence.TxContext) persistence.Query
}

type TableChangeInfo added in v1.9.11

type TableChangeInfo struct {
	Status int `gorm:"column:status;default:0"`
	TableInfo
	UpdateTime time.Time `gorm:"autoUpdateTime;column:mtime"`
}

TableChangeInfo 不可与 TableInfo 同时使用

type TableInfo added in v1.9.11

type TableInfo struct {
	CreateTime time.Time `gorm:"autoCreateTime;column:ctime"`
}

type Tenant added in v1.10.15

type Tenant struct {
	Org int `gorm:"column:org"` // org为tenant标记
}

Tenant 多租户

type TenantPk added in v1.10.15

type TenantPk struct {
	Pk
	Tenant
}

TenantPk 不可与 Pk / Pk64 同时使用

type TenantPk64 added in v1.22.1

type TenantPk64 struct {
	Pk64
	Tenant
}

TenantPk64 不可与 Pk / Pk64 同时使用

type TokenValidatorBuilder added in v1.9.0

type TokenValidatorBuilder func(injectFunc TokenValidatorInjectFunc)

type TokenValidatorInjectFunc added in v1.9.0

type TokenValidatorInjectFunc func(storage token.Storage)

Directories

Path Synopsis
application
api
examples
web-basic command
midware
driver/mysql
Package mysql provides MysqlConfig and registers the GORM mysql dialector on import.
Package mysql provides MysqlConfig and registers the GORM mysql dialector on import.
driver/postgres
Package postgres provides PostgresConfig and registers the GORM postgres dialector on import.
Package postgres provides PostgresConfig and registers the GORM postgres dialector on import.
driver/sqlite
Package sqlite provides SqliteConfig and registers the GORM sqlite dialector on import.
Package sqlite provides SqliteConfig and registers the GORM sqlite dialector on import.
sse

Jump to

Keyboard shortcuts

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