Skip to content

duckbunny/service

Repository files navigation

###Service

Is the basic template to define microservices in json and yaml format.

GoDoc Build Status Coverage Status Go Report Card

service

-- import "github.com/duckbunny/service"

Package service is the definition of the microservice.

The Service definition is used to automate bootstrap microservices, automate communication between separate services and to provide a human readable definition of a service.

Usage

var (
	//ErrNoPort when no port has been set for service
	ErrNoPort = errors.New("No port set")
	//ErrNoHost when no host has been set for service
	ErrNoHost = errors.New("No host set")
)

type Config

type Config struct {
	// Key name for variable
	Key string `json:"key" yaml:"Key"`
	// Required configuration variable
	Required bool `json:"required,omitempty" yaml:"Required"`
	// Description: A human readable description of the parameter.
	Description string `json:"description" yaml:"Description"`
}

Config represents one configuration value

type Configs

type Configs []Config

Configs represents a slice of configs

type Flag

type Flag struct {
	// Key is the flag designation for the command line flag.
	Key string `json:"key" yaml:"Key"`

	// Env is an environment variable that can bes set in lieu of the flag.
	// CLI flag always overrides environment variable.
	Env string `json:"env" yaml:"Env"`

	// Description is the human readable description of the flag.
	Description string `json:"description" yaml:"Description"`

	// Required defines flag as required.
	Required bool `json:"required" yaml:"Required"`
}

Flag represents a single command line flag.

type Flags

type Flags []Flag

Flags represents a slice of Flags.

func (Flags) GetFlag

func (fs Flags) GetFlag(key string) (Flag, error)

GetFlag by key.

func (Flags) Required

func (fs Flags) Required() []Flag

Required returns a slice required flags.

func (Flags) RequiredKeys

func (fs Flags) RequiredKeys() []string

RequiredKeys returns a slice required flag keys.

type Service

type Service struct {

	// Title: Title for service.
	Title string `json:"title" yaml:"Title"`

	// Domain: Domain of the Service many times the github user or organization.
	Domain string `json:"domain" yaml:"Domain"`

	// Version: Version of the Service.
	Version string `json:"version" yaml:"Version"`

	// Type: Category or type of the Service.
	Type string `json:"type" yaml:"Type"`

	// Type: Protocol of the service.
	Protocol string `json:"protocol" yaml:"Protocol"`

	// Private: True if the Service is for internal use only.
	Private bool `json:"private" yaml:"Private"`

	// Requires: An array of Services that are required for this Service,
	// must contain Title, Domain, and Version.
	Requires []Service `json:"requires,omitempty" yaml:"Requires"`

	// Configs: An array of configurations this service can use.
	Configs Configs `json:"configs,omitempty" yaml:"Configs"`

	// Parameters: An array of parameters to call this Service.
	Flags Flags `json:"flags,omitempty" yaml:"Flags"`

	// Port: The Port this service will serve from.  Only applies to local instance.
	Port string `json:"-" yaml:"-"`

	// Host: The hostname from which this service will serve from.  Only applies to local instance.
	Host string `json:"-" yaml:"-"`
}

Service definition

func LoadFromFile

func LoadFromFile(file string) (*Service, error)

LoadFromFile gets a new Service from yaml service definition file.

func LoadFromJSON

func LoadFromJSON(js []byte) (*Service, error)

LoadFromJSON loads to new Service from json bytes service definition

func New

func New() *Service

New get a new Service.

func This

func This() (*Service, error)

This shortcuts to load Service for this application.

func (*Service) LoadFromFile

func (s *Service) LoadFromFile(file string) error

LoadFromFile loads yaml service definition file into current service.

func (*Service) LoadFromJSON

func (s *Service) LoadFromJSON(js []byte) error

LoadFromJSON loads service definition into current Service

func (*Service) ToJSON

func (s *Service) ToJSON() ([]byte, error)

ToJSON converst current service to json

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages