a love letter to tangled (android, iOS, and a search API)
at main 46 lines 1.2 kB view raw
1package view 2 3import ( 4 _ "embed" 5 "encoding/json" 6) 7 8// DocParam describes a single path or query parameter for an endpoint. 9type DocParam struct { 10 Name string `json:"name"` 11 Type string `json:"type"` 12 Required bool `json:"required,omitempty"` 13 Description string `json:"description,omitempty"` 14} 15 16// DocEntry describes a single API endpoint. 17type DocEntry struct { 18 Page string `json:"page"` 19 Route string `json:"route"` 20 Method string `json:"method"` 21 Summary string `json:"summary"` 22 Details string `json:"details,omitempty"` 23 PathParams []DocParam `json:"pathParams,omitempty"` 24 QueryParams []DocParam `json:"queryParams,omitempty"` 25} 26 27//go:embed api-docs.json 28var apiDocFile []byte 29 30var docsByPage map[string][]DocEntry 31 32func init() { 33 var all []DocEntry 34 if err := json.Unmarshal(apiDocFile, &all); err != nil { 35 panic("api-docs.json: " + err.Error()) 36 } 37 docsByPage = make(map[string][]DocEntry) 38 for _, e := range all { 39 docsByPage[e.Page] = append(docsByPage[e.Page], e) 40 } 41} 42 43// PageDocs returns the doc entries for a given page key. 44func PageDocs(page string) []DocEntry { 45 return docsByPage[page] 46}