51 lines
1.1 KiB
Go
Executable File
51 lines
1.1 KiB
Go
Executable File
package config
|
|
|
|
import (
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// ServerInfo 服务器信息
|
|
type ServerInfo struct {
|
|
AppName string `json:"appName"`
|
|
InstanceID string `json:"instanceId"`
|
|
HomepageURL string `json:"homepageUrl"`
|
|
IsDown bool `json:"-"`
|
|
}
|
|
|
|
// AppConfig 配置文件
|
|
type AppConfig struct {
|
|
AppID string `json:",optional"`
|
|
Cluster string `json:",optional"`
|
|
NamespaceName string `json:",optional"`
|
|
IP string `json:",optional"`
|
|
NextTryConnTime int64 `json:",optional"`
|
|
}
|
|
|
|
// GetHost GetHost
|
|
func (a *AppConfig) GetHost() string {
|
|
if strings.HasPrefix(a.IP, "http") {
|
|
if !strings.HasSuffix(a.IP, "/") {
|
|
return a.IP + "/"
|
|
}
|
|
return a.IP
|
|
}
|
|
return "http://" + a.IP + "/"
|
|
}
|
|
|
|
// SetNextTryConnTime if this connect is fail will set this time
|
|
func (a *AppConfig) SetNextTryConnTime(nextTryConnectPeriod int64) {
|
|
a.NextTryConnTime = time.Now().Unix() + nextTryConnectPeriod
|
|
}
|
|
|
|
// IsConnectDirectly is connect by ip directly
|
|
// false : no
|
|
// true : yes
|
|
func (a *AppConfig) IsConnectDirectly() bool {
|
|
if a.NextTryConnTime >= 0 && a.NextTryConnTime > time.Now().Unix() {
|
|
return true
|
|
}
|
|
|
|
return false
|
|
}
|