Skip to content

A simple go backend (encapsulated into an Azure Function) with HTML frontend that generates random Markt-, Mess- and Netzlokation- and SR/TR-IDs for testing purposes

License

Notifications You must be signed in to change notification settings

Hochfrequenz/malo-id-generator

Repository files navigation

malo-id-generator / nelo-id-generator

Unittest status badge Coverage status badge Linter status badge

🇩🇪 Dieses Repository enthält den Source Code hinter den Websites:

🇬🇧 This repository contains an Azure Function with a Go Handler which is deployed to netz.lokations.id and markt.lokations.id.

Its purpose is to

  • generate:
    1. Marktlokations-IDs (MaLo-IDs)
    2. Netzlokations-IDs (NeLo-IDs)
    3. Messlokations-IDs (MeLo-IDs)
    4. Technische Ressourcen-IDs (TR-IDs)
    5. Steuerbare Ressourcen-IDs (SR-IDs)
  • with a valid checksum
  • on the fly

The business logic is written in Go using Gin Gonic and can be found in cmd/api.go.

It's a super basic website with three "pseudo files":

  1. / (root) that returns a basic HTML site which refers to (this is the main entry point for users)
  2. /api/favicon (returns a favicon) and refers to
  3. /api/style (returns a stylesheet)

The files are not really served as plain files as you would expect it from a usual web app setup, but they are all separate Azure Functions and hence have their own respective function.json.

The files are embedded into the go binary using go:embed. This means you need to rebuild in order to change e.g. the stylesheet.

Running it Locally

The setup is generally described quite well in this article by Thorsten Hans.

First install the Azure Function Core Tools.

Then, in the root directory of this repo, execute:

go build -o api ./cmd/

followed by (also in the repo root)

func start

CI/CD

This function app is managed in two separate Azure Function Apps. Both Function apps are assigned to the malo-id-generator resource group on Azure. There is one function app instance per supported ID type. This is because to use the function app directly behind top level domain registered in Azure, its respective entry point must be a top level domain itself without any further, relative path (e.g. foobarsomerandomstring.azurewebsites.net and not foobarsomerandomstring.azurewebsites.net/malo).

Purpose ID_TYPE_TO_GENERATE env var value Deployed to (URL) Settings
Generate MaLo-IDs "MALO" malo-id-generator.azurewebsites.net/ and markt.lokations.id malo-id-generator
Generate NeLo-IDs "NELO" nelo-id-generator.azurewebsites.net/ and netz.lokations.id nelo-id-generator
Generate MeLo-IDs "MELO" melo-id-generator.azurewebsites.net/ and mess.lokations.id melo-id-generator
Generate TR-IDs "TRID" tr-id-generator.azurewebsites.net/ and technische.ressource.id tr-id-generator
Generate SR-IDs "SRID" sr-id-generator.azurewebsites.net/ and steuerbare.ressource.id sr-id-generator

The function apps are all

  • code based (instead of dockerized (todo @kevin))
  • linux based (instead of windows)

There is an environment variable named ID_TYPE_TO_GENERATE which you can modify in the function app settings. Its value can be "MALO" or "NELO" or "MELO" or "TRID" or "SRID"at the moment. If its value is not set or set to an invalid value, the function app will return a HTTP 501 error. For your local tests you can modify the value in the local.settings.json file.

How To Deploy

There is no automatic deployment yet (fixable with docker).

To deploy:

First build locally for linux (note that the build is the same for all ID types, only the env var is different)

set GOOS=linux
go build -o api ./cmd

The GOOS env var can be set in the build configuration in Goland. The build should create an api (no file ending) file on root level.

Then upload

func azure functionapp publish malo-id-generator

or

func azure functionapp publish nelo-id-generator

respectively (and similar for melo-id-generator, sr-id-generator and tr-id-generator).

You have to be logged in (az login) using the Azure CLI Tools.

Deploy them all

func azure functionapp publish malo-id-generator
func azure functionapp publish melo-id-generator
func azure functionapp publish nelo-id-generator
func azure functionapp publish sr-id-generator
func azure functionapp publish tr-id-generator

About

A simple go backend (encapsulated into an Azure Function) with HTML frontend that generates random Markt-, Mess- and Netzlokation- and SR/TR-IDs for testing purposes

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published