common

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2020 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GlobalIsDebugMode bool
	GlobalEnvName     string
)

常用全局变量

Functions

func CollectionName

func CollectionName(collectName string) string

CollectionName 获取 默认 mongo collection name

func CollectionNameN

func CollectionNameN(name, collectName string) string

CollectionNameN 获取 指定 mongo collection name

func Init added in v1.0.1

func Init(opt *Opt)

Init common 不可以有 init 方法, 统一放在 这里��

func InitLogger added in v1.0.0

func InitLogger(logs map[string]*log4gopulus.Config)

InitLogger 初始化日志器

func InitMgo added in v1.0.0

func InitMgo(mgos map[string]*MgoConfig)

InitMgo ...

func InitRedigo added in v1.0.0

func InitRedigo(redigos map[string]*RedigoConfig)

InitRedigo ...

func InitSQLDB added in v1.0.0

func InitSQLDB(sqls map[string]*SQLConfig)

InitSQLDB ...

func ParseLogger added in v1.0.0

func ParseLogger() map[string]*log4gopulus.Config

ParseLogger 解析所有日志器配置

func ParseMgo added in v1.0.0

func ParseMgo() map[string]*MgoConfig

ParseMgo ...

func ParseRedigo added in v1.0.0

func ParseRedigo() map[string]*RedigoConfig

ParseRedigo ...

func ParseSQLDB added in v1.0.0

func ParseSQLDB() map[string]*SQLConfig

ParseSQLDB ...

Types

type MgoConfig

type MgoConfig struct {
	Addr                string `yml:"addr,omitempty" json:"addr,omitempty"`
	AuthSource          string `yml:"auth_source,omitempty" json:"auth_source,omitempty"`
	Username            string `yml:"username,omitempty" json:"username,omitempty"`
	Password            string `yml:"password,omitempty" json:"password,omitempty"`
	DB                  string `yml:"db,omitempty" json:"db,omitempty"`
	PoolLimit           int    `yml:"pool_limit,omitempty" json:"pool_limit,omitempty"`
	PoolTimeout         int    `yml:"pool_timeout,omitempty" json:"pool_timeout,omitempty"`
	MaxIdleTime         int    `yml:"max_idle_time,omitempty" json:"max_idle_time,omitempty"`
	Timeout             int    `yml:"timeout,omitempty" json:"timeout,omitempty"`
	IsUseTestCollection bool   `yml:"is_use_test_collection,omitempty" json:"is_use_test_collection,omitempty"` // 是否在 collection name 后加 .test  一个业务需求
}

MgoConfig mongoDB configuration

func (*MgoConfig) Conn

func (m *MgoConfig) Conn() (*mgo.Database, error)

Conn Conn

type Opt added in v1.0.1

type Opt struct {
	EnvName     string
	StartType   StartType
	IsDebugMode bool
}

Opt ...

type RedigoConfig

type RedigoConfig struct {
	Addr        string `yml:"addr,omitempty" json:"addr,omitempty"`
	Auth        string `yml:"auth,omitempty" json:"auth,omitempty"`
	DB          int    `yml:"db,omitempty" json:"db,omitempty"`
	MaxIdle     int    `yml:"max_idle,omitempty" json:"max_idle,omitempty"` // pool
	MaxActive   int    `yml:"max_active,omitempty" json:"max_active,omitempty"`
	IdleTimeout int    `yml:"idle_timeout,omitempty" json:"idle_timeout,omitempty"`
	PingRate    int    `yml:"ping_rate,omitempty" json:"ping_rate,omitempty"` // ping 的 频率 单位 /秒
}

RedigoConfig RedigoConfig

func (*RedigoConfig) Conn

func (redigoConfig *RedigoConfig) Conn() (redigo.Conn, error)

Conn Conn

func (*RedigoConfig) Pool

func (redigoConfig *RedigoConfig) Pool() *redigo.Pool

Pool Pool

type SQLConfig

type SQLConfig struct {
	DriverName   string `yml:"driver_name,omitempty" json:"driver_name,omitempty"`
	MaxOpenConns int    `yml:"max_open_conns,omitempty" json:"max_open_conns,omitempty"`
	MaxIdleConns int    `yml:"max_idle_conns,omitempty" json:"max_idle_conns,omitempty"`
	User         string `yml:"user,omitempty" json:"user,omitempty"`       // Username
	Passwd       string `yml:"passwd,omitempty" json:"passwd,omitempty"`   // Password (requires User)
	Net          string `yml:"net,omitempty" json:"net,omitempty"`         // Network type
	Addr         string `yml:"addr,omitempty" json:"addr,omitempty"`       // Network address (requires Net)
	DBName       string `yml:"db_name,omitempty" json:"db_name,omitempty"` // Database name
}

SQLConfig SQLConfig

func (*SQLConfig) Open

func (sqlConfig *SQLConfig) Open() (*sql.DB, error)

Open Open

func (*SQLConfig) ToDSN

func (sqlConfig *SQLConfig) ToDSN() string

ToDSN ToDSN

type StartType added in v1.0.1

type StartType int

StartType 启动类型

const (
	StartTypeWeb StartType = iota
	StartTypeScfgw
)

常量

Jump to

Keyboard shortcuts

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