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
|
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 {
|
func (cfg *AgentConfig) InitWithCerts(ctx context.Context, ca, crt, key []byte) error {
|
||||||
clientCert, err := tls.X509KeyPair(crt, key)
|
clientCert, err := tls.X509KeyPair(crt, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -120,10 +112,10 @@ func (cfg *AgentConfig) InitWithCerts(ctx context.Context, ca, crt, key []byte)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
versionStr := string(version)
|
agentVer := pkg.ParseVersion(string(version))
|
||||||
// skip version check for dev versions
|
serverVer := pkg.GetVersion()
|
||||||
if strings.HasPrefix(versionStr, "v") && !checkVersion(versionStr, pkg.GetVersion().String()) {
|
if !agentVer.IsEqual(serverVer) {
|
||||||
return gperr.Errorf("agent version mismatch: server: %s, agent: %s", pkg.GetVersion(), versionStr)
|
return gperr.Errorf("agent version mismatch: server: %s, agent: %s", serverVer, agentVer)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get agent name
|
// get agent name
|
||||||
|
|
|
@ -27,6 +27,7 @@ type (
|
||||||
refCount uint32
|
refCount uint32
|
||||||
closedOn int64
|
closedOn int64
|
||||||
|
|
||||||
|
key string
|
||||||
addr string
|
addr string
|
||||||
dial func(ctx context.Context) (net.Conn, error)
|
dial func(ctx context.Context) (net.Conn, error)
|
||||||
}
|
}
|
||||||
|
@ -179,6 +180,7 @@ func NewClient(host string) (*SharedClient, error) {
|
||||||
Client: client,
|
Client: client,
|
||||||
refCount: 1,
|
refCount: 1,
|
||||||
addr: addr,
|
addr: addr,
|
||||||
|
key: host,
|
||||||
dial: dial,
|
dial: dial,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,7 +199,7 @@ func NewClient(host string) (*SharedClient, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *SharedClient) Key() string {
|
func (c *SharedClient) Key() string {
|
||||||
return c.DaemonHost()
|
return c.key
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *SharedClient) Address() string {
|
func (c *SharedClient) Address() string {
|
||||||
|
|
|
@ -79,14 +79,16 @@ func flattenFields(t reflect.Type) []*field {
|
||||||
f.marshal = appendMarshal
|
f.marshal = appendMarshal
|
||||||
}
|
}
|
||||||
if structField.Anonymous {
|
if structField.Anonymous {
|
||||||
if structField.Type.Kind() == reflect.Pointer {
|
t := structField.Type
|
||||||
f.inner = flattenFields(structField.Type.Elem())
|
if t.Kind() == reflect.Pointer {
|
||||||
|
t = t.Elem()
|
||||||
f.omitEmpty = true
|
f.omitEmpty = true
|
||||||
} else {
|
|
||||||
f.inner = flattenFields(structField.Type)
|
|
||||||
}
|
}
|
||||||
|
if t.Kind() == reflect.Struct {
|
||||||
|
f.inner = flattenFields(t)
|
||||||
f.hasInner = len(f.inner) > 0
|
f.hasInner = len(f.inner) > 0
|
||||||
}
|
}
|
||||||
|
}
|
||||||
fields = append(fields, f)
|
fields = append(fields, f)
|
||||||
if f.omitEmpty {
|
if f.omitEmpty {
|
||||||
f.checkEmpty = checkEmptyFuncs[kind]
|
f.checkEmpty = checkEmptyFuncs[kind]
|
||||||
|
|
|
@ -20,7 +20,7 @@ func GetLastVersion() Version {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
currentVersion = parseVersion(version)
|
currentVersion = ParseVersion(version)
|
||||||
|
|
||||||
// ignore errors
|
// ignore errors
|
||||||
versionFile := filepath.Join(common.DataDir, "version")
|
versionFile := filepath.Join(common.DataDir, "version")
|
||||||
|
@ -28,7 +28,7 @@ func init() {
|
||||||
f, err := os.OpenFile(versionFile, os.O_RDWR|os.O_CREATE, 0o644)
|
f, err := os.OpenFile(versionFile, os.O_RDWR|os.O_CREATE, 0o644)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
_, err = fmt.Fscanf(f, "%s", &lastVersionStr)
|
_, err = fmt.Fscanf(f, "%s", &lastVersionStr)
|
||||||
lastVersion = parseVersion(lastVersionStr)
|
lastVersion = ParseVersion(lastVersionStr)
|
||||||
}
|
}
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil && !os.IsNotExist(err) {
|
||||||
logging.Warn().Err(err).Msg("failed to read version file")
|
logging.Warn().Err(err).Msg("failed to read version file")
|
||||||
|
@ -89,7 +89,7 @@ var (
|
||||||
lastVersion Version
|
lastVersion Version
|
||||||
)
|
)
|
||||||
|
|
||||||
func parseVersion(v string) (ver Version) {
|
func ParseVersion(v string) (ver Version) {
|
||||||
if v == "" {
|
if v == "" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue