Documentation ¶
Index ¶
- func HTPPAddr(address string) string
- func MakeDirAll(dir string) string
- type ChangeListener
- type ClientReportItem
- type ClientReportRspItem
- type Conf
- type ConfFile
- type ConfFileChangeEvent
- type ConfFmt
- type ConfigService
- type Context
- func (c *Context) GetConfigServers() []string
- func (c *Context) LoadConfCache(confFile string) *FileContent
- func (c *Context) LoadConfFile(confFile string) ConfFile
- func (c *Context) UpdateConfigServers(servers []string) bool
- func (c *Context) WalkFileContents(fn func(confFile string, fileContext *FileContent))
- type ContextConfig
- type FileContent
- type FileRaw
- type FileRawWait
- type MetaService
- type PollingService
- type Prop
- type PropertiesConfFile
- func (p *PropertiesConfFile) Bool(name string) bool
- func (p *PropertiesConfFile) BoolOr(name string, defaultValue bool) bool
- func (p *PropertiesConfFile) ConfFormat() ConfFmt
- func (p *PropertiesConfFile) Float32(name string) float32
- func (p *PropertiesConfFile) Float32Or(name string, defaultValue float32) float32
- func (p *PropertiesConfFile) Float64(name string) float64
- func (p *PropertiesConfFile) Float64Or(name string, defaultValue float64) float64
- func (p *PropertiesConfFile) Int(name string) int
- func (p *PropertiesConfFile) Int32(name string) int32
- func (p *PropertiesConfFile) Int32Or(name string, defaultValue int32) int32
- func (p *PropertiesConfFile) Int64(name string) int64
- func (p *PropertiesConfFile) Int64Or(name string, defaultValue int64) int64
- func (p *PropertiesConfFile) IntOr(name string, defaultValue int) int
- func (p *PropertiesConfFile) Str(name string) string
- func (p *PropertiesConfFile) StrOr(name, defaultValue string) string
- type RawConfFile
- type Runner
- func (r *Runner) ConfFile(confFile string) (ConfFile, error)
- func (r *Runner) ConsumeChan()
- func (r *Runner) ListenerResults(confFile, crc string) ([]ClientReportRspItem, error)
- func (r *Runner) PostConf(confFile, raw, clientIps string) (string, error)
- func (r *Runner) Properties(confFile string) (*PropertiesConfFile, error)
- func (r *Runner) Register(filename string, l ChangeListener)
- func (r *Runner) Start()
- func (r *Runner) Stop()
- func (r *Runner) Unregister(filename string, listener ChangeListener) int
- func (r *Runner) UnregisterAll(filename string)
- type SnapshotService
- func (s SnapshotService) Clear(confFile string) error
- func (s SnapshotService) Load(file string) error
- func (s SnapshotService) LoadMeta() string
- func (s SnapshotService) Save(confFile, content string)
- func (s SnapshotService) SaveMeta(configServerUrls []string)
- func (s SnapshotService) SaveUpdates(fcs []FileContent)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MakeDirAll ¶
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
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 ¶
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.
func ConfFmtString ¶
ConfFmtString retrieves an enum value from the enum constants string name. Throws an error if the param is not part of the enum.
func (ConfFmt) IsAConfFmt ¶
IsAConfFmt returns "true" if the value is listed in the enum definition. "false" otherwise
func (ConfFmt) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface for ConfFmt
func (*ConfFmt) UnmarshalJSON ¶
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 ¶
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 ¶
LoadConfFile loads the conf file by name confFile.
func (*Context) UpdateConfigServers ¶
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 ¶
FileRawWait structured the config file content detail.
type MetaService ¶
MetaService defines the meta refreshing service.
func (MetaService) Start ¶
func (m MetaService) Start(ctx context.Context)
Start starts the meta refreshing loop
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) 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 ¶
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) Unregister ¶
func (r *Runner) Unregister(filename string, listener ChangeListener) int
Unregister removes the register of the change listener of conf file
func (*Runner) UnregisterAll ¶
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.