cinit

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2019 License: MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

公共配置和初始化

Documentation

Index

Constants

View Source
const (
	ReqParam        = "req_param"     //  请求参数绑定
	JWTName         = "Authorization" //  JWT请求头名称
	JWTMsg          = "JWT-MSG"       //  JWT自定义的消息
	FloatComputeBit = 2               //  浮点计算位数
)
View Source
const (
	MySQL    = "MySQL"
	Trace    = "Trace"
	Mongo    = "Mongo"
	Redis    = "Redis"
	Kafka    = "Kafka"
	Metrics  = "Metrics"
	Postgres = "Postgres"
)

服务名称

View Source
const (
	TopicSrvKeyChange = "user_msg_change"
)

Variables

View Source
var Config = struct {
	Service struct {
		Name      string `default:""`     //  服务名称
		Version   string `default:"v1.0"` //  服务版本号
		RateTime  int    `default:"1024"` //  限制请求
		AppKey    string `default:"admin"`
		AppSecret string `default:"admin"`
	}
	//  tracing
	Trace struct {
		Address       string  `default:"http://jaeger:14268/api/traces?format=jaeger.thrift"` //  http://jaeger:14268/api/traces?format=jaeger.thrift
		ZipkinURL     string  `default:""`                                                    //  http://zipkin:9411/api/v1/spans
		SamplingRate  float64 `default:"0.1"`                                                 //  采样率 0.01-1范围
		LogTraceSpans bool    `default:"false"`                                               //  日志
	}
	//  log config
	Log struct {
		Path         string `default:"tmp"`   //  日志保存路径
		IsStdOut     string `default:"yes"`   //  是否输出日志到标准输出 yes:输出 no:不输出
		MaxAge       int    `default:"7"`     //  日志最大的保存时间,单位天
		RotationTime int    `default:"1"`     //  日志分割的时间,单位天
		MaxSize      int    `default:"100"`   //  日志分割的尺寸,单位MB
		LogLevel     string `default:"debug"` //  日志级别
	}
	//  mysql config
	Mysql struct {
		DbName   string `default:"guess"`     // 数据库名称
		Addr     string `default:"127.0.0.1"` // 地址
		User     string `default:"root"`
		Password string `default:"root"`
		Port     int    `default:"3306"` // required:"true" env:"DB_PROT"
		IDleConn int    `default:"4"`    // 空闲连接
		MaxConn  int    `default:"20"`   // 最大连接
	}
	// mysql config
	Postgres struct {
		DbName   string `default:"test"`      // 数据库名称
		Addr     string `default:"127.0.0.1"` // 地址
		User     string `default:"postgres"`
		Password string `default:"postgres"`
		Port     int    `default:"5432"` // required:"true"
		IDleConn int    `default:"4"`    // 空闲连接
		MaxConn  int    `default:"20"`   // 最大连接
	}
	// redis config
	Redis struct {
		Addr     string `default:"127.0.0.1:6379"` // 地址
		Password string `default:""`
		Db       int    `default:"0"`
	}
	// mongo config
	Mongo struct {
		Hosts     string `default:"127.0.0.1:27017"` // 数据库地址,可以多个,用逗号分割
		DbName    string `default:"test"`            // 数据库名称
		User      string `default:"root"`
		Password  string `default:"root"`
		PoolLimit int    `default:"4096"` // 连接池限制
	}
	Kafka struct {
		Addrs string `default:"127.0.0.1:9092"` // 数据库地址,可以多个,用逗号分割
	}
	// metrics config
	Metrics struct {
		Enable   string `default:"yes"` // 是否启用:yes 启用 no 停用
		Duration int    `default:"5"`   // 单位秒
		URL      string `default:"http://influxdb:8086"`
		Database string `default:"test01"`
		UserName string `default:""`
		Password string `default:""`
	}

	// userservice
	SrvUser struct {
		Port              string `default:":5001"`          // 定义的端口
		Address           string `default:"127.0.0.1:5001"` // 访问地址
		GateWayAddr       string `default:":9999"`          // 网关端口
		GateWaySwaggerDir string `default:"/swagger"`       //  swagger目录
	}
	// accountservice
	SrvAccount struct {
		Port              string `default:":5003"`          // 定义的端口
		Address           string `default:"127.0.0.1:5003"` // 访问地址
		GateWayAddr       string `default:":9997"`          // 网关端口
		GateWaySwaggerDir string `default:"/swagger"`       //  swagger目录
	}
	// api backend
	APIBackend struct {
		Port    string `default:":8888"`
		Address string `default:"127.0.0.1:8888"`
	}
	// api backend
	APIFrontend struct {
		Port    string `default:":8889"`
		Address string `default:"127.0.0.1:8889"`
	}
	// gamesocket
	SrvSocket struct {
		Port    string `default:":5002"`          // 定义的端口
		Address string `default:"127.0.0.1:5002"` // 访问地址
	}
}{}

Config 公共配置

View Source
var Mysql *sqlx.DB
View Source
var Pg *sqlx.DB
View Source
var RedisCli *redis.Client

Functions

func Close

func Close()

关闭打开的服务

func InitOption

func InitOption(sn string, args ...string)

初始化选项// log:日志(必须) trace:链路跟踪 mysql:mysql数据库 mongo:MongoDB postgres:postgres数据库

func KafkaClose

func KafkaClose()

关闭

func KafkaInit

func KafkaInit()

初始化连接

Types

This section is empty.

Jump to

Keyboard shortcuts

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