Base

package
v0.0.0-...-1bf86c4 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2020 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const ApiAppName = "ApiApp"
View Source
const ApiAppVersion = "1.0.0-Beta"
View Source
const ConfigureFaceId = "IConfiguration"
View Source
const ConfigureId = "configure"

常量

View Source
const ErrorFaceId = "error"
View Source
const ErrorId = "err"
View Source
const LoggerFaceId = "logger"
View Source
const LoggerId = "log"
View Source
const RpcAppName = "RpcApp"
View Source
const RpcAppVersion = "1.0.0-Beta"
View Source
const SuccessCode = 200
View Source
const WebAppName = "WebApp"
View Source
const WebAppVersion = "1.0.0-Beta"
View Source
const WebSocketAppName = "WebSocketApp"
View Source
const WebSocketAppVersion = "1.0.0-Beta"

Variables

This section is empty.

Functions

func AppDefaultBoot

func AppDefaultBoot(container ICtxContainer)

默认引导加载 注册

func AppDefaultInit

func AppDefaultInit(container ICtxContainer)

默认初始化调用

func AppDefaultSetup

func AppDefaultSetup(container ICtxContainer)

默认启动

func Container

func Container(name string, ctx ...ICtxContainer) interface{}

从容器中获取注册对象

func Dirname

func Dirname() string

当前目录

func DriverName

func DriverName(scope string, name string) string

驱动连接名

func LogicError

func LogicError(message string) error

逻辑异常

func NetWorkError

func NetWorkError(message string) error

网络异常

func OnError

func OnError(err error)

异常

func RuntimeError

func RuntimeError(message string) error

运行时异常

func ServiceError

func ServiceError(message string) error

服务异常

func TransformMap2Struct

func TransformMap2Struct(data map[string]interface{}, v interface{}, tags ...string) (err error)

简单转换 不支持嵌套

func TransformStruct2Map

func TransformStruct2Map(v interface{}, tags ...string) (data map[string]interface{}, err error)

简单转换 不支持嵌套

func WarpError

func WarpError(msg string, err ...error) error

异常wrap

Types

type AppApi

type AppApi struct {
	Ctx     ICtxContainer
	AppName string
	Version string
}

func (*AppApi) Boot

func (a *AppApi) Boot()

func (*AppApi) Component

func (a *AppApi) Component(string) (interface{}, error)

func (*AppApi) Context

func (a *AppApi) Context() ICtxContainer

func (*AppApi) Destroy

func (a *AppApi) Destroy()

func (*AppApi) Hook

func (a *AppApi) Hook(string, func(string, interface{}))

func (*AppApi) Init

func (a *AppApi) Init()

func (*AppApi) On

func (a *AppApi) On(string, IAppEventHandler)

func (*AppApi) Run

func (a *AppApi) Run()

func (*AppApi) Stop

func (a *AppApi) Stop()

type AppWeb

type AppWeb struct {
	Ctx     ICtxContainer
	AppName string
	Version string
}

func (*AppWeb) Boot

func (a *AppWeb) Boot()

func (AppWeb) Component

func (a AppWeb) Component(name string) (interface{}, error)

func (*AppWeb) Context

func (a *AppWeb) Context() ICtxContainer

func (*AppWeb) Destroy

func (a *AppWeb) Destroy()

func (*AppWeb) Hook

func (a *AppWeb) Hook(hook string, handler func(string, interface{}))

func (*AppWeb) Init

func (a *AppWeb) Init()

func (*AppWeb) On

func (a *AppWeb) On(event string, handler IAppEventHandler)

func (*AppWeb) Run

func (a *AppWeb) Run()

func (*AppWeb) Setup

func (a *AppWeb) Setup()

func (*AppWeb) Stop

func (a *AppWeb) Stop()

type ComponentInvoker

type ComponentInvoker func(ICtxContainer) interface{}

type Configure

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

配置管理门脸类

func (*Configure) Block

func (c *Configure) Block() bool

是否阻塞 boot

func (*Configure) Boot

func (c *Configure) Boot() bool

func (*Configure) Booted

func (c *Configure) Booted() bool

func (*Configure) Destroy

func (c *Configure) Destroy()

func (*Configure) Durations

func (c *Configure) Durations(key string) []time.Duration

func (*Configure) Face

func (c *Configure) Face() string

func (*Configure) Float64s

func (c *Configure) Float64s(key string) []float64

func (*Configure) Get

func (c *Configure) Get(key string) (string, error)

func (*Configure) GetBool

func (c *Configure) GetBool(key string) (bool, error)

func (*Configure) GetBoolDefault

func (c *Configure) GetBoolDefault(key string, defaultValue bool) bool

func (*Configure) GetDefault

func (c *Configure) GetDefault(key, defaultValue string) string

func (*Configure) GetDuration

func (c *Configure) GetDuration(key string) (time.Duration, error)

func (*Configure) GetDurationDefault

func (c *Configure) GetDurationDefault(key string, defaultValue time.Duration) time.Duration

func (*Configure) GetFloat64

func (c *Configure) GetFloat64(key string) (float64, error)

func (*Configure) GetFloat64Default

func (c *Configure) GetFloat64Default(key string, defaultValue float64) float64

func (*Configure) GetInt

func (c *Configure) GetInt(key string) (int, error)

func (*Configure) GetIntDefault

func (c *Configure) GetIntDefault(key string, defaultValue int) int

func (*Configure) Ints

func (c *Configure) Ints(key string) []int

func (*Configure) Keys

func (c *Configure) Keys() []string

func (*Configure) Prefix

func (c *Configure) Prefix(prefix string, withOutPrefix ...bool) ConfigureFace

func (*Configure) Register

func (c *Configure) Register(container ICtxContainer) bool

func (*Configure) Set

func (c *Configure) Set(key, val string)

func (*Configure) SetAll

func (c *Configure) SetAll(values map[string]string)

func (*Configure) Strings

func (c *Configure) Strings(key string) []string

func (*Configure) Unmarshal

func (c *Configure) Unmarshal(t interface{}) error

type ConfigureFace

type ConfigureFace interface {
	IFaced         // 门脸信息,门脸注册相关
	IConfiguration // 实例操作集合
}

配置管理(门脸)对象

func Config

func Config() ConfigureFace

获取配置

func GetConfigureInstance

func GetConfigureInstance(instances ...IConfiguration) ConfigureFace

获取单例

func GetPrefixConfig

func GetPrefixConfig(prefix string) ConfigureFace

获取某种前缀

func NewConfigure

func NewConfigure(instance IConfiguration) ConfigureFace

构造配置对象

type CreateAble

type CreateAble interface {
	Create() interface{}
}

创建

type CtxContainer

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

func (*CtxContainer) Faced

func (c *CtxContainer) Faced(face string) (ok bool)

func (*CtxContainer) Get

func (c *CtxContainer) Get(key string) interface{}

func (*CtxContainer) Register

func (c *CtxContainer) Register(face string, invoker ComponentInvoker)

func (*CtxContainer) RegisterByFace

func (c *CtxContainer) RegisterByFace(instance IFaced)

func (*CtxContainer) RegisterBySingle

func (c *CtxContainer) RegisterBySingle(face string, instance interface{})

func (*CtxContainer) Remove

func (c *CtxContainer) Remove(id string) bool

type DataMap

type DataMap map[string]interface{}

模型 map 类型

func CreateModelMap

func CreateModelMap() DataMap

创建dataMap

type ErrorAble

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

func (*ErrorAble) Block

func (e *ErrorAble) Block() bool

func (*ErrorAble) Boot

func (e *ErrorAble) Boot() bool

func (*ErrorAble) Booted

func (e *ErrorAble) Booted() bool

func (*ErrorAble) Code

func (e *ErrorAble) Code() int

func (*ErrorAble) Destroy

func (e *ErrorAble) Destroy()

func (*ErrorAble) Error

func (e *ErrorAble) Error() string

func (*ErrorAble) ErrorType

func (e *ErrorAble) ErrorType() string

func (*ErrorAble) Face

func (e *ErrorAble) Face() string

func (*ErrorAble) Message

func (e *ErrorAble) Message() string

func (*ErrorAble) New

func (e *ErrorAble) New(msg string, code int, parent ...error) error

func (*ErrorAble) Register

func (e *ErrorAble) Register(ctx ICtxContainer) bool

func (*ErrorAble) Set

func (e *ErrorAble) Set(key string, value interface{}) ErrorInstance

func (*ErrorAble) TraceString

func (e *ErrorAble) TraceString() string

type ErrorFace

type ErrorFace interface {
	IFaced
	ErrorInstance
}

func GetErrorFaceInstance

func GetErrorFaceInstance() ErrorFace

func NewErrorFace

func NewErrorFace(instance ...ErrorInstance) ErrorFace

type ErrorInstance

type ErrorInstance interface {
	error
	Code() int
	Message() string
	TraceString() string
	ErrorType() string
	Set(string, interface{}) ErrorInstance
	New(msg string, code int, parent ...error) error
}

type IAppEventHandler

type IAppEventHandler func(target interface{}, ctx ICtxContainer, next IAppEventHandler)

type IApplication

type IApplication interface {
	Boot()                                  // 在自身所需 配置 或者驱动 和检查相关环境
	Init()                                  // 初始化 依赖组织 并注册 到相关容器中
	Run()                                   // 运行于启动 应用, 提供外部相关服务
	Stop()                                  // 暂停服务
	Destroy()                               // 回收服务资源
	Context() ICtxContainer                 // 获取上线文容器
	Component(string) (interface{}, error)  // 获取组件
	Hook(string, func(string, interface{})) // 添加相关hook处理函数
	On(string, IAppEventHandler)            // 添加事件处理机制调用链 , 事件处理链路可以自由阻断
}

func NewApiApp

func NewApiApp(name ...string) IApplication

func NewRpcApp

func NewRpcApp(name ...string) IApplication

func NewWebApp

func NewWebApp(name ...string) IApplication

func NewWsApp

func NewWsApp(name ...string) IApplication

type IConfiguration

type IConfiguration interface {
	// values
	Strings(key string) []string
	Ints(key string) []int
	Float64s(key string) []float64
	Durations(key string) []time.Duration
	//
	Get(string) (string, error)
	GetDefault(string, string) string
	//
	GetInt(string) (int, error)
	GetIntDefault(string, int) int
	//
	GetDuration(string) (time.Duration, error)
	GetDurationDefault(string, time.Duration) time.Duration
	//
	GetBool(string) (bool, error)
	GetBoolDefault(string, bool) bool
	//
	GetFloat64(string) (float64, error)
	GetFloat64Default(string, float64) float64

	Set(string, string)
	SetAll(map[string]string)
	Keys() []string
	//t必须为指针型
	Unmarshal(interface{}) error
	// 获取特定前缀配置,返回新配置对象
	Prefix(string, ...bool) ConfigureFace
}

配置操作对象

type ICtxContainer

type ICtxContainer interface {
	Get(string) interface{}               // 获取注册对象
	Register(string, ComponentInvoker)    // 构造函数注册
	RegisterBySingle(string, interface{}) // 单例注册
	RegisterByFace(IFaced)                // 门脸模式自动注册
	Faced(string) bool                    // 是否已注册
	IRemoveAble
}

func AppContext

func AppContext() ICtxContainer

上下文

func GetContainerInstance

func GetContainerInstance() ICtxContainer

func NewCtxContainer

func NewCtxContainer() ICtxContainer

type ICtxRegister

type ICtxRegister interface {
	Register(ICtxContainer) // 注册
}

type IDatabase

type IDatabase interface {
	SetConnection(string)                                // 获取链接对象
	Create(interface{}) bool                             // 通过数据结构体 创建,返回是否成功
	Table(string) IQueryBuilder                          // 获取 指定表的查询对象
	Select(string) IQueryBuilder                         // 通过 select 语句构造 query 对象
	Exec(string) (int, error)                            // 执行原始sql 返回影响记录数和异常
	Connection() interface{}                             // 获取当前链接对象
	Query(string, ...interface{}) (IQueryBuilder, error) // 构建 query 查询对象
}

数据库

type IDestroy

type IDestroy interface {
	Destroy() // 清理函数
}

type IFaced

type IFaced interface {
	Face() string                // 门脸名
	Register(ICtxContainer) bool // 自动注册逻辑
	Booted() bool                // 是否已执行引导
	Boot() bool                  // 引导加载逻辑
	Block() bool                 // 引导加载是否阻塞
	Destroy()                    // 清理回收
}

门脸对象

type IModel

type IModel interface {
	Table() string                    // 表名
	Model() interface{}               // 模型结构体
	Tags(...string) map[string]string // 结构体 对应 tags集合
	Conn(...string) IDatabase         // 获取数据库操作对象
}

模型

type IQueryBuilder

type IQueryBuilder interface {
	ToSql() string                                                  // 输出sql
	Count() int                                                     // 条数
	Exists() bool                                                   // 是否存在
	Save() (int, error)                                             // 保存
	CurrentTable() string                                           // 当前表名
	All() (interface{}, error)                                      // 获取所有
	First() (interface{}, error)                                    // 获取第一条
	Update(map[string]interface{}) ISqlExecutor                     // 更新
	Order(string, string) IQueryBuilder                             // 排序
	Group(string, string) IQueryBuilder                             // 分组
	Join(string, ...string) IQueryBuilder                           // join
	Insert(interface{}, ...interface{}) ISqlExecutor                // 插入
	Delete(string, ...interface{}) ISqlExecutor                     // 删除语句
	Pluck(string, interface{}) IQueryBuilder                        // 获取其中一个键值
	When(string, ...func(IQueryBuilder) ISqlExecutor) IQueryBuilder // 组合语句
	Raw(string) IQueryBuilder                                       // sql原始语句
	Get() (interface{}, error)                                      // 执行并获取sql结果
	GetOne() (interface{}, error)                                   // 获取任意一条
}

查询构造器

type IRedisClient

type IRedisClient interface {
	Del(key string)
	Exists(key string) bool
	Set(key string, value string)
	Get(key string) (string, error)
	HSet(key string, hash map[string]string)
	HGet(key string, field string) (string, error)
	HGetAll(key string) (map[string]string, error)
	Setex(key string, value string, expire time.Duration)
	Command(command string, args ...interface{}) (interface{}, error)
}

type IRemoveAble

type IRemoveAble interface {
	Remove(string) bool
}

type IReturnAble

type IReturnAble interface {
	State() int64
	Message() string
	Value() interface{}
	ToJson() string
	ToMap() DataMap
	Error() error
	Transform(interface{}, string) error
}

结果对象

func NewFailAbel

func NewFailAbel(errMsg string, errNo int64, res ...interface{}) IReturnAble

func NewReturnAble

func NewReturnAble(code int64, msg string, data interface{}, errNo int64, errMsg string) IReturnAble

func NewSuccessAble

func NewSuccessAble(data interface{}, msg string, codeArg ...int64) IReturnAble

type ISqlExecutor

type ISqlExecutor interface {
	Sql() string                // 输出 sql
	Exec() (interface{}, error) // 执行 Sql 语句 获取结果
}

sql 执行器

type IStarter

type IStarter interface {
	Init()                  // 初始化函数
	Start()                 // 启动函数
	Stop()                  // 停止
	Register(ICtxContainer) // 自动注册函数
	Block() bool            // 是否阻塞启动
	Destroy()               // 清理
}

type LogInstanceFace

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

日志实例 对象

func (*LogInstanceFace) Block

func (l *LogInstanceFace) Block() bool

func (*LogInstanceFace) Boot

func (l *LogInstanceFace) Boot() bool

func (*LogInstanceFace) Booted

func (l *LogInstanceFace) Booted() bool

func (*LogInstanceFace) Debug

func (l *LogInstanceFace) Debug(args ...interface{})

func (*LogInstanceFace) Debugf

func (l *LogInstanceFace) Debugf(format string, args ...interface{})

func (*LogInstanceFace) Destroy

func (l *LogInstanceFace) Destroy()

func (*LogInstanceFace) Error

func (l *LogInstanceFace) Error(args ...interface{})

func (*LogInstanceFace) Errorf

func (l *LogInstanceFace) Errorf(format string, args ...interface{})

func (*LogInstanceFace) Face

func (l *LogInstanceFace) Face() string

func (*LogInstanceFace) Fatal

func (l *LogInstanceFace) Fatal(args ...interface{})

func (*LogInstanceFace) Fatalf

func (l *LogInstanceFace) Fatalf(format string, args ...interface{})

func (*LogInstanceFace) Info

func (l *LogInstanceFace) Info(args ...interface{})

func (*LogInstanceFace) Infof

func (l *LogInstanceFace) Infof(format string, args ...interface{})

func (*LogInstanceFace) Panic

func (l *LogInstanceFace) Panic(args ...interface{})

func (*LogInstanceFace) Panicf

func (l *LogInstanceFace) Panicf(format string, args ...interface{})

func (*LogInstanceFace) Print

func (l *LogInstanceFace) Print(args ...interface{})

func (*LogInstanceFace) Printf

