GRcpConfig

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

README

gconfig-client

基于gRPC协议,集群配置中心客户端程序

Install

go get github.com/ldongpo/gconfig-client

添加环境变量:

用于配置中心服务端微服务地址

export GO_GRPC_CONFIG_SERVER_HOST="127.0.0.1:9090"

添加环境变量:

  • GO_GRPC_CONFIG_ENV:环境
  • GO_GRPC_CONFIG_NAMESPACE:命名空间
  • GO_GRPC_CONFIG_PROJECT:项目
  • GO_GRPC_CONFIG_VERSION:版本
export GO_GRPC_CONFIG_ENV=PROD
export GO_GRPC_CONFIG_NAMESPACE="ecsemir"
export GO_GRPC_CONFIG_PROJECT="天枢"
export GO_GRPC_CONFIG_VERSION="v1.0.1"

其他配置:

  • GO_GRPC_CONFIG_SHOW_CHANGE_LOG 是否显示配置文件更新提示 hidden:不显示,其他值显示
export GO_GRPC_CONFIG_SHOW_CHANGE_LOG="hidden"

服务端代码(暂未上传)

代码示例:
package main

import (
	"fmt"
	"github.com/ldongpo/gconfig-client"
)

func main() {
	val := GRcpConfig.C.Get("redis.db")
	fmt.Println("db:",val)
}

感谢:

viper

kitex

Documentation

Index

Constants

View Source
const (
	FN  = "application" //生成配置文件的名称
	Ext = "json"        //生成配置文件的后缀

	ServerHost = "GO_GRPC_CONFIG_SERVER_HOST" //服务端地址
	ENV        = "GO_GRPC_CONFIG_ENV"         //环境
	NAMESPACE  = "GO_GRPC_CONFIG_NAMESPACE"   //命名空间
	PROJECT    = "GO_GRPC_CONFIG_PROJECT"     //项目
	VERSION    = "GO_GRPC_CONFIG_VERSION"     //版本

)

Variables

View Source
var (
	I *info
)

Functions

func OnConfigChange added in v1.1.4

func OnConfigChange()

Types

type GRcpConfig

type GRcpConfig struct {
	// contains filtered or unexported fields
}
var (
	C *GRcpConfig
)

func (*GRcpConfig) AllSettings

func (g *GRcpConfig) AllSettings() map[string]interface{}

func (*GRcpConfig) DelConfig added in v1.1.0

func (g *GRcpConfig) DelConfig() error

DelConfig @Author liangdongpo @Description 删除缓存**慎用,安排默认参数,会把此环境、命名空间、项目、版本条件的缓存都删除 @Date 12:35 下午 2021/11/18 @Param @return

func (*GRcpConfig) DelConfigParam added in v1.1.3

func (g *GRcpConfig) DelConfigParam(env string, namespace string, project string, version string) error

DelConfigParam @Author liangdongpo @Description 删除缓存,按传来的参数 @Date 2:24 下午 2021/11/18 @Param @return

func (*GRcpConfig) Get

func (g *GRcpConfig) Get(key string) interface{}

Get @Author liangdongpo @Description 获取某个缓存,只支持默认参数下 @Date 2:25 下午 2021/11/18 @Param @return

func (*GRcpConfig) GetAll added in v1.1.1

func (g *GRcpConfig) GetAll() (string, error)

GetAll @Author liangdongpo @Description 获取所有配置,按默认的参数:string 类型 @Date 12:45 下午 2021/11/18 @Param @return

func (*GRcpConfig) GetAllParam added in v1.1.2

func (g *GRcpConfig) GetAllParam(env string, namespace string, project string, version string) (string, error)

GetAllParam @Author liangdongpo @Description 自定义参数获取全部配置 @Date 1:38 下午 2021/11/18 @Param @return

func (*GRcpConfig) GetBool

func (g *GRcpConfig) GetBool(key string) bool

GetBool 获取bool 类型 支持默认参数

func (*GRcpConfig) GetDuration

func (g *GRcpConfig) GetDuration(key string) time.Duration

func (*GRcpConfig) GetFloat64

func (g *GRcpConfig) GetFloat64(key string) float64

func (*GRcpConfig) GetInt

func (g *GRcpConfig) GetInt(key string) int

GetInt 获取int 类型 支持默认参数

func (*GRcpConfig) GetInt32

func (g *GRcpConfig) GetInt32(key string) int32

func (*GRcpConfig) GetInt64

func (g *GRcpConfig) GetInt64(key string) int64

func (*GRcpConfig) GetIntSlice

func (g *GRcpConfig) GetIntSlice(key string) []int

func (*GRcpConfig) GetSizeInBytes

func (g *GRcpConfig) GetSizeInBytes(key string) uint

func (*GRcpConfig) GetString

func (g *GRcpConfig) GetString(key string) string

GetString @Author liangdongpo @Description 获取string类型的缓存,只支持默认参数下 @Date 2:30 下午 2021/11/18 @Param @return

func (*GRcpConfig) GetStringMap

func (g *GRcpConfig) GetStringMap(key string) map[string]interface{}

func (*GRcpConfig) GetStringMapString

func (g *GRcpConfig) GetStringMapString(key string) map[string]string

func (*GRcpConfig) GetStringMapStringSlice

func (g *GRcpConfig) GetStringMapStringSlice(key string) map[string][]string

func (*GRcpConfig) GetStringSlice

func (g *GRcpConfig) GetStringSlice(key string) []string

func (*GRcpConfig) GetTime

func (g *GRcpConfig) GetTime(key string) time.Time

func (*GRcpConfig) GetUint

func (g *GRcpConfig) GetUint(key string) uint

func (*GRcpConfig) GetUint32

func (g *GRcpConfig) GetUint32(key string) uint32

func (*GRcpConfig) GetUint64

func (g *GRcpConfig) GetUint64(key string) uint64

func (*GRcpConfig) PutConfig added in v1.1.0

func (g *GRcpConfig) PutConfig(data string) error

PutConfig @Author liangdongpo @Description 设置缓存,按默认参数 @Date 12:33 下午 2021/11/18 @Param @return

func (*GRcpConfig) PutConfigParam added in v1.1.3

func (g *GRcpConfig) PutConfigParam(env string, namespace string, project string, version string, data string) error

PutConfigParam @Author liangdongpo @Description 设置缓存,按传来的参数 @Date 2:23 下午 2021/11/18 @Param @return

Directories

Path Synopsis
kitex_gen
grpcConfig/grpcconfig
Code generated by Kitex v0.1.0.
Code generated by Kitex v0.1.0.

Jump to

Keyboard shortcuts

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