Documentation ¶
Index ¶
- Constants
- func IsEqualProxy(first *Proxy, second *Proxy) bool
- func IsEqualRule(first *Rule, second *Rule) bool
- func IsEqualSourceService(first *SourceService, second *SourceService) bool
- func IsProxyExist(proxies []*Proxy, id string) bool
- func IsRuleExist(proxyChains []*ProxyChain, rule *Rule) bool
- func IsSourceExist(sources []*Source, rule *Rule) bool
- func IsSourceServiceExist(proxies []*SourceService, id string) bool
- func IsStringSliceValid(haystack []string) bool
- func ManagerId(serviceId string) string
- func NewManager(id string, url string) (*clientConfig.Client, error)
- func SourceServiceIndex(proxies []*SourceService, id string) int
- func ValidateServiceType(t Type) error
- type Local
- type Proxy
- type ProxyChain
- type Rule
- type Service
- func (s *Service) ExtensionByUrl(url string) *clientConfig.Client
- func (s *Service) HandlerByCategory(category string) (*handlerConfig.Handler, error)
- func (s *Service) HandlersByCategory(category string) ([]*handlerConfig.Handler, error)
- func (s *Service) SetExtension(extension *clientConfig.Client)
- func (s *Service) SetHandler(handler *handlerConfig.Handler)
- func (s *Service) SetServiceSource(rule *Rule, source *SourceService) bool
- func (s *Service) SourceById(id string) *SourceService
- func (s *Service) SourceExist(id string) bool
- func (s *Service) ValidateTypes() error
- type Source
- type SourceService
- type Type
- type Unit
Constants ¶
const ( ManagerCategory = "manager" ConfigFlag = "config" )
Variables ¶
This section is empty.
Functions ¶
func IsEqualProxy ¶
IsEqualProxy returns true if the proxies match.
func IsEqualRule ¶
IsEqualRule returns true if the fields of both structs match.
func IsEqualSourceService ¶
func IsEqualSourceService(first *SourceService, second *SourceService) bool
IsEqualSourceService returns true if the fields of both structs match.
func IsProxyExist ¶
func IsRuleExist ¶
func IsRuleExist(proxyChains []*ProxyChain, rule *Rule) bool
IsRuleExist returns true if there is a proxy chain that matches to the rule
func IsSourceExist ¶
IsSourceExist returns true if the sources contains the rule
func IsSourceServiceExist ¶
func IsSourceServiceExist(proxies []*SourceService, id string) bool
func IsStringSliceValid ¶
IsStringSliceValid returns true if all elements are unique. Valid string slice must not be nil and elements must not be empty. The empty slice is considered as valid.
func ManagerId ¶
ManagerId generates a service manager id. If no service id, then it will return an error
func NewManager ¶
func NewManager(id string, url string) (*clientConfig.Client, error)
NewManager generates a service manager configuration
func SourceServiceIndex ¶
func SourceServiceIndex(proxies []*SourceService, id string) int
func ValidateServiceType ¶
ValidateServiceType checks whether the given string is the valid or not. If not valid, then returns the error otherwise returns nil.
Types ¶
type Local ¶
type Local struct { LocalSrc string `json:"local_src,omitempty" yaml:"local_src,omitempty"` LocalBin string `json:"local_bin,omitempty" yaml:"local_bin,omitempty"` }
The Local keeps the parameters of the service in the local field. These parameters are optional.
type Proxy ¶
type Proxy struct { *Local Id string `json:"id" yaml:"id"` Url string `json:"url" yaml:"url"` Category string `json:"category" yaml:"category"` // proxy category, example authr, valid, convert }
Proxy in the service.
If two endpoints lint to the same route,
func LastProxies ¶
func LastProxies(proxyChains []*ProxyChain) []*Proxy
LastProxies returns the list of the proxies from all proxy chains. The identical proxies are compacted
type ProxyChain ¶
type ProxyChain struct { Sources []string `json:"sources,omitempty" yaml:"sources,omitempty"` Proxies []*Proxy `json:"proxies" yaml:"proxies"` Destination *Rule `json:"destination" yaml:"destination"` // only shown for a proxy }
func NewProxyChain ¶
func NewProxyChain(params ...interface{}) (*ProxyChain, error)
NewProxyChain creates a proxy chain for the service url
func ProxyChainByRule ¶
func ProxyChainByRule(proxyChains []*ProxyChain, rule *Rule) *ProxyChain
ProxyChainByRule returns a proxy chain that has the rule
func (*ProxyChain) IsProxiesValid ¶
func (proxyChain *ProxyChain) IsProxiesValid() bool
IsProxiesValid returns true if the Proxies field has no duplicate elements. Proxies are compared against their ids.
func (*ProxyChain) IsValid ¶
func (proxyChain *ProxyChain) IsValid() bool
IsValid returns true if the proxy chain is valid. It's counted as valid if it doesn't have a duplicate values. Any nil field makes the proxy chain as invalid.
type Rule ¶
type Rule struct { Urls []string `json:"urls" yaml:"urls"` // Service url Categories []string `json:"categories" yaml:"categories"` // Handler category Commands []string `json:"commands" yaml:"commands"` // Route command ExcludedCommands []string `json:"excluded_commands" yaml:"excluded_commands"` // Exclude this commands from routing }
The Rule is the pattern matching rule to find the services, handlers and routes as the proxy destination.
func NewDestination ¶
func NewDestination(params ...interface{}) *Rule
NewDestination returns a destination rule for routes. Returns nil if params are invalid.
Any parameter could be a string or []string.
func NewHandlerDestination ¶
func NewHandlerDestination(params ...interface{}) *Rule
NewHandlerDestination returns a rule for the handler. Returns nil if parameters are invalid.
Any parameter could be a string or []string.
func NewServiceDestination ¶
func NewServiceDestination(params ...interface{}) *Rule
NewServiceDestination returns a rule for the service. Returns nil if parameter is invalid.
A parameter could be a string or []string. If no parameter is given, returns an empty rule. In that case, set the urls later.
func (*Rule) ExcludeCommands ¶
ExcludeCommands adds the list of commands as an exception for proxies
func (*Rule) IsEmpty ¶
IsEmpty returns true if no fields are given.
One way to create an empty parameter is to call NewServiceDestination() without any argument.
func (*Rule) IsEmptyCommands ¶
IsEmptyCommands returns true if all Commands are in the ExcludedCommands
func (*Rule) IsHandler ¶
IsHandler returns true for the handler destination. The rule is a handler destination if Urls and Categories are given, but not Commands.
func (*Rule) IsRoute ¶
IsRoute returns true if for the route destination. The rule is a route destination if Urls, Categories and Commands are given
type Service ¶
type Service struct { Type Type `json:"type" yaml:"type"` Url string `json:"url" yaml:"url"` Id string `json:"id" yaml:"id"` Manager *clientConfig.Client `json:"manager" yaml:"manager"` Handlers []*handlerConfig.Handler `json:"handlers" yaml:"handlers"` Extensions []*clientConfig.Client `json:"extensions,omitempty" yaml:"extensions,omitempty"` Sources []*Source `json:"sources,omitempty" yaml:"sources,omitempty"` }
Service type defined in the config.
Fields
- Type is the type of service. For example, ProxyType, IndependentType or ExtensionType
- Url to the service source code
- Id within the application
- Manager parameter of the service
- Handlers that are listed in the service
- Extensions that this service depends on
- Sources that are can access to this service
func (*Service) ExtensionByUrl ¶
func (s *Service) ExtensionByUrl(url string) *clientConfig.Client
ExtensionByUrl returns the first occurred extension config by the url. If the extension doesn't exist, then it returns nil
func (*Service) HandlerByCategory ¶
func (s *Service) HandlerByCategory(category string) (*handlerConfig.Handler, error)
HandlerByCategory returns the handler config by the handler category. If the handler doesn't exist, then it returns an error.
func (*Service) HandlersByCategory ¶
func (s *Service) HandlersByCategory(category string) ([]*handlerConfig.Handler, error)
HandlersByCategory returns the multiple handlers of the given name. If the handlers don't exist, then it returns an error
func (*Service) SetExtension ¶
func (s *Service) SetExtension(extension *clientConfig.Client)
SetExtension will set a new extension. If it exists, it will overwrite it
func (*Service) SetHandler ¶
func (s *Service) SetHandler(handler *handlerConfig.Handler)
SetHandler adds a new handler. If the handler by the same id exists, it will over-write that handler.
func (*Service) SetServiceSource ¶
func (s *Service) SetServiceSource(rule *Rule, source *SourceService) bool
SetServiceSource updates the source. Returns true if the Service was updated.
func (*Service) SourceById ¶
func (s *Service) SourceById(id string) *SourceService
SourceById returns the manager parameter of the proxy
func (*Service) SourceExist ¶
SourceExist returns true if the proxy id exists in the sources
func (*Service) ValidateTypes ¶
ValidateTypes the parameters of the service
type Source ¶
type Source struct { Proxies []*SourceService `json:"proxies" yaml:"proxies"` Rule *Rule `json:"rule,omitempty" yaml:"rule,omitempty"` }
The Source defines the proxy
type SourceService ¶
type SourceService struct { *Proxy Manager *clientConfig.Client `json:"manager" yaml:"manager"` Clients []*clientConfig.Client `json:"clients" yaml:"clients"` }
type Type ¶
type Type string
Type defines the available kind of services If you are creating a new service, then define the constant value here.
const ( // ProxyType services are handling the message and redirects it to another service ProxyType Type = "Proxy" // ExtensionType services are exposing the API to be used by Independent, Proxy or other Extension. ExtensionType Type = "Extension" // IndependentType service means the service is intended to be used as a standalone service IndependentType Type = "Independent" )