github.com/PDOK/gokoala@v0.50.6/internal/ogc/README.md (about) 1 # OGC API 2 3 OGC APIs are constructed by different building blocks. These building blocks 4 are composed of the different [OGC API standards](https://ogcapi.ogc.org/) as 5 defined by the OGC. Each OGC building block resides in its own Go package. 6 7 ## Coding 8 9 ### Naming convention 10 11 When coding we will try to use the naming convention as that is used by the OGC. 12 So it is clean which specification or part is referred to in the code. 13 14 ### Templates 15 16 We use templates to generate static/pre-defined API responses based on 17 the given GoKoala configuration file. Lots of OGC API responses can be 18 statically generated. Generation happens at startup and results are served 19 from memory when an API request is received. Benefits of this approach are: 20 21 - Lightning fast responses to API calls since everything is served from memory 22 - Fail fast since validation is performed during startup 23 24 #### Duplication 25 26 We will have duplication between JSON and HTML templates: that's ok. They're 27 different representations of the same data. Don't try to be clever and 28 "optimize" it. The duplication is pretty obvious/visible since the files only 29 differ by extension, so it's clear any changes need to be done in both 30 representations. Having independent files keeps the templates simple and 31 flexible. 32 33 #### IDE support 34 35 See [README](../README.md) in the root. 36 37 #### Tip: handling JSON 38 39 When generating JSON arrays using templates you need to be aware of trailing 40 commas. The last element in an array must not contain a comma. To prevent this, 41 either: 42 43 - Add the comma in front of array items 44 - Use the index of a `range` to check array position and place the comma based 45 on the index 46 - The most comprehensive solution is to use: 47 48 ```jinja 49 {{ $first := true }} 50 {{ range $_, $element := .}} 51 {{if not $first}}, {{else}} {{$first = false}} {{end}} 52 {{$element.Name}} 53 {{end}} 54 ```