services

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2019 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var PublicIP string

The preferred outbound ip of this machine http://stackoverflow.com/a/37382208/3079922.

Functions

This section is empty.

Types

type Service

type Service struct {
	// Name is the service name.
	Name string `yaml:"Name"`

	// Version of the service.
	Version string `sprbox:"default=1" yaml:"Version"`

	// ProxyService is optional, default no proxy.
	// It only works inside ServicesMap struct:
	// the proxy will be automatically populated based
	// on the proxy service name.
	ProxyService string `yaml:"ProxyService"`

	// Proxy will be automatically populated inside ServicesMap struct.
	// Can be set manually in the config file otherwise.
	Proxy *Service `sprbox:"-"`

	// IPs contains the ip list of the machines running this service
	// in the format <public:private> (e.g. 192.168.1.10: 127.0.0.1 locally).
	// use <tasks.serviceName>:<tasks.serviceName> in Docker swarm
	// use <serviceName>:<serviceName> in Docker
	IPs map[string]string `yaml:"IPs"`

	// Port 443 automatically set https scheme when you get the service url.
	// Port 80 and all the others automatically set http scheme when you get the service url.
	Port int `sprbox:"default=80" yaml:"Port"`

	// Hosts contains the host names pointing to this service.
	// The first one will be used to build the service URL,
	// others may be useful for CORS config or whatever you need
	// and they're used in URLAlternatives().
	Hosts []string `yaml:"Hosts"`

	// Basepath is optional, it will be parsed by
	// the template package, so you can use placeholders here
	// (eg.: "{{.Name}}/v{{.Version}}" -> 'api/v1')
	Basepath string `yaml:"Basepath"`

	// Data is optional, set custom data here.
	Data map[string]interface{} `yaml:"Data"`
}

Service is an abstraction of a service (or microservice) or the monolith itself. it holds some basic information useful for service discovery.

func (*Service) Host

func (s *Service) Host() string

Host returns the first host listed in the config file.

func (*Service) IP

func (s *Service) IP() string

IP returns the service private ip address. If not found it returns the public one (or the service name if docker is used).

func (*Service) PortForURLString

func (s *Service) PortForURLString() (port string)

PortForURLString returns the service port for URL. If service.Port == 443 or 80 returns an empty string, otherwise returns ":<Port>".

func (*Service) ProxyURL

func (s *Service) ProxyURL() *url.URL

ProxyURL returns the service Proxy URL safely, it will fallback to the standard URL if no Proxy is set.

func (*Service) SpareConfig

func (s *Service) SpareConfig(configFiles []string) (err error)

SpareConfig is the sprbox 'configurable' interface. if Env() == local the service's primary host will be overriden by outbound IP, that will make possible to connect to it through your local network (wi-fi) also.

func (*Service) SpareConfigBytes

func (s *Service) SpareConfigBytes(configBytes []byte) (err error)

SpareConfigBytes is the sprbox 'configurableInCollections' interface. if Env() == local the service's primary host will be overriden by outbound IP, that will make possible to connect to it through your local network (wi-fi) also.

func (*Service) URL

func (s *Service) URL() *url.URL

URL returns the service URL by service name. If the service use a proxy the proxy scheme and port will be used.

func (*Service) URLAlternatives

func (s *Service) URLAlternatives() ([]url.URL, []string)

URLAlternatives returns the service alternative URLs by service name. If the service use a proxy the proxy scheme and port will be used.

type ServicesMap

type ServicesMap map[string]*Service

func (*ServicesMap) SpareConfig

func (s *ServicesMap) SpareConfig(configFiles []string) (err error)

SpareConfig is the sprbox 'configurable' interface implementation.

Jump to

Keyboard shortcuts

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