gateway

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2019 License: Apache-2.0 Imports: 8 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetServiceIP

func GetServiceIP() (string, error)

GetServiceIP returns the valid IP of the microservice container.

Types

type API

type API struct {
	ID                     string   `json:"id,omitempty"`
	CreatedAt              int      `json:"created_at,omitempty"`
	Hosts                  []string `json:"hosts,omitempty"`
	URIs                   []string `json:"-"`
	Methods                []string `json:"-"`
	HTTPIfTerminated       bool     `json:"http_if_terminated,omitempty"`
	HTTPSOnly              bool     `json:"https_only,omitempty"`
	Name                   string   `json:"name,omitempty"`
	PreserveHost           bool     `json:"preserve_host,omitempty"`
	Retries                int      `json:"retries,omitempty"`
	StripURI               bool     `json:"strip_uri,omitempty"`
	UpstreamConnectTimeout int      `json:"upstream_connect_timeout,omitempty"`
	UpstreamReadTimeout    int      `json:"upstream_read_timeout,omitempty"`
	UpstreamSendTimeout    int      `json:"upstream_send_timeout,omitempty"`
	UpstreamURL            string   `json:"upstream_url,omitempty"`
}

API is a structure that represents Kong's API object. See https://getkong.org/docs/0.10.x/admin-api/#api-object

func NewAPIConf

func NewAPIConf() *API

NewAPIConf creates new API object with sensible defaults.

func (*API) AddHost

func (api *API) AddHost(host string)

AddHost adds a new host to the API configuration structure.

type KongGateway

type KongGateway struct {
	// GatewayURL is the admin URL of the kong gateway. This is usually the URL (host plus port) of Kong admin
	GatewayURL string
	// contains filtered or unexported fields
}

KongGateway holds the configuration and values for a pre-defined Kong API Gateway.

func NewKongGateway

func NewKongGateway(adminURL string, client *http.Client, config *MicroserviceConfig) *KongGateway

NewKongGateway creates a Kong Gateway with the given admin URL of kong, an http.Client and a MicroserviceConfig.

func NewKongGatewayFromConfigFile

func NewKongGatewayFromConfigFile(adminURL string, client *http.Client, configFile string) (*KongGateway, error)

NewKongGatewayFromConfigFile creates a Kong Gateway for a given admin URL of kong, an http.Client and a location of a JSON file with the configuration. The configuration JSON has the following structure:

	{
		"name": "The name of the service",
		"port": 8080, // the local microservice port
		"virtual_host": "Microservices upstream virtual host",
		"hosts": ["localhost", "example.org"] // valid HTTP Host header values for this microservice
		"weight": 10, // microservice instance weight used for load ballancing
		"slots": 100 // maximal number of slots to allocate for this microservices group
}

func (*KongGateway) SelfRegister

func (kong *KongGateway) SelfRegister() error

SelfRegister performs a self registration of the microservice with a Kong Gateway. It performs the following tasks: 1. Checks for existence of 'upstream' for the microservices group. If there is no 'upstream' configured, it creates a new one with the given configuration. 2. Checks for the existince of API for the microservices group. If there is no API created on Kong, it creates a new one with the given configuration. 3. Adds new target on kong for the configured 'upstream' and 'API'.

func (*KongGateway) Unregister

func (kong *KongGateway) Unregister() error

Unregister unregisters this instance of the microservice from the Kong Gateway. Basically it updates the upstream target with weight 0, which disables the target.

type MicroserviceConfig

type MicroserviceConfig struct {

	// MicroserviceName is the name of the microservice. This microservice will be registered on the Gateway under this name.
	// Note that this is not the domain (host) of the microservice, but a human readable name of the microservice.
	MicroserviceName string `json:"name,omitempty"`

	// MicroservicePort is the local port on which the microservice is exposed.
	MicroservicePort int `json:"port,omitempty"`

	// VirtualHost is the domain name of the virtual host for all microservices of this name.
	// We can have multiple instances (containers) running on a single platform. Every microservice instance must have the same
	// virtual host name to be a part of the same cluster. For example, if you are exposing a user microservices, then a
	// virtual host might be 'user.services.mydomain.com'. When accessing user microservices you'll call http://user.services.mydomain.com:8000/user
	// which will redirect to a specific microservice.
	// This is a configuration for 'upstream' in Kong Gateway.
	VirtualHost string `json:"virtual_host,omitempty"`

	Paths []string `json:"paths,omitempty"`

	// Hosts is a list of supported hosts by the microservice.
	// When accessing the microservice, you must set the HTTP header 'Host' to a value
	// that is listed in this list of hosts.
	Hosts []string `json:"hosts,omitempty"`

	// Weight is the weight of this particular microservice used for load ballancing by the gateway.
	Weight int `json:"weight,omitempty"`

	// ServicesMaxSlots is the maximal number of slots which the load ballancer on the gateway will
	// allocate for the this VirtualHost.
	ServicesMaxSlots int `json:"slots,omitempty"`
}

MicroserviceConfig represents configuration for the microservice itself.

type Registration

type Registration interface {

	// SelfRegister performs a self registration of the microservice against an API Gateway.
	SelfRegister() error

	// Unregister unregisters previously registerd microservice on an API Gateway.
	Unregister() error
}

Registration registers and unregisters microservices on the API Gateway.

Jump to

Keyboard shortcuts

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