service

package module
v0.0.0-...-51b0d1f Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2016 License: LGPL-3.0 Imports: 7 Imported by: 5

README

###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

Documentation

Overview

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.

Index

Constants

This section is empty.

Variables

View Source
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")
)

Functions

This section is empty.

Types

type APIDefinition

type APIDefinition struct {
	// Type represents the type of API definition (swagger, apiblueprint)
	Type string `json:"type,omitempty" yaml:"Type"`
	// LocationType defines how to find the API definition (url, vcs)
	LocationType string `json:"locationType,omitempty" yaml:"LocationType"`
	// VCS defines the API definition as found in a VCS repository
	VCS `json:"vcs,omitempty" yaml:"VCS"`
	// URL gives API Definition's location on the web
	URL string `json:"url,omitempty" yaml:"URL"`
}

APIDefinition Defines how to access the API

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 value.
	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"`

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

	// APIDefinition: APIDefinition of the service.
	APIDefinition `json:"apiDefinition" yaml:"APIDefinition"`

	// 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 `json:"configs,omitempty" yaml:"Configs"`

	// Parameters: An array of parameters to call this Service.
	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

type VCS

type VCS struct {
	// Location is the VCS endpoint
	Location string `json:"location,omitempty" yaml:"Location"`
	// Type is the VCS type (git, hg)
	Type string `json:"type,omitempty" yaml:"Type"`
	// File is where to find the definition in relation to the root of the repository
	File string `json:"file,omitempty" yaml:"File"`
}

VCS holds the information to load an API Definition from a VCS repository

Jump to

Keyboard shortcuts

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