coord_cfg

package module
v0.0.0-...-1af5e41 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2021 License: MIT Imports: 18 Imported by: 0 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

cfg 配置中心

  • 读取配置顺序 内存缓存 -> Redis -> Mysql -> 本地Yaml文件 -> 环境变量
  • 以Mysql数据为基准数据, 每次设置会更新Mysql , 同时清空缓存
  • 提供grpc 接口 ,提供grpc-gateway 形式作为http接口,进行数据读取
  • 也可以导入组合成到项目中去使用,由于是独立的项目,也避免了循环导包的尴尬
todo :
  1. etcd 作为存储介质,然后增加同步内存缓存策略
  2. websocket接口

Documentation

Index

Constants

View Source
const (
	// yaml配置文件 环境变量键名
	YamlFileEnvKey  = "CFG_YAML"
	YamlDefaultPath = "application.yaml"

	// db 相关
	MysqlUserKey     = "DB_MYSQL_USER"
	DefaultMYSQLUser = "root"
	MysqlPwdKey      = "DB_MYSQL_PWD"
	DefaultMYSQLPwd  = "mysql"
	MysqlHostKey     = "DB_MYSQL_HOST"
	DefaultMYSQLHost = "127.0.0.1"
	MysqlPortKey     = "DB_MYSQL_USER"
	DefaultMYSQLPort = "3306"
	MysqlDBKey       = "DB_MYSQL_DB"
	DefaultMYSQLDB   = "cfg_db"

	// redis
	RedisHostKey     = "DB_REDIS_HOST"
	DefaultRedisHost = "127.0.0.1"
	RedisPortKey     = "DB_REDIS_PORT"
	DefaultRedisPort = "6379"
	RedisPwdKey      = "DB_REDIS_PWD"
	DefaultRedisPwd  = ""
	RedisDBKey       = "DB_REDIS_DB"
	DefaultRedisDB   = "1"

	// 缓存相关默认值
	DefaultCacheTime = 3600 * time.Second
	ScanInterval     = 30 * time.Second

	// grpc
	GrpcHostKey     = "SERVER_GRPC_HOST"
	GrpcPortKey     = "SERVER_GRPC_PORT"
	GrpcDefaultHost = "0.0.0.0"
	GrpcDefaultPort = 7720

	// grpc 网关
	GrpcGateWayHostKey     = "SERVER_GRPC_GATEWAY_HOST"
	GrpcGateWayPortKey     = "SERVER_GRPC_GATEWAY_PORT"
	GrpcGateWayDefaultHost = "0.0.0.0"
	GrpcGateWayDefaultPort = 7721
)

Variables

This section is empty.

Functions

func Get

func Get(ctx context.Context, k string, defaultV ...string) (v string)

读取环境变量逻辑

func Json

func Json(v interface{}) string

func Set

func Set(ctx context.Context, k, v string) error

设置配置逻辑

func StandCode

func StandCode(code string) string

配置文件 code 的标准命名,存DB和程序运行中都存储的该命名

最终目标 server.env => SERVER_ENV

func Yaml2Map

func Yaml2Map(data3 []byte) map[string]interface{}

Types

type Config

type Config struct {
	Code    string `xorm:"varchar(64) pk" remark:"配置编码"`
	Name    string `xorm:"varchar(32)" remark:"配置名称"`
	Value   string `xorm:"text" remark:"配置值"`
	Remark  string `xorm:"text" remark:"配置备注"`
	Version int64  `xorm:"version index"`
	Created int64  `xorm:"created" remark:"创建时间"`
	Updated int64  `xorm:"updated" remark:"更新时间"`
	Deleted int64  `xorm:"deleted default(0)" remark:"删除时间"`
}

type ConfigStatus

type ConfigStatus int8

type I

type I interface{}

Directories

Path Synopsis
Package proto is a reverse proxy.
Package proto is a reverse proxy.

Jump to

Keyboard shortcuts

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