common

package
v0.0.0-...-2971174 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2023 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const USER_ID_ADMIN = "_admin_"

magic user id used for admin access

View Source
const USER_ID_INTERNAL = "_internal_"

magic user id used for internal access, i.e. one type/service accessing another service

Variables

This section is empty.

Functions

func DeregisterOneAndOnlyType

func DeregisterOneAndOnlyType(typeIdentifier TypeIdentifier)

func FindTypeServiceUrl

func FindTypeServiceUrl(typeIdentifier TypeIdentifier) (string, error)

func GetUserIdFromGinContext

func GetUserIdFromGinContext(c *gin.Context) string

function to get the HTTP header "X-User-Id" from the gin context

func RegisterOneAndOnlyType

func RegisterOneAndOnlyType(typeIdentifier TypeIdentifier, port int)

Types

type ConsulClient

type ConsulClient struct {
	*api.Client
}

heavily inspired by https://blog.devgenius.io/tooling-go-microservices-with-consul-service-discovery-and-kv-store-2c52bcdf4fd4

func NewClient

func NewClient(addr string) (*ConsulClient, error)

func (*ConsulClient) DeregisterType

func (c *ConsulClient) DeregisterType(typeIdentifier TypeIdentifier) error

the following function deregisters the type/service from consul

func (*ConsulClient) FindTypeServiceUrl

func (c *ConsulClient) FindTypeServiceUrl(typeIdentifier TypeIdentifier) (string, error)

find a service based on the type identifier in ConsulClient

func (*ConsulClient) RegisterType

func (c *ConsulClient) RegisterType(typeIdentifier TypeIdentifier, port int) error

type ThingIdentifier

type ThingIdentifier struct {
	Group string `json:"group,omitempty"`
	Type  string `json:"type,omitempty"`
	UID   UID    `json:"uid,omitempty"`
}

identifier for a specific single thing, e.g. group=sammeles.herzog.fyi, type=postcard, uid=abc123

type ThingMetadata

type ThingMetadata struct {
	UID UID `json:"uid,omitempty"`
	// human-readable name of the thing (can contain spaces etc. as it is not used for identification)
	Name       string `json:"name,omitempty"`
	Generation int64  `json:"generation,omitempty"`
	// reference to the direct parent (sub-) thing.
	// this is empty for root things.
	ParentRef         string    `json:"parentRef,omitempty"`
	CreationTimestamp time.Time `json:"creationTimestamp,omitempty"`
	UpdateTimestamp   time.Time `json:"updateTimestamp,omitempty"`
	// collections that this (sub) thing belongs to.
	// for sub-things this will be synced eventually with the collections of the root thing (eventual consistency)
	Collections []UID             `json:"collections,omitempty"`
	Annotations map[string]string `json:"annotations,omitempty"`
}

metadata for every (sub) thing, heavily inspired by https://pkg.go.dev/golang.org/x/build/kubernetes/api#ObjectMeta

type TypeIdentifier

type TypeIdentifier struct {
	// a group is a domain name, e.g. herzog.fyi
	Group string `json:"id"`
	// the type of the thing, e.g. postcard.
	// should be short (often only one word) and not contain spaces or special characters besides _ and -
	Type string `json:"type"`
	// the schema version of the thing, e.g. 1.
	// the version is monotonically increasing and signals major changes to the type, possibly breaking backwards compatibility
	SchemaVersion int64 `json:"schemaVersion"`
}

identifier for types of things. e.g. group=herzog.fyi, type=postcard, schemaVersion=1

type UID

type UID string

every (sub) thing has to have a UID but the UID format is up to the type (i.e. every microservice can choose its own UID implementation)

Jump to

Keyboard shortcuts

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