diff options
| author | Fuwn <[email protected]> | 2026-02-26 20:20:17 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-02-26 20:20:17 -0800 |
| commit | e264ed8f36b26c5684ea653ad7299603ccffe02b (patch) | |
| tree | 95bbb4ad51740d7bcc0d834bd1aaa587df22f233 /internal/api/server.go | |
| parent | fix: align PLC compatibility read endpoints with plc.directory schema (diff) | |
| download | plutia-test-e264ed8f36b26c5684ea653ad7299603ccffe02b.tar.xz plutia-test-e264ed8f36b26c5684ea653ad7299603ccffe02b.zip | |
feat: Apply Iku formatting
Diffstat (limited to 'internal/api/server.go')
| -rw-r--r-- | internal/api/server.go | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/internal/api/server.go b/internal/api/server.go index e9e1e15..822d865 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -469,6 +469,7 @@ func (s *Server) handleGetDIDCompatibility(w http.ResponseWriter, r *http.Reques } data, err := s.ingestor.LoadCurrentPLCData(r.Context(), did) + if err != nil { if errors.Is(err, ingest.ErrDIDNotFound) { writeCompatibilityErr(w, http.StatusNotFound, "DID not registered: "+did) @@ -488,8 +489,8 @@ func (s *Server) handleGetDIDCompatibility(w http.ResponseWriter, r *http.Reques } status := http.StatusOK - deactivated := isTombstonedDIDDocument(state.DIDDocument) + if deactivated { status = http.StatusGone } @@ -738,10 +739,11 @@ func buildPLCDIDDocument(did string, plcData map[string]any, deactivated bool) p AlsoKnownAs: extractStringArray(plcData["alsoKnownAs"]), Deactivated: deactivated, } - verificationMethods := extractVerificationMethodMap(plcData["verificationMethods"]) + if len(verificationMethods) > 0 { names := make([]string, 0, len(verificationMethods)) + for name := range verificationMethods { names = append(names, name) } @@ -749,8 +751,10 @@ func buildPLCDIDDocument(did string, plcData map[string]any, deactivated bool) p sort.Strings(names) doc.VerificationMethod = make([]plcVerificationEntry, 0, len(names)) + for _, name := range names { value := verificationMethods[name] + if strings.TrimSpace(value) == "" { continue } @@ -765,8 +769,10 @@ func buildPLCDIDDocument(did string, plcData map[string]any, deactivated bool) p } services := extractServicesMap(plcData["services"]) + if len(services) > 0 { names := make([]string, 0, len(services)) + for name := range services { names = append(names, name) } @@ -774,6 +780,7 @@ func buildPLCDIDDocument(did string, plcData map[string]any, deactivated bool) p sort.Strings(names) doc.Service = make([]plcServiceEntry, 0, len(names)) + for _, name := range names { entry := services[name] typ := entry["type"] @@ -798,8 +805,10 @@ func extractStringArray(v any) []string { switch raw := v.(type) { case []string: out := make([]string, 0, len(raw)) + for _, item := range raw { item = strings.TrimSpace(item) + if item == "" { continue } @@ -810,8 +819,10 @@ func extractStringArray(v any) []string { return out case []any: out := make([]string, 0, len(raw)) + for _, item := range raw { s, _ := item.(string) + if strings.TrimSpace(s) == "" { continue } @@ -840,6 +851,7 @@ func extractVerificationMethodMap(v any) map[string]string { case map[string]any: for name, raw := range vm { key, _ := raw.(string) + if strings.TrimSpace(key) == "" { continue } @@ -858,6 +870,7 @@ func extractServicesMap(v any) map[string]map[string]string { case map[string]map[string]string: for name, entry := range services { endpoint := strings.TrimSpace(entry["endpoint"]) + if endpoint == "" { endpoint = strings.TrimSpace(entry["serviceEndpoint"]) } @@ -874,12 +887,14 @@ func extractServicesMap(v any) map[string]map[string]string { case map[string]any: for name, raw := range services { entry, ok := raw.(map[string]any) + if !ok { continue } typ, _ := entry["type"].(string) endpoint, _ := entry["endpoint"].(string) + if endpoint == "" { endpoint, _ = entry["serviceEndpoint"].(string) } |