generated from wisdom-oss/microservice-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from wisdom-oss/dev
Stable Release
- Loading branch information
Showing
29 changed files
with
1,019 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,34 @@ | ||
<div align="center"> | ||
<img height="150px" src="https://raw.githubusercontent.com/wisdom-oss/brand/main/svg/standalone_color.svg"> | ||
<h1>Microservice Template/Example</h1> | ||
<h3>service-example</h3> | ||
<p>📐 A minimal working example for microservices in the WISdoM Architecture</p> | ||
<img src="https://img.shields.io/github/go-mod/go-version/wisdom-oss/microservice-template?style=for-the-badge" alt="Go Lang Version"/> | ||
<h1>Water Levels</h1> | ||
<h3>service-water-levels</h3> | ||
<p>🌊 read collected water levels</p> | ||
<img src="https://img.shields.io/github/go-mod/go-version/wisdom-oss/crawler-nlwkn-water-levels?style=for-the-badge" alt="Go Lang Version"/> | ||
<a href="openapi.yaml"> | ||
<img src="https://img.shields.io/badge/Schema%20Version-3.0.0-6BA539?style=for-the-badge&logo=OpenAPI%20Initiative" alt="Open | ||
API Schema Version"/></a> | ||
<img src="https://img.shields.io/badge/Schema%20Version-3.0.0-6BA539?style=for-the-badge&logo=OpenAPI%20Initiative" alt="Open API Schema Version"/> | ||
</a> | ||
</div> | ||
|
||
## Using the template | ||
1. Download this archive as `.zip` or `.tar.gz` (whatever you prefer) | ||
|
||
2. Extract the downloaded archive to a directory of your choice and remove the | ||
parent folders which may have been created during the download | ||
|
||
3. Make sure that your folder now contains at least the following file structure: | ||
``` | ||
├── globals | ||
│ ├── connections.go (contains globally available connections) | ||
│ ├── variables.go (contains globally available variables) | ||
├── resources | ||
│ ├── authConfig.json (contains auth config) | ||
│ ├── environment.json (contains the environment setup) | ||
│ ├── errors.json (contains http errors) | ||
│ ├── queries.sql (contains sql queries for the service) | ||
├── routes | ||
│ ├── templates.go (contains three template routes) | ||
├── .gitignore | ||
├── init.go (contains code used during startup) | ||
├── template-service.go (contains the bootstrapping code for the service) | ||
├── go.mod (contains the dependencies of the service) | ||
├── go.sum (is the lockfile for the dependencies) | ||
``` | ||
|
||
4. **Important** Change the service name | ||
|
||
To change the service name, you need to edit the file `globals/variables.go` | ||
which should contain the following line | ||
|
||
```go | ||
const ServiceName = "template-service" | ||
``` | ||
|
||
This line needs to be changed to your service name. This constant is | ||
used in logs and error handling to identify the service. | ||
|
||
5. Initialize a Git Repository with `main` as default branch | ||
|
||
```shell | ||
git init -b main | ||
``` | ||
6. Add all files to the repository | ||
|
||
```shell | ||
git add -A | ||
``` | ||
|
||
7. Commit the template to the repository | ||
|
||
```shell | ||
git commit -m "loading wisdom-oss/microservice-template" | ||
``` | ||
|
||
8. Set up a remote origin for the repository | ||
|
||
```shell | ||
git remote add origin <your-remote-url> | ||
``` | ||
|
||
9. Push the repository to the remote origin | ||
|
||
```shell | ||
git push origin main | ||
``` | ||
|
||
10. :tada: You are now able to develop your new microservice | ||
|
||
11. Change the README to the contents you desire in here | ||
> [!NOTE] | ||
> The data made available through this service needs to be crawled regularly. | ||
> A working crawler is available here: [wisdom-oss/crawler-nlwkn-water-levels]. | ||
> Otherwise, there will be no data available for the service to display. | ||
> | ||
> [wisdom-oss/crawler-nlwkn-water-levels]: https://github.com/wisdom-oss/crawler-nlwkn-water-levels | ||
> [!IMPORTANT] | ||
> The data provided by this application has been licensed under the | ||
> [Datenlizenz Deutschland — Namensnennung — Version 2.0]. | ||
> | ||
> ``` | ||
> 2024- NLWKN | ||
> www.nlwkn.niedersachsen.de/opendata | ||
> ``` | ||
> | ||
> [Datenlizenz Deutschland — Namensnennung — Version 2.0]: https://www.govdata.de/dl-de/by-2-0 | ||
|
||
This service enables the access to the water levels collected and stored in your | ||
WISdoM platform. | ||
The recommended crawler is listed in the note above which will ensure a | ||
constant collection of the water levels and management of the available stations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//go:build docker | ||
|
||
package config | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
chiMiddleware "github.com/go-chi/chi/v5/middleware" | ||
"github.com/go-chi/httplog" | ||
errorMiddleware "github.com/wisdom-oss/microservice-middlewares/v5/error" | ||
securityMiddleware "github.com/wisdom-oss/microservice-middlewares/v5/security" | ||
|
||
"microservice/globals" | ||
) | ||
|
||
// This file contains default paths that are used inside the service to load | ||
// resource files. | ||
// The go toolchain automatically uses this file if no build tags have been | ||
// set. | ||
// This should be the case in local development and testing. | ||
// To achieve the behavior in docker containers, supply the build tag "docker" | ||
// and the Docker defaults are used | ||
|
||
// Middlewares contains the middlewares used per default in this service. | ||
// To disable single middlewares, please remove the line in which this array | ||
// is used and add the middlewares that shall be used manually to the router | ||
var Middlewares = []func(next http.Handler) http.Handler{ | ||
httpLogger(), | ||
chiMiddleware.RequestID, | ||
chiMiddleware.RealIP, | ||
errorMiddleware.Handler, | ||
securityMiddleware.ValidateServiceJWT, | ||
} | ||
|
||
// EnvironmentFilePath contains the default file path under which the | ||
// environment configuration file is stored | ||
const EnvironmentFilePath = "./environment.json" | ||
|
||
// QueryFilePath contains the default file path under which the | ||
// sql queries are stored | ||
const QueryFilePath = "./queries.sql" | ||
|
||
// ListenAddress sets the host on which the microservice listens to incoming | ||
// requests | ||
const ListenAddress = "0.0.0.0" | ||
|
||
func httpLogger() func(next http.Handler) http.Handler { | ||
l := httplog.NewLogger(globals.ServiceName) | ||
httplog.Configure(httplog.Options{ | ||
JSON: true, | ||
Concise: true, | ||
TimeFieldFormat: time.RFC3339, | ||
}) | ||
return httplog.Handler(l) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
//go:build !docker | ||
|
||
package config | ||
|
||
import ( | ||
"net/http" | ||
"time" | ||
|
||
chiMiddleware "github.com/go-chi/chi/v5/middleware" | ||
"github.com/go-chi/httplog" | ||
errorMiddleware "github.com/wisdom-oss/microservice-middlewares/v5/error" | ||
|
||
"microservice/globals" | ||
) | ||
|
||
// This file contains default paths that are used inside the service to load | ||
// resource files. | ||
// The go toolchain automatically uses this file if no build tags have been | ||
// set. | ||
// This should be the case in local development and testing. | ||
// To achieve the behavior in docker containers, supply the build tag "docker" | ||
// and the Docker defaults are used | ||
|
||
// Middlewares contains the middlewares used per default in this service. | ||
// To disable single middlewares, please remove the line in which this array | ||
// is used and add the middlewares that shall be used manually to the router | ||
var Middlewares = []func(next http.Handler) http.Handler{ | ||
httpLogger(), | ||
chiMiddleware.RequestID, | ||
chiMiddleware.RealIP, | ||
errorMiddleware.Handler, | ||
} | ||
|
||
// EnvironmentFilePath contains the default file path under which the | ||
// environment configuration file is stored | ||
const EnvironmentFilePath = "./resources/environment.json" | ||
|
||
// QueryFilePath contains the default file path under which the | ||
// sql queries are stored | ||
const QueryFilePath = "./resources/queries.sql" | ||
|
||
// ListenAddress sets the host on which the microservice listens to incoming | ||
// requests | ||
const ListenAddress = "127.0.0.1" | ||
|
||
func httpLogger() func(next http.Handler) http.Handler { | ||
l := httplog.NewLogger(globals.ServiceName) | ||
httplog.Configure(httplog.Options{ | ||
JSON: false, | ||
Concise: true, | ||
TimeFieldFormat: time.RFC3339, | ||
}) | ||
return httplog.Handler(l) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package main | ||
|
||
import _ "embed" | ||
|
||
//go:embed schema.graphql | ||
var graphQlSchema string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.