bluesky appview implementation using microcosm and other services server.reddwarf.app
appview bluesky reddwarf microcosm
1package main 2 3import ( 4 "encoding/json" 5 "fmt" 6 "net/http" 7 "strings" 8) 9 10type DIDDocument struct { 11 ID string `json:"id"` 12 Service []struct { 13 ID string `json:"id"` 14 Type string `json:"type"` 15 ServiceEndpoint string `json:"serviceEndpoint"` 16 } `json:"service"` 17} 18 19func ResolveDID(did string) (*DIDDocument, error) { 20 var url string 21 22 if strings.HasPrefix(did, "did:plc:") { 23 // Resolve via PLC Directory 24 url = "https://plc.directory/" + did 25 } else if strings.HasPrefix(did, "did:web:") { 26 // Resolve via Web (simplified) 27 domain := strings.TrimPrefix(did, "did:web:") 28 url = "https://" + domain + "/.well-known/did.json" 29 } else { 30 return nil, fmt.Errorf("unsupported DID format: %s", did) 31 } 32 33 resp, err := http.Get(url) 34 if err != nil { 35 return nil, err 36 } 37 defer resp.Body.Close() 38 39 if resp.StatusCode != http.StatusOK { 40 return nil, fmt.Errorf("resolver returned status: %d", resp.StatusCode) 41 } 42 43 var doc DIDDocument 44 if err := json.NewDecoder(resp.Body).Decode(&doc); err != nil { 45 return nil, err 46 } 47 48 return &doc, nil 49}