Version: v0.1.5 Latest Latest

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

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




This section is empty.


View Source
var (
	// AppMode is App's running envirenment. Valid values are dev and prod
	AppMode string
	// ConfigFile is the absolute path of config file
	ConfigFile string
	// LogPath is where log file will be
	LogPath string
View Source
var (
	// MySQLMaxIdle of connection
	MySQLMaxIdle = 10
	// MySQLMaxOpen of connection
	MySQLMaxOpen = 20


func ListenAndServe added in v0.1.1

func ListenAndServe(s *grpc.Server, addr string)

ListenAndServe the gRPC server at addr

func NewRedisClient added in v0.1.1

func NewRedisClient(cfg config.RedisConfig) *redis.Client

NewRedisClient get a redis client

func NewXormEngine added in v0.1.2

func NewXormEngine(mysql config.MysqlInstance, logWriter io.Writer, idle, open int, debug, ping bool) (*xorm.Engine, error)


type App

type App struct {
	Store    *container.Map
	Injector container.Injector

	//loggers map[string]util.Logger
	Config *cfg.AppConfig
	// contains filtered or unexported fields

App represents the application

func NewApp

func NewApp() App

NewApp gets a new application

func (*App) DefaultLogger

func (app *App) DefaultLogger() util.Logger

DefaultLogger gets default logger

func (*App) Get

func (app *App) Get(key string) interface{}

Get object from app.Store

func (*App) GetConfig

func (app *App) GetConfig() *cfg.AppConfig

GetConfig gets config ptr

func (*App) GetHook

func (app *App) GetHook(ht HookType) *[]HookFunc

GetHook returns hook slice by type

func (*App) Initialize

func (app *App) Initialize()

Initialize application

func (*App) Inject

func (app *App) Inject(object interface{}) error

Inject dependencies to the object. Please MAKE SURE that the dependencies should be stored at app.Injector before this method is called. Please use app.Set() to make this happen.

func (*App) LoadConfig

func (app *App) LoadConfig(mode string) *cfg.AppConfig

LoadConfig by mode from file

func (*App) Logger

func (app *App) Logger(name string) (util.Logger, error)

Logger of name

func (*App) RegisterHook

func (app *App) RegisterHook(ht HookType, hooks ...HookFunc)

RegisterHook in application's starting process

func (*App) Set

func (app *App) Set(key string, object interface{}, ifacePtr interface{})

Set object into app.Store and Map it into app.Injector

func (*App) SetConfig

func (app *App) SetConfig(config *cfg.AppConfig)

SetConfig sets config ptr

func (*App) SetLogger

func (app *App) SetLogger(name string, logger util.Logger)

SetLogger set logger

type Application

type Application interface {
	// Container
	Set(key string, object interface{}, ifacePtr interface{})
	Get(key string) interface{}
	Inject(object interface{}) error
	// hook
	GetHook(HookType) *[]HookFunc
	// load from file
	LoadConfig(mode string) *cfg.AppConfig
	GetConfig() *cfg.AppConfig
	// logger
	DefaultLogger() util.Logger
	Logger(name string) (util.Logger, error)
	SetLogger(string, util.Logger)
	// init

	RegisterHook(HookType, ...HookFunc)

Application interface represents a service application

type GrpcApp

type GrpcApp struct {
	// contains filtered or unexported fields

GrpcApp is the concrete type of GrpcApplication

func NewGrpcApp

func NewGrpcApp(s *grpc.Server) *GrpcApp

NewGrpcApp returns a new GrpcApp

func (*GrpcApp) GetServer

func (app *GrpcApp) GetServer() *grpc.Server

GetServer implements the GrpcApplication interface

func (*GrpcApp) Initialize

func (app *GrpcApp) Initialize()

Initialize web application

func (*GrpcApp) ListenAndServe

func (app *GrpcApp) ListenAndServe()

ListenAndServe implements the GrpcApplication interface

func (*GrpcApp) SetServer

func (app *GrpcApp) SetServer(s *grpc.Server)

SetServer implements the GrpcApplication interface

type GrpcApplication

type GrpcApplication interface {
	GetServer() *grpc.Server

GrpcApplication represents a gRPC Application

type HookFunc

type HookFunc func(Application) error

HookFunc when app starting and tearing down

type HookType

type HookType byte

HookType for hook

const (
	// ConfigHook is a hook type for config
	ConfigHook HookType = iota
	// LoggerHook is a hook type for logger
	// ServiceHook is a hook type for service
	// RouterHook is a hook type for router
	// ShutdownHook is a hook type for shutting down

type MysqlManager added in v0.1.1

type MysqlManager struct {
	App    Application `inject:"app"`
	Config config.MysqlConfig
	// contains filtered or unexported fields

MysqlManager for mysql connection

func NewMysqlManager added in v0.1.1

func NewMysqlManager(app Application, config config.MysqlConfig) (*MysqlManager, error)

NewMysqlManager returns a new MysqlManager

func (*MysqlManager) DB added in v0.1.1

func (mm *MysqlManager) DB(name string) *xorm.Engine

DB gets databases by name

func (*MysqlManager) R added in v0.1.1

func (mm *MysqlManager) R() *xorm.Engine

R get read-only mysql Engine

func (*MysqlManager) SetDB added in v0.1.2

func (mm *MysqlManager) SetDB(name string, engine *xorm.Engine) bool

SetDB sets database by name

func (*MysqlManager) W added in v0.1.1

func (mm *MysqlManager) W() *xorm.Engine

W gets master mysql Engine

type WebApp

type WebApp struct {
	Router *echo.Echo

WebApp is the concrete type of WebApplication

func NewWebApp

func NewWebApp() *WebApp

NewWebApp returns a new web app

func (*WebApp) GetRouter

func (app *WebApp) GetRouter() *echo.Echo

GetRouter gets router

func (*WebApp) Initialize

func (app *WebApp) Initialize()

Initialize web application

func (*WebApp) ListenAndServe

func (app *WebApp) ListenAndServe()

ListenAndServe the web application

func (*WebApp) SetRouter

func (app *WebApp) SetRouter(r *echo.Echo)

SetRouter sets router

type WebApplication

type WebApplication interface {
	GetRouter() *echo.Echo

WebApplication interface represents a web application


Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL