go-bo4e

module
v0.5.0-alpha0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: MIT

README

go-bo4e

Unittest status badge Coverage status badge Linter status badge Go Report Card Go Reference

Business Objects for Energy (BO4E) Implementation in Go. Highlights are

  • includes json tags for easy (un)marshalling
  • comes with builtin validator logic
  • is linted and has decent test coverage

This package (as of November 2021) implements

  • BO Ansprechpartner
  • BO Bilanzierung (not official BO4E Standard yet)
  • BO Energiemenge
  • BO Geschaeftspartner
  • BO Handelsunstimmigkeit (not official BO4E Standard yet)
  • BO Lastgang
  • BO Marktlokation
  • BO Marktteilnehmer
  • BO Messlokation
  • BO Preisblatt
  • BO Rechnung
  • BO Reklamation (not official BO4E Standard yet)
  • BO Vertrag
  • BO Zaehler

so far.

Installation

go get github.com/hochfrequenz/go-bo4e

Minimal Working Example

package main

import (
	"encoding/json"
	"fmt"
	"github.com/go-playground/validator/v10"
	"github.com/hochfrequenz/go-bo4e/bo"
	"github.com/hochfrequenz/go-bo4e/com"
	"github.com/hochfrequenz/go-bo4e/enum/botyp"
	"github.com/hochfrequenz/go-bo4e/enum/landescode"
	"github.com/hochfrequenz/go-bo4e/enum/sparte"
)

func main() {
	melo := bo.Messlokation{
		Geschaeftsobjekt: bo.Geschaeftsobjekt{
			BoTyp:             botyp.MESSLOKATION,
			VersionStruktur:   "1",
			ExterneReferenzen: nil,
		},
		MesslokationsId: "DE0000011111222223333344444555556",
		Sparte:          sparte.STROM,
		Messadresse: &com.Adresse{
			Postleitzahl: "82031",
			Ort:          "Grünwald",
			Strasse:      "Nördliche Münchner Straße",
			Hausnummer:   "27A",
			Landescode:   landescode.DE,
		},
	}
	vali := validator.New()
	err := vali.Struct(melo)
	if err == nil {
		fmt.Println("The MeLo is valid.")
	}
	meloBytes, err := json.Marshal(melo)
	meloJson := string(meloBytes)
	fmt.Print(meloJson)
}

Use this in the Go Playground.

Caveats

When serializing decimals (e.g. Zaehlwerk.Wandlerfaktor) you'll notice that the decimals are by default serialized as strings

{
  "wandlerfaktor": "0.8"
}

instead of a number like

{
  "wandlerfaktor": 0.8
}

This is the default behaviour defined in the decimal package . You can change the behaviour by setting

decimal.MarshalJSONWithoutQuotes = true

as described f.e. in issue 21 there.

Version Notes

Go 1.19 since v0.3.0

Since version 0.3.0 this library is based on Go 1.19.

Go 1.18 since v0.2.0

Since version 0.2.0 this library is based on Go 1.18, because we want to make use of Generics.

Go 1.17 since v0.1.0

Since version 0.1.0 this library is based on Go 1.17, because Go 1.16 has reached end of life.

Handling Unknown Fields in (Un)Marshaling since v0.0.36

If you're unmarshaling a Business Object that contains fields which are not defined in the BO structs, they'll be deserialized into the Geschaeftsobjekt.ExtensionData map. This behaviour is achieved by implementing a custom UnmarshalJSON func. The ExtensionData, if not empty, will also be marshalled on root level by default.

⚠ This feature is experimental and for now only works for the Marktlokation.

General Default Value Marshalling Behaviour since v0.0.22

Since v0.0.22 default values are no longer marshalled/included in serialized Business Objects or COMponents. Prior to v0.0.22 default values of required fields serialized as f.e. empty string, null or empty slice. For enums this behaviour had already been introduced in v0.0.19 (see below). This is a step towards decoupling of serialization and validation.

Default Enum Marshalling Behaviour since v0.0.19

Since version v0.0.19 default enum values are no longer serialized/marshalled. Prior to v0.0.19 fields with an enum type that are required but were uninitialized had been serialized as NameOfEnum(0). This change is a step towards decoupling of serialization and validation.

Breaking Changes introduced in v0.0.13 and v0.0.14:
  • The struct that is embedded in all BusinessObjects is now called Geschaeftsobjekt (was BusinessObject <=v0.0.12)to be consistent with the official documentation
  • BusinessObject is now the name of the interface that all structs with embedded Geschaeftsobjekt implement
  • Enums are consistently written in upper case (PR 32)

Other Noteworthy BO4E Implementations

Contributing

Contributions are welcome. Feel free to open a Pull Request against the main branch of this repository. Please provide unit tests if you contribute logic beyond bare bare business object definitions. We do track our modification proposals to the official BO4E standard in a separate repository: BO4E-modification-proposals.

Adding Enums

When adding Enums there are two packages (stringer , jsonenums) needed to go-generate additional files, which contain an implementation of the fmt.Stringer and json.Marshaler interface for the respective enum. Since they are just needed for the code generation, but not a real dependency we don't want them in the go.mod file. One way to install them is outside of your directory with:

go install github.com/campoy/jsonenums@latest
go install golang.org/x/tools/cmd/stringer@latest

Hochfrequenz

Hochfrequenz Unternehmensberatung GmbH is a Grünwald (near Munich) based consulting company with offices in Berlin and Bremen. We're not only the main contributor to open source BO4E software but, according to Kununu ratings, also among the most attractive employers within the German energy market. Applications of talented developers are welcome at any time! Please consider visiting our career page ( German only).

Directories

Path Synopsis
enum
abweichungsgrund
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
aggregationsverantwortung
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
anrede
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
arithmetischeoperation
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
avistyp
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
bdewartikelnummer
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
bemessungsgroesse
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
bilanzierungsmethode
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
botyp
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
dienstleistungstyp
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
energierichtung
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
fallgruppenzuordnung
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
fernschaltung
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
gasqualitaet
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
gebiettyp
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
geraetetyp
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
geschaeftspartnerrolle
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
handelsunstimmigkeitsgrund
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
handelsunstimmigkeitstyp
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
kalkulationsmethode
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
kontaktart
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
landescode
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
leistungstyp
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
lokationstyp
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
marktrolle
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
mengeneinheit
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
messwerterfassung
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
messwertstatus
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
messwertstatuszusatz
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
netzebene
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
netznutzungsabrechnungsgrundlage
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
netznutzungsabrechnungsvariante
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
netznutzungsvertragsart
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
netznutzungszahler
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
nnrechnungsart
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
nnrechnungstyp
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
preisstatus
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
profilart
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
profiltyp
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
profilverfahren
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
prognosegrundlage
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
rechnungsstatus
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
rechnungstyp
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
reklamationsgrund
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
rollencodetyp
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
rufnummernart
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
schwachlastfaehigkeit
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
sparte
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
steuerkennzeichen
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
tarifart
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
tarifzeit
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
themengebiet
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
titel
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
verbrauchsart
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
vertragsart
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
vertragsstatus
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
waehrungscode
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
waehrungseinheit
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
wertermittlungsverfahren
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
zaehlerauspraegung
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
zaehlertyp
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
zeiteinheit
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
zeitreihentyp
Code auto-generated; DO NOT EDIT.
Code auto-generated; DO NOT EDIT.
jsonfieldnames
Package jsonfieldnames contains a function to extract JSON field names from a value.
Package jsonfieldnames contains a function to extract JSON field names from a value.

Jump to

Keyboard shortcuts

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