package postgresadmin import ( "encoding/json" "math" "net/netip" "strings" "time" "proxy-pool/internal/domain/adminstate" ) func cloneConfigCommand(command adminstate.CommitConfigCommand) adminstate.CommitConfigCommand { cloned := command cloned.Checksum = strings.ToLower(command.Checksum) cloned.Upstreams = append([]adminstate.UpstreamDefinition(nil), command.Upstreams...) cloned.Routings = make([]adminstate.RoutingDefinition, len(command.Routings)) for index, routing := range command.Routings { cloned.Routings[index] = routing cloned.Routings[index].Upstreams = append([]string(nil), routing.Upstreams...) } return cloned } func sourceIPValue(sourceIP string) any { if sourceIP == "" { return nil } address, err := netip.ParseAddr(sourceIP) if err != nil { return nil } return address.Unmap() } func encodePayload(value any) (json.RawMessage, error) { payload, err := json.Marshal(value) if err != nil { return nil, err } return json.RawMessage(payload), nil } func databaseID(value uint64) (int64, bool) { if value > math.MaxInt64 { return 0, false } return int64(value), true } func domainID(value int64) (uint64, bool) { if value < 0 { return 0, false } return uint64(value), true } func eventDatabaseIDs(values []uint64) ([]int64, bool) { result := make([]int64, len(values)) for index, value := range values { converted, ok := databaseID(value) if !ok { return nil, false } result[index] = converted } return result, true } func utc(value time.Time) time.Time { return value.UTC() }