github.com/PDOK/gokoala@v0.50.6/README.md (about) 1 <p align="center"> 2 <img src="docs/gopher-koala.png" alt="GoKoala" title="GoKoala" width="300" /> 3 </p> 4 5 # GoKoala 6 7 _Cloud Native OGC APIs server, written in Go._ 8 9 [![Build](https://github.com/PDOK/gokoala/actions/workflows/build-and-publish-image.yml/badge.svg)](https://github.com/PDOK/gokoala/actions/workflows/build-and-publish-image.yml) 10 [![Lint (go)](https://github.com/PDOK/gokoala/actions/workflows/lint-go.yml/badge.svg)](https://github.com/PDOK/gokoala/actions/workflows/lint-go.yml) 11 [![Lint (ts)](https://github.com/PDOK/gokoala/actions/workflows/lint-ts.yml/badge.svg)](https://github.com/PDOK/gokoala/actions/workflows/lint-ts.yml) 12 [![Go Report Card](https://goreportcard.com/badge/github.com/PDOK/gokoala)](https://goreportcard.com/report/github.com/PDOK/gokoala) 13 [![Coverage (go)](https://github.com/PDOK/gokoala/wiki/coverage.svg)](https://raw.githack.com/wiki/PDOK/gokoala/coverage.html) 14 [![GitHub license](https://img.shields.io/github/license/PDOK/gokoala)](https://github.com/PDOK/gokoala/blob/master/LICENSE) 15 [![Docker Pulls](https://img.shields.io/docker/pulls/pdok/gokoala.svg)](https://hub.docker.com/r/pdok/gokoala) 16 17 ## Description 18 19 This server implements modern OGC APIs such as Common, Tiles, Styles, Features and GeoVolumes in a cloud-native way. 20 It contains a complete implementation of OGC API Features (part 1 and 2). With respect to OGC API Tiles, Styles, 21 GeoVolumes the goal is to keep a narrow focus and not implement every aspect of these APIs. Meaning complex logic is 22 delegated to other implementations. For example vector tile hosting may be delegated to a vector tile engine, 23 3D tile hosting to object storage, raster map hosting to a WMS server, etc. 24 25 This application is deliberately not multi-tenant, it exposes an OGC API for _one_ dataset. Want to host multiple 26 datasets? Spin up a separate instance/container. 27 28 ## Features 29 30 - [OGC API Common](https://ogcapi.ogc.org/common/) serves landing page and conformance declaration. Also serves 31 OpenAPI specification and interactive Swagger UI. Multilingual support available. 32 - [OGC API Features](https://ogcapi.ogc.org/features/) supports part 1 and part 2 of the spec. Serves features as HTML, GeoJSON or JSON-FG 33 from GeoPackages in multiple projections. No on-the-fly re-projections are applied, separate GeoPackages should 34 be configured ahead-of-time in each projection. Features can be served from local and/or 35 [Cloud-Backed](https://sqlite.org/cloudsqlite/doc/trunk/www/index.wiki) GeoPackages. Support for 36 property and temporal filter(s) is available. 37 - [OGC API Tiles](https://ogcapi.ogc.org/tiles/) serves HTML, JSON and TileJSON metadata. Act as a proxy in front 38 of a vector tiles engine (like Trex, Tegola, Martin) of your choosing. Currently, 3 39 projections (RD, ETRS89 and WebMercator) are supported. 40 - [OGC API Styles](https://ogcapi.ogc.org/styles/) serves HTML - including legends - 41 and JSON representation of supported (Mapbox) styles. 42 - [OGC API 3D GeoVolumes](https://ogcapi.ogc.org/geovolumes/) serves HTML and JSON metadata and functions as a proxy 43 in front of a [3D Tiles](https://www.ogc.org/standard/3dtiles/) server/storage of your choosing. 44 - [OGC API Processes](https://ogcapi.ogc.org/processes/) act as a passthrough proxy to an OGC API Processes 45 implementation of your choosing, but enables the use of GoKoala's OGC API Common functionality. 46 47 ## Build 48 49 ```bash 50 docker build -t pdok/gokoala . 51 ``` 52 53 ## Run 54 55 ```bash 56 NAME: 57 GoKoala - Cloud Native OGC APIs server, written in Go 58 59 USAGE: 60 GoKoala [global options] command [command options] [arguments...] 61 62 COMMANDS: 63 help, h Shows a list of commands or help for one command 64 65 GLOBAL OPTIONS: 66 --host value bind host for OGC server (default: "0.0.0.0") [$HOST] 67 --port value bind port for OGC server (default: 8080) [$PORT] 68 --debug-port value bind port for debug server (disabled by default), do not expose this port publicly (default: -1) [$DEBUG_PORT] 69 --shutdown-delay value delay (in seconds) before initiating graceful shutdown (e.g. useful in k8s to allow ingress controller to update their endpoints list) (default: 0) [$SHUTDOWN_DELAY] 70 --config-file value reference to YAML configuration file [$CONFIG_FILE] 71 --openapi-file value reference to a (customized) OGC OpenAPI spec for the dynamic parts of your OGC API [$OPENAPI_FILE] 72 --enable-trailing-slash allow API calls to URLs with a trailing slash. (default: false) [$ALLOW_TRAILING_SLASH] 73 --enable-cors enable Cross-Origin Resource Sharing (CORS) as required by OGC API specs. Disable if you handle CORS elsewhere. (default: false) [$ENABLE_CORS] 74 --help, -h show help 75 ``` 76 77 Example (config-file is mandatory): 78 79 ```docker 80 docker run -v `pwd`/examples:/examples -p 8080:8080 -it pdok/gokoala --config-file /examples/config_vectortiles.yaml 81 ``` 82 83 Now open <http://localhost:8080>. See [examples](examples) for more details. 84 85 ### Configuration file 86 87 The configuration file consists of a general section and a section 88 per OGC API building block (tiles, styles, etc). See [example configuration 89 files](examples/) for details. You can reference environment variables in the 90 configuration file. For example to use the `MY_SERVER` env var: 91 92 ```yaml 93 ogcApi: 94 tiles: 95 title: My Dataset 96 tileServer: https://${MY_SERVER}/foo/bar 97 ``` 98 99 ### OpenAPI spec 100 101 GoKoala ships with OGC OpenAPI support out of the box, see [OpenAPI 102 specs](engine/templates/openapi) for details. You can overwrite or extend 103 the defaults by providing your own spec using the `openapi-file` CLI flag. 104 105 ### Observability 106 107 #### Health checks 108 109 Health endpoint is available on `/health`. 110 111 #### Profiling 112 113 Besides the main OGC server GoKoala can also start a debug server. This server 114 binds to localhost and a different port which you must specify using the 115 `--debug-port` flag. You shouldn't expose this port publicly but only access it 116 through a tunnel/port-forward. The debug server exposes `/debug` for use by 117 [pprof](https://go.dev/blog/pprof). For example with `--debug-port 9001`: 118 119 - Create a tunnel to the debug server e.g. in k8s: `kubectl port-forward 120 gokoala-75f59d57f4-4nd6q 9001:9001` 121 - Create CPU profile: `go tool pprof 122 http://localhost:9001/debug/pprof/profile?seconds=20` 123 - Start pprof visualization `go tool pprof -http=":8000" pprofbin <path to pb.gz 124 file>` 125 - Open <http://localhost:8000> to explore CPU flamegraphs and such. 126 127 A similar flow can be used to profile memory issues. 128 129 #### SQL query logging 130 131 Set `LOG_SQL=true` environment variable to enable logging of all SQL queries to stdout for debug purposes. 132 Only applies to OGC API Features. Set e.g. `SLOW_QUERY_TIME=10s` to change the definition of a 133 slow query. Slow queries are always logged. 134 135 ## Develop 136 137 Design principles: 138 139 - Performance and scalability are key! 140 - Be opinionated when you can, only make stuff configurable when you must. 141 - The `ogc` [package](internal/ogc/README.md) contains logic per specific OGC API 142 building block. 143 - The `engine` package should contain general logic. `ogc` may reference 144 `engine`. 145 > :warning: The other way around is not allowed! 146 - Geospatial related configuration is done through the config file, technical 147 configuration (host/port/etc) is done through CLI flags/env variables. 148 - Fail fast, fail hard: do as much pre-processing/validation on startup instead 149 of during request handling. 150 - Assets/templates/etc should be explicitly included in the Docker image, see COPY 151 commands in [Dockerfile](Dockerfile). 152 - Document your changes to [OGC OpenAPI example specs](engine/templates/openapi/README.md). 153 154 ### Linting 155 156 Install [golangci-lint](https://golangci-lint.run/usage/install/) and run `golangci-lint run` 157 from the root. 158 159 ### Viewer 160 161 GoKoala includes a [viewer](viewer) which is available 162 as a [Web Component](https://developer.mozilla.org/en-US/docs/Web/API/Web_components) for embedding in HTML pages. 163 To use the viewer locally when running GoKoala outside Docker execute: `hack/build-local-viewer.sh`. This will 164 build the viewer and add it to the GoKoala assets. 165 166 Note this is only required for local development. When running GoKoala as a container this is 167 already being taken care of when building the Docker container image. 168 169 ### IntelliJ / GoLand 170 171 - Install the [Go Template](https://plugins.jetbrains.com/plugin/10581-go-template) plugin 172 - Open `Preferences` > `Editor` > `File Types` select `Go Template files` and 173 add the following file patterns: 174 - `"*.go.html"` 175 - `"*.go.json"` 176 - `"*.go.tilejson"` 177 - Now add template language support by running the 178 [setup-jetbrains-gotemplates.sh](hack/setup-jetbrains-gotemplates.sh) script. 179 - Reopen the project (or restart IDE). Now you'll have full IDE support in the GoKoala templates. 180 181 Also: 182 183 - Set import order in `Preferences` > `Editor` > `Code Style` > `Go` > `Imports` 184 to `goimports` to align with VSCode and goimports usage in golangci-lint. 185 186 ### VSCode 187 188 - Install the [Go Template](https://marketplace.visualstudio.com/items?itemName=jinliming2.vscode-go-template) 189 extension 190 - Open Extension Settings and add the following file patterns: 191 - `"*.go.html"` 192 - `"*.go.json"` 193 - `"*.go.tilejson"` 194 - Also add `html` and `json` to the list of Go template languages. 195 - Now you'll have IDE support in the GoKoala templates. 196 197 ### OGC compliance validation 198 199 See our [end-to-end tests](tests/README.md). 200 201 ## Misc 202 203 ### How to Contribute 204 205 Make a pull request... 206 207 ### Contact 208 209 Contacting the maintainers can be done through the issue tracker.