infrastructure

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2025 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAreaMaxDepth       = errors.New("area max depth reached")
	ErrAreaNodeNameUnique = errors.New("area name must be unique")
	ErrHostUnique         = errors.New("host must be unique")
)

Errors.

View Source
var (
	// ErrGeoCoordinatesLongitude is returned when the longitude is not valid.
	ErrGeoCoordinatesLongitude = errors.New("longitude is not valid")
	// ErrGeoCoordinatesLatitude is returned when the latitude is not valid.
	ErrGeoCoordinatesLatitude = errors.New("latitude is not valid")
)
View Source
var (
	// ErrInfrastructureAreaIdentifiersUnique is returned when an node identifier is duplicated.
	ErrInfrastructureAreaIdentifiersUnique = errors.New("infrastructure node identifiers unique")
	// ErrInfrastructureAreaIdentifiersEmpty is returned when the Infrastructure has no node identifiers.
	ErrInfrastructureAreaIdentifiersEmpty = errors.New("infrastructure node identifiers empty")
	// ErrInfrastructureNodeIdentifierEmpty is returned when an node identifier is empty.
	ErrInfrastructureAreaIdentifierEmpty = errors.New("infrastructure node identifier empty")
)

Errors.

View Source
var (
	ErrAreaNameEmpty         = errors.New("area name cannot be empty")
	ErrHostEmpty             = errors.New("host cannot be empty")
	ErrLatitudeOutOfRange    = errors.New("latitude out of range")
	ErrLongitudeOutOfRange   = errors.New("longitude out of range")
	ErrResourceValueNegative = errors.New("resource value cannot be negative")
)

Errors.

Functions

func CheckArea

func CheckArea(area Area, maxDepth float64, areasMap map[string]*Area, hostsMap map[string]bool) error

CheckArea checks the Area.

func CheckGeoCoordinates

func CheckGeoCoordinates(coordinates GeoCoordinates) error

CheckGeoCoordinates checks if the GeoCoordinates are valid.

func CheckInfrastructure

func CheckInfrastructure(infrastructure Infrastructure) (map[string]*Area, error)

CheckInfrastructure checks the Infrastructure.

func CheckNode

func CheckNode(node Node) error

CheckNode checks the node.

func MarshalArea

func MarshalArea(area Area) ([]byte, error)

MarshalArea marshals the Area.

func MarshalInfrastructure

func MarshalInfrastructure(infrastructure Infrastructure) ([]byte, error)

MarshalInfrastructure marshals the Infrastructure.

func MarshalNode

func MarshalNode(node Node) ([]byte, error)

MarshalNode marshals the node.

func MarshallGeoCoordinates

func MarshallGeoCoordinates(coordinates GeoCoordinates) ([]byte, error)

MarshallGeoCoordinates marshalls the GeoCoordinates.

Types

type Area

type Area struct {
	Node
	// The sub-areas.
	Areas []Area `json:"areas,omitempty"`
}

Struct that represents an Area.

func NewArea

func NewArea(node Node, areas []Area) (*Area, map[string]*Area, error)

NewArea creates a new Area.

func UnmarshalArea

func UnmarshalArea(data []byte) (*Area, error)

UnmarshalArea unmarshals the Area.

func (*Area) Flatten

func (a *Area) Flatten() []*Area

Returns the flatten list of areas.

func (*Area) String

func (a *Area) String() string

String returns the string representation of the Area.

type GeoCoordinates

type GeoCoordinates struct {
	Longitude float64 `json:"longitude"`
	Latitude  float64 `json:"latitude"`
}

func NewGeoCoordinates

func NewGeoCoordinates(longitude float64, latitude float64) (*GeoCoordinates, error)

NewGeoCoordinates creates a new GeoCoordinates.

func UnmarshalGeoCoordinates

func UnmarshalGeoCoordinates(data []byte) (*GeoCoordinates, error)

UnmarshalGeoCoordinates unmarshals the GeoCoordinates.

func (*GeoCoordinates) String

func (g *GeoCoordinates) String() string

String returns the string representation of the GeoCoordinates.

type Infrastructure

type Infrastructure struct {
	// Area identifiers are used to identify the hierarchy of areas.
	AreaIdentifiers []string `json:"areaIdentifiers"`
	// Areas are the hierarchy of areas.
	Areas []Area `json:"areas"`
}

Struct that represents the entry point of the infrastructure.

func NewInfrastructure

func NewInfrastructure(areaIdentifiers []string, areas []Area) (*Infrastructure, map[string]*Area, error)

NewInfrastructure creates a new Infrastructure.

func UnmarshalInfrastructure

func UnmarshalInfrastructure(data []byte) (*Infrastructure, map[string]*Area, error)

UnmarshalInfrastructure unmarshals the Infrastructure.

func (*Infrastructure) Flatten

func (i *Infrastructure) Flatten() []*Area

Returns the flatten list of areas.

func (*Infrastructure) String

func (i *Infrastructure) String() string

String returns the string representation of the Infrastructure.

type Node

type Node struct {
	// The name of the node.
	AreaName string `json:"areaName"`
	// The host of the node.
	Host string `json:"host"`
	// The geo coordinates of the node.
	GeoCoordinates GeoCoordinates `json:"geoCoordinates,omitempty"`
	// The resources of the node.
	Resources Resources `json:"resources,omitempty"`
	// The tags of the node.
	Tags map[string]string `json:"tags,omitempty"`
}

Struct that represents the data of a node.

func NewNode

func NewNode(areaName string, host string, geoCoordinates GeoCoordinates) (*Node, error)

NewNode creates a new node.

func UnmarshalNode

func UnmarshalNode(data []byte) (*Node, error)

UnmarshalNode unmarshals the node.

func (*Node) String

func (n *Node) String() string

String returns the string representation of the Node.

type Resources

type Resources = map[string]float64

Type that represents a map of resources and their values.

Jump to

Keyboard shortcuts

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