malo-id-generator

module
v0.0.0-...-c8bfcf5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2024 License: MIT

README

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 (NeLo-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

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 only be "MALO" or "NELO" or "MELO" 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.

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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL