service

package
v0.0.0-...-0bd6e25 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: MPL-2.0 Imports: 5 Imported by: 5

Documentation

Index

Constants

View Source
const (
	ManagerCategory = "manager"
	ConfigFlag      = "config"
)

Variables

This section is empty.

Functions

func IsEqualProxy

func IsEqualProxy(first *Proxy, second *Proxy) bool

IsEqualProxy returns true if the proxies match.

func IsEqualRule

func IsEqualRule(first *Rule, second *Rule) bool

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 IsProxyExist(proxies []*Proxy, id string) bool

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

func IsSourceExist(sources []*Source, rule *Rule) bool

IsSourceExist returns true if the sources contains the rule

func IsSourceServiceExist

func IsSourceServiceExist(proxies []*SourceService, id string) bool

func IsStringSliceValid

func IsStringSliceValid(haystack []string) bool

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

func ManagerId(serviceId string) string

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

func ValidateServiceType(t Type) error

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

func (*Proxy) IsValid

func (proxy *Proxy) IsValid() bool

IsValid returns true if all fields are set

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

func (unit *Rule) ExcludeCommands(commands ...string) *Rule

ExcludeCommands adds the list of commands as an exception for proxies

func (*Rule) IsEmpty

func (unit *Rule) IsEmpty() bool

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

func (unit *Rule) IsEmptyCommands() bool

IsEmptyCommands returns true if all Commands are in the ExcludedCommands

func (*Rule) IsHandler

func (unit *Rule) IsHandler() bool

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

func (unit *Rule) IsRoute() bool

IsRoute returns true if for the route destination. The rule is a route destination if Urls, Categories and Commands are given

func (*Rule) IsService

func (unit *Rule) IsService() bool

IsService returns true for the service destination. The rule is a service destination if Urls are given, but not Categories and Commands.

func (*Rule) IsValid

func (unit *Rule) IsValid() bool

IsValid returns true for a valid destination. The rule is considered valid if it's for route or handler or service.

The empty rule is not a valid rule.

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 New

func New(id string, url string, serviceType Type, managerClient *clientConfig.Client) *Service

New generates a service configuration. It also generates the manager client

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

func (s *Service) SourceExist(id string) bool

SourceExist returns true if the proxy id exists in the sources

func (*Service) ValidateTypes

func (s *Service) ValidateTypes() error

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

func (Type) String

func (s Type) String() string

type Unit

type Unit struct {
	ServiceId string `json:"service_id"` // Service id
	HandlerId string `json:"handler_id"` // Handler id
	Command   string `json:"command"`    // Route command
}

Jump to

Keyboard shortcuts

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