definition

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ServiceType_gRPC   = CreateServiceType("grpc")
	ServiceType_HTTP   = CreateServiceType("http")
	ServiceType_Native = CreateServiceType("native")
	ServiceType_Script = CreateServiceType("script")
)

Functions

func ParseExternalDefinitions

func ParseExternalDefinitions(path string, defs interface{}) error

ParseExternalDefinitions allows loading specific service definitions from its file using a custom target. This provides external features (plugins) to load their definitions from the same file into their own structures.

func SupportedLanguages

func SupportedLanguages() []string

SupportedLanguages gives a slice of supported programming languages.

func SupportedServiceTypes

func SupportedServiceTypes() []string

SupportedServiceTypes gives a slice of all supported service types.

func ValidateVersion

func ValidateVersion(input string) bool

ValidateVersion is a helper function to validate the version format used by services.

Types

type Definitions

type Definitions struct {
	Name     string                 `toml:"name" validate:"required"`
	Types    []string               `toml:"types" validate:"required,single_script,no_duplicated_service,dive,service_type"`
	Version  string                 `toml:"version" validate:"required,version"`
	Language string                 `toml:"language" validate:"required,oneof=go rust"`
	Product  string                 `toml:"product" validate:"required"`
	Envs     []string               `toml:"envs,omitempty" validate:"dive,ascii,uppercase"`
	Deploy   Deploy                 `toml:"deploy,omitempty"`
	Features Features               `toml:"features,omitempty"`
	HTTP     HTTP                   `toml:"http,omitempty"`
	Log      Log                    `toml:"log,omitempty"`
	Service  map[string]interface{} `toml:"service,omitempty"`
	Clients  map[string]GrpcClient  `toml:"clients,omitempty"`
	// contains filtered or unexported fields
}

Definitions is a structure representation of a 'service.toml' file. It holds all service information that will be used to initialize it as well as all features it will have when executing.

func New

func New() (*Definitions, error)

New creates a new Definitions structure initializing the service features with default values.

func Parse

func Parse(path string) (*Definitions, error)

Parse is responsible for loading the service definitions file (service.toml) into a proper Definitions structure.

func (*Definitions) AddExternalFeatureDefinitions

func (d *Definitions) AddExternalFeatureDefinitions(name string, defs ExternalFeatureEntry)

AddExternalFeatureDefinitions adds definitions from external features into the Definitions object.

func (*Definitions) AddExternalServiceDefinitions

func (d *Definitions) AddExternalServiceDefinitions(name string, defs ExternalServiceEntry)

AddExternalServiceDefinitions adds definitions from external service into the Definitions object.

func (*Definitions) AddSupportedServiceType

func (d *Definitions) AddSupportedServiceType(name string)

AddSupportedServiceType adds a new service type as supported by the service definitions.

func (*Definitions) ExternalFeatureDefinitions

func (d *Definitions) ExternalFeatureDefinitions(name string) (ExternalFeatureEntry, error)

ExternalFeatureDefinitions retrieves definitions from an external feature previously added into the Definitions.

func (*Definitions) ExternalServiceDefinitions

func (d *Definitions) ExternalServiceDefinitions(name string) (ExternalServiceEntry, error)

ExternalServiceDefinitions retrieves definitions from an external service previously added into the Definitions.

func (*Definitions) IsServiceType

func (d *Definitions) IsServiceType(serviceType ServiceType) bool

IsServiceType checks if the current service definitions is of a specific service type.

func (*Definitions) ServiceName

func (d *Definitions) ServiceName() service.Name

ServiceName returns the service.Name loaded from the definitions.

func (*Definitions) ServiceTypes

func (d *Definitions) ServiceTypes() map[ServiceType]service.ServerPort

ServiceTypes gives back all service types found inside the service definitions.

func (*Definitions) ServiceTypesAsString

func (d *Definitions) ServiceTypesAsString() string

func (*Definitions) Validate

func (d *Definitions) Validate() error

Validate validates if all data loaded from the service definitions is correct.

It also validates external services and external features custom definitions.

type Deploy

type Deploy struct {
	DisableProd bool   `toml:"disable_prod"`
	DisableDev  bool   `toml:"disable_dev"`
	Env         string `toml:"env,omitempty" validate:"omitempty,oneof=local test dev prod"`
}

type ExternalFeatureEntry

type ExternalFeatureEntry interface {
	// Enabled must return true or false if the feature is enabled or not.
	Enabled() bool

	// Validate should validate if the custom settings are valid or not.
	Validate() error
}

ExternalFeatureEntry is a behavior that all external feature must have to be supported by the package Definitions object.

type ExternalServiceEntry

type ExternalServiceEntry interface {
	// Name must return the service name that the definitions will support.
	Name() string

	// Validate should validate if the custom settings are valid or not.
	Validate() error
}

ExternalServiceEntry is a behavior that all external services implementation must have to be supported by the Definitions object.

type FeatureEntry

type FeatureEntry struct {
	// Enabled should enable or disable the feature. Default is always to start
	// with the feature disabled.
	Enabled bool `toml:"enabled,omitempty"`
}

FeatureEntry is a structure that an external feature should have so that all presents at least a few common settings.

func (FeatureEntry) IsEnabled

func (f FeatureEntry) IsEnabled() bool

type Features

type Features struct {
	// contains filtered or unexported fields
}

Features is a structure that defines a list of features that a service may use or not when executing. By convention, all features are turned off by default, and should be explicitly enabled when desired using the 'enabled' key.

type GrpcClient

type GrpcClient struct {
	Port int32  `toml:"port"`
	Host string `toml:"host"`
}

type HTTP

type HTTP struct {
	DisableAuth          bool `toml:"disable_auth,omitempty" default:"false"`
	DisablePanicRecovery bool `toml:"disable_panic_recovery,omitempty" default:"false"`
	HideErrorDetails     bool `toml:"hide_error_details,omitempty"`
}

type Log

type Log struct {
	ErrorStacktrace bool   `toml:"error_stacktrace,omitempty"`
	Level           string `toml:"level,omitempty" validate:"omitempty,oneof=info debug error warn internal"`
}

type ServiceDeploy

type ServiceDeploy int32
const (
	ServiceDeploy_Unknown ServiceDeploy = iota
	ServiceDeploy_Production
	ServiceDeploy_Test
	ServiceDeploy_Development
	ServiceDeploy_Local
)

func (ServiceDeploy) FromString

func (e ServiceDeploy) FromString(in string) ServiceDeploy

func (ServiceDeploy) String

func (e ServiceDeploy) String() string

type ServiceType

type ServiceType struct {
	// contains filtered or unexported fields
}

func CreateServiceType

func CreateServiceType(name string) ServiceType

func (ServiceType) String

func (s ServiceType) String() string

Jump to

Keyboard shortcuts

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