wip
at main 89 lines 1.7 kB view raw
1package plc 2 3import ( 4 "net/url" 5 "strings" 6 7 plclib "tangled.org/atscan.net/plcbundle/plc" 8) 9 10// Re-export library types 11type PLCOperation = plclib.PLCOperation 12type DIDDocument = plclib.DIDDocument 13type Client = plclib.Client 14type ExportOptions = plclib.ExportOptions 15 16// Keep your custom types 17const BUNDLE_SIZE = 10000 18 19type DIDHistoryEntry struct { 20 Operation PLCOperation `json:"operation"` 21 PLCBundle string `json:"plc_bundle,omitempty"` 22} 23 24type DIDHistory struct { 25 DID string `json:"did"` 26 Current *PLCOperation `json:"current"` 27 Operations []DIDHistoryEntry `json:"operations"` 28} 29 30type EndpointInfo struct { 31 Type string 32 Endpoint string 33} 34 35// PLCOpLabel holds metadata from the label CSV file 36type PLCOpLabel struct { 37 Bundle int `json:"bundle"` 38 Position int `json:"position"` 39 CID string `json:"cid"` 40 Size int `json:"size"` 41 Confidence float64 `json:"confidence"` 42 Detectors []string `json:"detectors"` 43} 44 45// validateEndpoint checks if endpoint is in correct format: https://<domain> 46func validateEndpoint(endpoint string) bool { 47 // Must not be empty 48 if endpoint == "" { 49 return false 50 } 51 52 // Must not have trailing slash 53 if strings.HasSuffix(endpoint, "/") { 54 return false 55 } 56 57 // Parse URL 58 u, err := url.Parse(endpoint) 59 if err != nil { 60 return false 61 } 62 63 // Must use https scheme 64 if u.Scheme != "https" { 65 return false 66 } 67 68 // Must have a host 69 if u.Host == "" { 70 return false 71 } 72 73 // Must not have path (except empty) 74 if u.Path != "" && u.Path != "/" { 75 return false 76 } 77 78 // Must not have query parameters 79 if u.RawQuery != "" { 80 return false 81 } 82 83 // Must not have fragment 84 if u.Fragment != "" { 85 return false 86 } 87 88 return true 89}