mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 04:42:33 +02:00
Merge branch 'main' into feat/custom-json-marshaling
This commit is contained in:
commit
25d5fee05f
4 changed files with 17 additions and 21 deletions
|
@ -81,14 +81,6 @@ func (cfg *AgentConfig) Parse(addr string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func withoutBuildTime(version string) string {
|
||||
return strings.Split(version, "-")[0]
|
||||
}
|
||||
|
||||
func checkVersion(a, b string) bool {
|
||||
return withoutBuildTime(a) == withoutBuildTime(b)
|
||||
}
|
||||
|
||||
func (cfg *AgentConfig) InitWithCerts(ctx context.Context, ca, crt, key []byte) error {
|
||||
clientCert, err := tls.X509KeyPair(crt, key)
|
||||
if err != nil {
|
||||
|
@ -120,10 +112,10 @@ func (cfg *AgentConfig) InitWithCerts(ctx context.Context, ca, crt, key []byte)
|
|||
return err
|
||||
}
|
||||
|
||||
versionStr := string(version)
|
||||
// skip version check for dev versions
|
||||
if strings.HasPrefix(versionStr, "v") && !checkVersion(versionStr, pkg.GetVersion().String()) {
|
||||
return gperr.Errorf("agent version mismatch: server: %s, agent: %s", pkg.GetVersion(), versionStr)
|
||||
agentVer := pkg.ParseVersion(string(version))
|
||||
serverVer := pkg.GetVersion()
|
||||
if !agentVer.IsEqual(serverVer) {
|
||||
return gperr.Errorf("agent version mismatch: server: %s, agent: %s", serverVer, agentVer)
|
||||
}
|
||||
|
||||
// get agent name
|
||||
|
|
|
@ -27,6 +27,7 @@ type (
|
|||
refCount uint32
|
||||
closedOn int64
|
||||
|
||||
key string
|
||||
addr string
|
||||
dial func(ctx context.Context) (net.Conn, error)
|
||||
}
|
||||
|
@ -179,6 +180,7 @@ func NewClient(host string) (*SharedClient, error) {
|
|||
Client: client,
|
||||
refCount: 1,
|
||||
addr: addr,
|
||||
key: host,
|
||||
dial: dial,
|
||||
}
|
||||
|
||||
|
@ -197,7 +199,7 @@ func NewClient(host string) (*SharedClient, error) {
|
|||
}
|
||||
|
||||
func (c *SharedClient) Key() string {
|
||||
return c.DaemonHost()
|
||||
return c.key
|
||||
}
|
||||
|
||||
func (c *SharedClient) Address() string {
|
||||
|
|
|
@ -79,14 +79,16 @@ func flattenFields(t reflect.Type) []*field {
|
|||
f.marshal = appendMarshal
|
||||
}
|
||||
if structField.Anonymous {
|
||||
if structField.Type.Kind() == reflect.Pointer {
|
||||
f.inner = flattenFields(structField.Type.Elem())
|
||||
t := structField.Type
|
||||
if t.Kind() == reflect.Pointer {
|
||||
t = t.Elem()
|
||||
f.omitEmpty = true
|
||||
} else {
|
||||
f.inner = flattenFields(structField.Type)
|
||||
}
|
||||
if t.Kind() == reflect.Struct {
|
||||
f.inner = flattenFields(t)
|
||||
f.hasInner = len(f.inner) > 0
|
||||
}
|
||||
}
|
||||
fields = append(fields, f)
|
||||
if f.omitEmpty {
|
||||
f.checkEmpty = checkEmptyFuncs[kind]
|
||||
|
|
|
@ -20,7 +20,7 @@ func GetLastVersion() Version {
|
|||
}
|
||||
|
||||
func init() {
|
||||
currentVersion = parseVersion(version)
|
||||
currentVersion = ParseVersion(version)
|
||||
|
||||
// ignore errors
|
||||
versionFile := filepath.Join(common.DataDir, "version")
|
||||
|
@ -28,7 +28,7 @@ func init() {
|
|||
f, err := os.OpenFile(versionFile, os.O_RDWR|os.O_CREATE, 0o644)
|
||||
if err == nil {
|
||||
_, err = fmt.Fscanf(f, "%s", &lastVersionStr)
|
||||
lastVersion = parseVersion(lastVersionStr)
|
||||
lastVersion = ParseVersion(lastVersionStr)
|
||||
}
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
logging.Warn().Err(err).Msg("failed to read version file")
|
||||
|
@ -89,7 +89,7 @@ var (
|
|||
lastVersion Version
|
||||
)
|
||||
|
||||
func parseVersion(v string) (ver Version) {
|
||||
func ParseVersion(v string) (ver Version) {
|
||||
if v == "" {
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue