typhon4g

package module
v1.0.2 Latest Latest
Warning

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

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

README

typhon4g

Travis CI Software License GoDoc Coverage Status goreport

typhon/apollo client for golang

Setup config file like the following:

# $PWD/etc/typhon-context.properties

# 应用程序id
appId = a100

# 配置中心服务器类型: apollo, typhon, 默认typhon
serverType = apollo


# 以下是apollo专有
cluster    = default
dataCenter = 
# localIp不配置的话,默认获取en0/eth0网卡的v4版本的IP地址
localIp    =

# Meta服务器地址列表,多个时以英文逗号分隔
metaServers = http://127.0.0.1:11683
# 配置服务器列表,多个时以英文逗号分隔(如果meta不填,则需要填写此项)
configServers = 
# 配置刷新时间间隔,默认5分钟
configRefreshInterval = 5m
# 配置刷新是读取超时时间,默认5s
# configReadTimeout = 5s
# Http连接超时时间,默认60s
# connectTimeout = 60s
# 长连接保持时间,默认70秒,服务器端是一分钟,这里配置比服务器端多一点点即可
# pollingReadTimeout = 70s

# 快照存储目录,不配置时,默认 ~/.typhon-client/snapshots
# snapshotsDir = ~/.typhon-client/snapshots
snapshotsDir = ./etc/snapshots

# meta server/config server连接不上时,等待重试的时间,默认60秒
# retryNetworkSleep = 60s

# 配置主动刷新时间间隔,默认5分钟
# configRefreshInterval = 5m

# Meta主动刷新时间间隔,默认5分钟
# metaRefreshInterval = 5m

# 推送配置所需要的用户名密码
# postAuth = admin:admin

# 服务端证书校验用的根证书文件(不校验服务端证书时,请注释本配置项)
#rootPem = ./root.pem

# 提供给服务端校验的客户端证书文件和客户端私钥文件(服务端不需要校验时,请注释两个配置项)
#clientPem = ./client.pem
#clientKey = ./client.key

Use the api to access config

package main

import (
    "fmt"
    "github.com/spf13/viper"
	"github.com/bingoohuang/typhon4g"
)
 
func init() {
    // 注册viper读取
    ty := typhon4g.LoadStart()
	ty.Register("application.properties", &typhon4g.ViperListener{Prefix:""})
	ty.Register("hello.yaml", &typhon4g.ViperListener{Prefix:"hello."})
}

func main() {
    fmt.Println("name:", viper.GetString("name"))
    fmt.Println("age:", viper.GetInt("hello.age"))
    fmt.Println("adult", viper.GetBool("hello.adult"))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadContext

func LoadContext(reader io.Reader) (*base.Context, error)

LoadContext loads the typhon context by reader.

func LoadContextFile

func LoadContextFile(contextFile string) (*base.Context, error)

LoadContextFile load the typhon context by file contextFile

func LoadStart

func LoadStart() *base.Runner

LoadStart loads and starts the typhon client.

func LoadStartByContext

func LoadStartByContext(context *base.Context) *base.Runner

LoadStartByContext load the runner from the context.

func LoadStartByFile

func LoadStartByFile(typhonContextFile string) *base.Runner

LoadStartByFile loads and starts the typhon client.

func LoadStartByFileE

func LoadStartByFileE(typhonContextFile string) (*base.Runner, error)

LoadStartByFileE loads and starts the typhon client.

func LoadStartE

func LoadStartE() (*base.Runner, error)

LoadStartE loads and starts the typhon client.

func ViperUnset

func ViperUnset(key string) error

ViperUnset unset the viper key.

Types

type ChangeType

type ChangeType int

ChangeType defines the type of chaging.

const (
	// Modified ...
	Modified ChangeType = iota
	// Added ...
	Added
	// Removed ...
	Removed
	// Same ...
	Same
)

type DiffItem

type DiffItem struct {
	ChangeType ChangeType
	Key        interface{}
	LeftValue  interface{}
	RightValue interface{}
}

DiffItem defines ChangeEvent for properties diff

func DiffMap

func DiffMap(a, b interface{}) []DiffItem

DiffMap compares two map.

type ViperListener

type ViperListener struct {
	Prefix string
}

ViperListener defines the viper setter listener

func (ViperListener) OnChange

func (l ViperListener) OnChange(event base.ConfFileChangeEvent) (msg string, ok bool)

OnChange defines the callback when changes detected.

Directories

Path Synopsis
cmd
typhon4gdemo
nolint gomnd
nolint gomnd

Jump to

Keyboard shortcuts

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