base

package
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: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTPPAddr

func HTPPAddr(address string) string

HTPPAddr try to prepends the http:// to the address

func MakeDirAll

func MakeDirAll(dir string) string

MakeDirAll make sure the mkdir all success or panic

Types

type ChangeListener

type ChangeListener interface {
	OnChange(event ConfFileChangeEvent) (string, bool)
}

ChangeListener defines the interface for change listener

type ClientReportItem

type ClientReportItem struct {
	Time     string `json:"time"`
	Msg      string `json:"msg"`
	Ok       bool   `json:"ok"`
	ConfFile string `json:"confFile"`
	Crc      string `json:"crc"`
}

ClientReportItem defines the structure of client listener report item.

type ClientReportRspItem

type ClientReportRspItem struct {
	ID    string `json:"id"`
	AppID string `json:"appID"`
	Host  string `json:"host"`
	Pid   string `json:"pid"`
	Bin   string `json:"bin"`
	ClientReportItem
}

ClientReportRspItem defines the structure of response to client report querying.

type Conf

type Conf struct {
	// contains filtered or unexported fields
}

Conf defines the base structure of conf file

func (*Conf) Name

func (b *Conf) Name() string

Name gets the name of conf file

func (*Conf) Raw

func (b *Conf) Raw() string

Raw gets the raw content of conf file

func (*Conf) UpdateRaw

func (b *Conf) UpdateRaw(updated string)

UpdateRaw update the raw content of conf file

type ConfFile

type ConfFile interface {
	// Raw gets the raw content of conf file
	Raw() string
	// ConfFormat gets the format of conf file
	ConfFormat() ConfFmt
	// Name gets the name of conf file
	Name() string
	// UpdateRaw update the raw content of conf file
	UpdateRaw(updated string)
}

ConfFile defines the interface of a typhon conf file.

func NewConfFile

func NewConfFile(confFile, raw string) ConfFile

NewConfFile creates a ConfFile interface by confFile and raw content.

type ConfFileChangeEvent

type ConfFileChangeEvent struct {
	ConfFile    string    `json:"confFile"`
	Old         string    `json:"old"`
	Current     string    `json:"current"`
	ChangedTime time.Time `json:"changedTime"` // 变更发生的时间(毫秒)
}

ConfFileChangeEvent structured the change event content.

type ConfFmt

type ConfFmt int

ConfFmt defines the conf file format.

const (
	// PropertiesFmt means the conf file is in *.properties format.
	PropertiesFmt ConfFmt = iota
	// TxtFmt means the conf file is in *.txt format.
	TxtFmt
)

func ConfFmtString

func ConfFmtString(s string) (ConfFmt, error)

ConfFmtString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.

func ConfFmtValues

func ConfFmtValues() []ConfFmt

ConfFmtValues returns all values of the enum

func (ConfFmt) IsAConfFmt

func (i ConfFmt) IsAConfFmt() bool

IsAConfFmt returns "true" if the value is listed in the enum definition. "false" otherwise

func (ConfFmt) MarshalJSON

func (i ConfFmt) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for ConfFmt

func (ConfFmt) String

func (i ConfFmt) String() string

func (*ConfFmt) UnmarshalJSON

func (i *ConfFmt) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface for ConfFmt

type ConfigService

type ConfigService struct {
	*Context
}

ConfigService defines the structure used for config refresh/write service

func (*ConfigService) Start

func (c *ConfigService) Start(ctx context.Context)

Start starts the refreshing loop of config service.

type Context

type Context struct {
	ContextConfig

	Cache map[string]*FileContent // file->content

	Req     *gonet.ReqOption
	ReqPoll *gonet.ReqOption

	Client configClient

	MetaServersParsed   []string
	ConfigServersParsed []string

	FileRawChan chan FileRawWait
	// contains filtered or unexported fields
}

Context defines the context of typhon client.

func (*Context) GetConfigServers

func (c *Context) GetConfigServers() []string

GetConfigServers gets the config servers.

func (*Context) LoadConfCache

func (c *Context) LoadConfCache(confFile string) *FileContent

LoadConfCache load the config from the cache.

func (*Context) LoadConfFile

func (c *Context) LoadConfFile(confFile string) ConfFile

LoadConfFile loads the conf file by name confFile.

func (*Context) UpdateConfigServers

func (c *Context) UpdateConfigServers(servers []string) bool

UpdateConfigServers updates the config server addresses.

func (*Context) WalkFileContents

func (c *Context) WalkFileContents(fn func(confFile string, fileContext *FileContent))

WalkFileContents walks the cache.

type ContextConfig

type ContextConfig struct {
	// 配置中心服务器类型: apollo, typhon, 默认typhon
	ServerType string

	// 以下是apollo专有
	Cluster    string `default:"default"`
	DataCenter string
	LocalIP    string

	// AppID defines the global appID of the typhon client.
	AppID string `validate:"empty=false"`

	// MetaServers defines the meta servers.
	MetaServers string

	// ConfigServers defines the config servers.
	ConfigServers string

	// ConnectTimeoutMillis defines the http connect timeout in millis.
	ConnectTimeout time.Duration `default:"60s"`
	// PollingReadTimeoutMillis defines the read timeout in millis of config polling
	PollingReadTimeout time.Duration `default:"70s"`
	// RetryNetworkSleepSeconds defines the sleeping time in seconds before retry.
	RetryNetworkSleep time.Duration `default:"60s"`
	// ConfigRefreshIntervalSeconds defines the refresh loop interval of config service.
	ConfigRefreshInterval time.Duration `default:"5m"`
	// ConfigReadTimeoutMillis defines the read timeout in millis of config service.
	ConfigReadTimeout time.Duration `default:"5s"`
	// MetaRefreshIntervalSeconds defines the refresh loop interval of meta service.
	MetaRefreshInterval time.Duration `default:"5m"`
	// SnapshotsDir defines the snapshot directory of config.
	SnapshotsDir string

	RootPem   string
	ClientPem string
	ClientKey string
	PostAuth  string
}

ContextConfig defines the structure for the config.

type FileContent

type FileContent struct {
	FileRaw
	// contains filtered or unexported fields
}

FileContent structured the config file content detail.

type FileRaw

type FileRaw struct {
	AppID    string `json:"appID"`
	ConfFile string `json:"confFile"`
	Content  string `json:"content"`
	Crc      string `json:"crc"`
}

FileRaw structured the config file content detail.

type FileRawWait

type FileRawWait struct {
	FileRaw

	Wait                chan bool
	TriggerChangeIgnore bool
	SnapshotIgnore      bool
}

FileRawWait structured the config file content detail.

type MetaService

type MetaService struct {
	*Context
	ConfigServersUpdater func(addr []string)
}

MetaService defines the meta refreshing service.

func (MetaService) Start

func (m MetaService) Start(ctx context.Context)

Start starts the meta refreshing loop

func (MetaService) Try

func (m MetaService) Try()

Try try to refresh meta.

type PollingService

type PollingService struct {
	*Context
}

PollingService defines the polling service.

func (PollingService) Start

func (p PollingService) Start(ctx context.Context)

Start starts the polling service loop.

type Prop

type Prop interface {
	// Str get the string value of key specified by name.
	Str(name string) string
	// StrOr get the string value of key specified by name or defaultValue when value is empty or missed.
	StrOr(name, defaultValue string) string

	// Bool get the bool value of key specified by name.
	Bool(name string) bool
	// BoolOr get the bool value of key specified by name or defaultValue when value is empty or missed.
	BoolOr(name string, defaultValue bool) bool

	// Int get the int value of key specified by name.
	Int(name string) int
	// IntOr get the int value of key specified by name or defaultValue when value is empty or missed.
	IntOr(name string, defaultValue int) int

	// Int32 get the int32 value of key specified by name.
	Int32(name string) int32
	// Int32Or get the int32 value of key specified by name or defaultValue when value is empty or missed.
	Int32Or(name string, defaultValue int32) int32

	// Int64 get the int64 value of key specified by name.
	Int64(name string) int64
	// Int64Or get the int64 value of key specified by name or defaultValue when value is empty or missed.
	Int64Or(name string, defaultValue int64) int64

	// Float32 get the float32 value of key specified by name.
	Float32(name string) float32
	// Float32Or get the float32 value of key specified by name or defaultValue when value is empty or missed.
	Float32Or(name string, defaultValue float32) float32

	// Float64 get the float64 value of key specified by name.
	Float64(name string) float64
	// Float64Or get the float64 value of key specified by name or defaultValue when value is empty or missed.
	Float64Or(name string, defaultValue float64) float64
}

Prop defines the interface of properties.

type PropertiesConfFile

type PropertiesConfFile struct {
	Conf
	Doc *properties.Doc
}

PropertiesConfFile defines the properties format of conf file

func NewPropertiesConfFile

func NewPropertiesConfFile(confFile, raw string) *PropertiesConfFile

NewPropertiesConfFile new a PropertiesConfFile file.

func (*PropertiesConfFile) Bool

func (p *PropertiesConfFile) Bool(name string) bool

Bool get the bool value of key specified by name.

func (*PropertiesConfFile) BoolOr

func (p *PropertiesConfFile) BoolOr(name string, defaultValue bool) bool

BoolOr get the bool value of key specified by name or defaultValue when value is empty or missed.

func (*PropertiesConfFile) ConfFormat

func (p *PropertiesConfFile) ConfFormat() ConfFmt

ConfFormat gets the format of conf file

func (*PropertiesConfFile) Float32

func (p *PropertiesConfFile) Float32(name string) float32

Float32 get the float32 value of key specified by name.

func (*PropertiesConfFile) Float32Or

func (p *PropertiesConfFile) Float32Or(name string, defaultValue float32) float32

Float32Or get the float32 value of key specified by name or defaultValue when value is empty or missed.

func (*PropertiesConfFile) Float64

func (p *PropertiesConfFile) Float64(name string) float64

Float64 get the float64 value of key specified by name.

func (*PropertiesConfFile) Float64Or

func (p *PropertiesConfFile) Float64Or(name string, defaultValue float64) float64

Float64Or get the float64 value of key specified by name or defaultValue when value is empty or missed.

func (*PropertiesConfFile) Int

func (p *PropertiesConfFile) Int(name string) int

Int get the int value of key specified by name.

func (*PropertiesConfFile) Int32

func (p *PropertiesConfFile) Int32(name string) int32

Int32 get the int32 value of key specified by name.

func (*PropertiesConfFile) Int32Or

func (p *PropertiesConfFile) Int32Or(name string, defaultValue int32) int32

Int32Or get the int32 value of key specified by name or defaultValue when value is empty or missed.

func (*PropertiesConfFile) Int64

func (p *PropertiesConfFile) Int64(name string) int64

Int64 get the int64 value of key specified by name.

func (*PropertiesConfFile) Int64Or

func (p *PropertiesConfFile) Int64Or(name string, defaultValue int64) int64

Int64Or get the int64 value of key specified by name or defaultValue when value is empty or missed.

func (*PropertiesConfFile) IntOr

func (p *PropertiesConfFile) IntOr(name string, defaultValue int) int

IntOr get the int value of key specified by name or defaultValue when value is empty or missed.

func (*PropertiesConfFile) Str

func (p *PropertiesConfFile) Str(name string) string

Str get the string value of key specified by name.

func (*PropertiesConfFile) StrOr

func (p *PropertiesConfFile) StrOr(name, defaultValue string) string

StrOr get the string value of key specified by name or defaultValue when value is empty or missed.

type RawConfFile

type RawConfFile struct {
	Conf
}

RawConfFile defines the txt format of conf file

func NewRawConfFile

func NewRawConfFile(confFile, raw string) *RawConfFile

NewRawConfFile new a RawConfFile.

func (*RawConfFile) ConfFormat

func (t *RawConfFile) ConfFormat() ConfFmt

ConfFormat gets the format of conf file

type Runner

type Runner struct {
	*Context
	SnapshotService *SnapshotService
	ConfigService   *ConfigService
	MetaService     *MetaService
	PollingService  *PollingService
	// contains filtered or unexported fields
}

Runner defines the typhon-client typhon service.

func (*Runner) ConfFile

func (r *Runner) ConfFile(confFile string) (ConfFile, error)

ConfFile gets the conf file.

func (*Runner) ConsumeChan

func (r *Runner) ConsumeChan()

ConsumeChan consumes the updating config changes from the channel.

func (*Runner) ListenerResults

func (r *Runner) ListenerResults(confFile, crc string) ([]ClientReportRspItem, error)

ListenerResults get the listener results

func (*Runner) PostConf

func (r *Runner) PostConf(confFile, raw, clientIps string) (string, error)

PostConf posts the conf to the server with clientIps(blank/comma separated or all) returns crc and error.

func (*Runner) Properties

func (r *Runner) Properties(confFile string) (*PropertiesConfFile, error)

Properties gets the properties conf file.

func (*Runner) Register

func (r *Runner) Register(filename string, l ChangeListener)

Register registers the change listener of conf file

func (*Runner) Start

func (r *Runner) Start()

Start start the typhon.

func (*Runner) Stop

func (r *Runner) Stop()

Stop stops the runner.

func (*Runner) Unregister

func (r *Runner) Unregister(filename string, listener ChangeListener) int

Unregister removes the register of the change listener of conf file

func (*Runner) UnregisterAll

func (r *Runner) UnregisterAll(filename string)

UnregisterAll removes all registers of the change listener of conf file

type SnapshotService

type SnapshotService struct {
	*Context
}

SnapshotService defines the snapshot service of typhon client

func (SnapshotService) Clear

func (s SnapshotService) Clear(confFile string) error

Clear clears the snapshot of confFile.

func (SnapshotService) Load

func (s SnapshotService) Load(file string) error

Load loads the snapshot in file.

func (SnapshotService) LoadMeta

func (s SnapshotService) LoadMeta() string

LoadMeta loads meta from snapshot.

func (SnapshotService) Save

func (s SnapshotService) Save(confFile, content string)

Save saves the confFile and its content to snapshot.

func (SnapshotService) SaveMeta

func (s SnapshotService) SaveMeta(configServerUrls []string)

SaveMeta saves the meta to snapshot.

func (SnapshotService) SaveUpdates

func (s SnapshotService) SaveUpdates(fcs []FileContent)

SaveUpdates saves the updates to snapshot.

Jump to

Keyboard shortcuts

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