base

package
v0.0.0-...-90f78ec Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2020 License: MIT Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const TX = "tx"

Variables

This section is empty.

Functions

func Check

func Check(a interface{})

结构体指针检查验证,如果传入的interface为nil,就通过log.Panic函数抛出一个异常 被用在starter中检查公共资源是否被实例化了

func DbxDatabase

func DbxDatabase() *dbx.Database

func ExecuteContext

func ExecuteContext(ctx context.Context, fn func(*dbx.TxRunner) error) error

在事务上下文中执行事务逻辑 传入绑定了runner的上下文,并执行事务函数代码 函数只能用在绑定了runner的事务上下文中,也就是说用在事务函数内部,和WithValueContext配合一起来完成。 举例:

func CreateXyz() error {
	err := Tx(func(runner *dbx.TxRunner) error {
		//将runner绑定到上下文
		ctx := WithValueContext(context.Background(), runner)
		//dao.insert xxx
		TxStepY(ctx)
		TxStepZ(ctx)
		return nil
	})

	return err
}
func TxStepY(ctx context.Context) error {
	//事务上下文中执行Y数据库操作
	return ExecuteContext(ctx, func(runner *dbx.TxRunner) error {
		//dao.insert yyy
		return nil
	})

}

func TxStepZ(ctx context.Context) error {
	//事务上下文中执行Z数据库操作
	return ExecuteContext(ctx, func(runner *dbx.TxRunner) error {
		//dao.update zzz
		return nil
	})

}

func GetEnvelopeActivityLink() string

读取红包活动相关配置

func GetEnvelopeDomain

func GetEnvelopeDomain() string

func Iris

func Iris() *iris.Application

iris applicaiton 的暴漏函数

func Props

func Props() kvs.ConfigSource

func Register

func Register(fn func())

func RpcRegister

func RpcRegister(ri interface{})

api 向 rpc server 注册函数

func RpcServer

func RpcServer() *rpc.Server

rpc server 获取函数

func Translator

func Translator() ut.Translator

func Tx

func Tx(fn func(*dbx.TxRunner) error) error

事务执行帮助函数,简化代码

func TxContext

func TxContext(ctx context.Context, fn func(runner *dbx.TxRunner) error) error

事务执行帮助函数,简化代码,需要传入上下文

func Validate

func Validate() *validator.Validate

func ValidateStruct

func ValidateStruct(s interface{}) (err error)

验证输入参数是否合法

func WithValueContext

func WithValueContext(parent context.Context, runner *dbx.TxRunner) context.Context

将runner绑定到上下文,并创建一个新的WithValueContext

Types

type BaseDao

type BaseDao struct {
	TX *sql.Tx
}

提供一个基本Dao基础功能的支持

func (*BaseDao) SetTx

func (d *BaseDao) SetTx(tx *sql.Tx)

type DbxDatabaseStarter

type DbxDatabaseStarter struct {
	infra.BaseStarter
}

dbx 数据库 starter,并设置为全局

func (*DbxDatabaseStarter) Setup

func (s *DbxDatabaseStarter) Setup(ctx infra.StarterContext)

数据库连接的生命周期要晚于配置文件的加载,为了更好的符合此逻辑,将连接的初始化设置在 Setup 阶段

type EurekaStarter

type EurekaStarter struct {
	infra.BaseStarter
	// contains filtered or unexported fields
}

func (*EurekaStarter) Init

func (e *EurekaStarter) Init(ctx infra.StarterContext)

func (*EurekaStarter) Setup

func (e *EurekaStarter) Setup(ctx infra.StarterContext)

type GoRPCStarter

type GoRPCStarter struct {
	infra.BaseStarter
	// contains filtered or unexported fields
}

func (*GoRPCStarter) Init

func (g *GoRPCStarter) Init(ctx infra.StarterContext)

func (*GoRPCStarter) Start

func (g *GoRPCStarter) Start(ctx infra.StarterContext)

type HookStarter

type HookStarter struct {
	infra.BaseStarter
}

func (*HookStarter) Init

func (h *HookStarter) Init(ctx infra.StarterContext)

func (*HookStarter) Start

func (h *HookStarter) Start(ctx infra.StarterContext)

type IrisServerStarter

type IrisServerStarter struct {
	infra.BaseStarter
}

func (*IrisServerStarter) Init

func (i *IrisServerStarter) Init(ctx infra.StarterContext)

func (*IrisServerStarter) Start

func (i *IrisServerStarter) Start(ctx infra.StarterContext)

func (*IrisServerStarter) StartBlocking

func (i *IrisServerStarter) StartBlocking() bool

type PropsStarter

type PropsStarter struct {
	infra.BaseStarter
}

func (*PropsStarter) Init

func (p *PropsStarter) Init(ctx infra.StarterContext)

type ResCode

type ResCode int

常见的 web 响应码

const (
	ResCodeOk                 ResCode = 1000
	ResCodeValidationError    ResCode = 2000
	ResCodeRequestParamsError ResCode = 2100
	ResCodeInterServerError   ResCode = 5000
	ResCodeBizError           ResCode = 6000
)

type Response

type Response struct {
	Code    ResCode     `json:"code"`
	Message string      `json:"message"`
	Data    interface{} `json:"data"`
}

http 响应结构体

type SystemAccount

type SystemAccount struct {
	AccountNo   string
	AccountName string
	UserId      string
	Username    string
}

读取一次系统红包账户的配置信息

func GetSystemAccount

func GetSystemAccount() *SystemAccount

type ValidatorStarter

type ValidatorStarter struct {
	infra.BaseStarter
}

func (*ValidatorStarter) Init

func (v *ValidatorStarter) Init(ctx infra.StarterContext)

Jump to

Keyboard shortcuts

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