func (l *LogInstanceFace) Printf(format string, args ...interface{})

func (*LogInstanceFace) Register

func (l *LogInstanceFace) Register(ctx ICtxContainer) bool

func (*LogInstanceFace) Warn

func (l *LogInstanceFace) Warn(args ...interface{})

func (*LogInstanceFace) Warnf

func (l *LogInstanceFace) Warnf(format string, args ...interface{})

func (*LogInstanceFace) Warning

func (l *LogInstanceFace) Warning(args ...interface{})

func (*LogInstanceFace) Warningf

func (l *LogInstanceFace) Warningf(format string, args ...interface{})

type Logger

type Logger interface {
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Printf(format string, args ...interface{})
	Warnf(format string, args ...interface{})
	Warningf(format string, args ...interface{})
	Errorf(format string, args ...interface{})
	Fatalf(format string, args ...interface{})
	Panicf(format string, args ...interface{})

	Debug(args ...interface{})
	Info(args ...interface{})
	Print(args ...interface{})
	Warn(args ...interface{})
	Warning(args ...interface{})
	Error(args ...interface{})
	Fatal(args ...interface{})
	Panic(args ...interface{})
}

日志操作对象

type LoggerFace

type LoggerFace interface {
	IFaced
	Logger
}

日志 门脸接口

func GetLoggerInstance

func GetLoggerInstance() LoggerFace

获取logger Instance

func Log

func Log() LoggerFace

日志

func NewLoggerInstance

func NewLoggerInstance(logs ...Logger) LoggerFace

创建 logger 服务

type ReturnAble

type ReturnAble struct {
	Code   int64       `json:"code" Tr:"code"`
	Msg    string      `json:"msg" Tr:"msg"`
	Data   interface{} `json:"data" Tr:"data"`
	ErrNo  int64       `json:"errNo" Tr:"errno"`
	ErrMsg string      `json:"errMsg" Tr:"errMsg"`
}

func (*ReturnAble) Error

func (r *ReturnAble) Error() error

func (*ReturnAble) Message

func (r *ReturnAble) Message() string

func (*ReturnAble) State

func (r *ReturnAble) State() int64

func (*ReturnAble) ToJson

func (r *ReturnAble) ToJson() string

func (*ReturnAble) ToMap

func (r *ReturnAble) ToMap() DataMap

func (*ReturnAble) Transform

func (r *ReturnAble) Transform(v interface{}, scope string) error

对应结果体装载

func (*ReturnAble) Value

func (r *ReturnAble) Value() interface{}

type RpcApp

type RpcApp struct {
	Ctx     ICtxContainer
	AppName string
	Version string
}

func (*RpcApp) Boot

func (r *RpcApp) Boot()

func (*RpcApp) Component

func (r *RpcApp) Component(string) (interface{}, error)

func (*RpcApp) Context

func (r *RpcApp) Context() ICtxContainer

func (*RpcApp) Destroy

func (r *RpcApp) Destroy()

func (*RpcApp) Hook

func (r *RpcApp) Hook(string, func(string, interface{}))

func (*RpcApp) Init

func (r *RpcApp) Init()

func (*RpcApp) On

func (r *RpcApp) On(string, IAppEventHandler)

func (*RpcApp) Run

func (r *RpcApp) Run()

func (*RpcApp) Stop

func (r *RpcApp) Stop()

type StarterContext

type StarterContext struct {
	CtxContainer
	Name string // 启动器名
}

starter 上下文 构造环境获取器

type WebSocketApp

type WebSocketApp struct {
	Ctx     ICtxContainer
	AppName string
	Version string
}

func (*WebSocketApp) Boot

func (w *WebSocketApp) Boot()

func (*WebSocketApp) Component

func (w *WebSocketApp) Component(string) (interface{}, error)

func (*WebSocketApp) Context

func (w *WebSocketApp) Context() ICtxContainer

func (*WebSocketApp) Destroy

func (w *WebSocketApp) Destroy()

func (*WebSocketApp) Hook

func (w *WebSocketApp) Hook(string, func(string, interface{}))

func (*WebSocketApp) Init

func (w *WebSocketApp) Init()

func (*WebSocketApp) On

func (*WebSocketApp) Run

func (w *WebSocketApp) Run()

func (*WebSocketApp) Stop

func (w *WebSocketApp) Stop()

Jump to

Keyboard shortcuts

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