Documentation ¶
Index ¶
- Variables
- type Service
- func (s *Service) Host() string
- func (s *Service) IP() string
- func (s *Service) PortForURLString() (port string)
- func (s *Service) ProxyURL() *url.URL
- func (s *Service) SpareConfig(configFiles []string) (err error)
- func (s *Service) SpareConfigBytes(configBytes []byte) (err error)
- func (s *Service) URL() *url.URL
- func (s *Service) URLAlternatives() ([]url.URL, []string)
- type ServicesMap
Constants ¶
This section is empty.
Variables ¶
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) IP ¶
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 ¶
PortForURLString returns the service port for URL. If service.Port == 443 or 80 returns an empty string, otherwise returns ":<Port>".
func (*Service) ProxyURL ¶
ProxyURL returns the service Proxy URL safely, it will fallback to the standard URL if no Proxy is set.
func (*Service) SpareConfig ¶
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 ¶
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.
type ServicesMap ¶
func (*ServicesMap) SpareConfig ¶
func (s *ServicesMap) SpareConfig(configFiles []string) (err error)
SpareConfig is the sprbox 'configurable' interface implementation.