gateway

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SERVER_TYPE is the type of the server.
	SERVER_TYPE = "gateway"
)

Variables

View Source
var (
	// ErrGatewayConfigLoad returned when env config for gRPC-gateway results in an error
	ErrGatewayConfigLoad = errors.New("error loading gateway config")
	// ErrNotDefinedHTTPServiceHandlerRegistrar thrown when http service registration handler is not provided
	ErrNotDefinedHTTPServiceHandlerRegistrar = errors.New("http service handler registration callback not provided")
	// ErrHTTPServiceHandlerRegFailed returned when any HTTP service handler registration fails
	ErrHTTPServiceHandlerRegFailed = errors.New("http service handler registration failed")
	// ErrCannotAddMuxOptionAtPos returned when adding new mux option at the specified position is not possible
	ErrCannotAddMuxOptionAtPos = errors.New("cannot add mux option at the position specified")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Host     string `env:"HTTP_HOST,defaut="`
	Port     int    `env:"HTTP_PORT,default=8080"`
	Tags     string `env:"HTTP_CONSUL_TAGS,default="`
	Metadata Metadata
}

Config manages the HTTP server config

func NewConfig

func NewConfig() *Config

NewConfig returns the parsed config for gateway server from env

func (*Config) Address

func (c *Config) Address() string

Address returns the full formatted http address

func (*Config) GetTags

func (c *Config) GetTags() []string

GetTags return the service registry tags slice

type Gateway

type Gateway struct {
	Mux                         *runtime.ServeMux
	Middleware                  []Middleware
	HTTPServiceHandlerRegistrar HTTPServiceHandlerRegistrar
	MuxOptions                  []runtime.ServeMuxOption
	Server                      *http.Server

	*Config
	// contains filtered or unexported fields
}

Gateway handle gRPC gateway

func NewGateway

func NewGateway(opts ...Option) *Gateway

NewGateway creates and returns gRPC-gateway

func (*Gateway) AddRegistryTags

func (g *Gateway) AddRegistryTags(tags ...string)

AddRegistryTags - sets the registry tags for the server

func (*Gateway) Address

func (g *Gateway) Address() string

Address returns the server address

func (*Gateway) GetMetadata

func (g *Gateway) GetMetadata(key string) interface{}

GetMetadata returns the metadata by key

func (*Gateway) HasInitializer

func (g *Gateway) HasInitializer() bool

func (*Gateway) Host

func (g *Gateway) Host() string

Host returns gateway server hostname

func (*Gateway) Initializer

func (g *Gateway) Initializer() component.Initializer

func (*Gateway) Port

func (g *Gateway) Port() int

Port returns gateway server port

func (*Gateway) RegistryTags

func (g *Gateway) RegistryTags() []string

RegistryTags returns gateway server registry tags

func (*Gateway) String

func (g *Gateway) String() string

String - Returns the type of the server

type HTTPServiceHandlerRegistrar

type HTTPServiceHandlerRegistrar func(context.Context, *Gateway) error

HTTPServiceHandlerRegistrar HTTP service handler registration func

type Initializer

type Initializer struct {
	// contains filtered or unexported fields
}

func NewInitializer

func NewInitializer(g *Gateway) *Initializer

NewInitializer returns a new JetStream Initialiazer

func (*Initializer) AddDependency

func (i *Initializer) AddDependency(dep interface{}) error

AddDependency adds necessary service components as dependencies

func (*Initializer) CanRun

func (i *Initializer) CanRun() bool

CanRun returns true if the component has anything to Run

func (*Initializer) CanStop

func (i *Initializer) CanStop() bool

CanRun returns true if the component has anything to Run

func (*Initializer) Dependencies

func (i *Initializer) Dependencies() []string

Dependencies returns the string names of service components that are required as dependencies for this component

func (*Initializer) Run

func (i *Initializer) Run(ctx context.Context) error

Run start the service component

func (*Initializer) Stop

func (i *Initializer) Stop(ctx context.Context) error

Run start the service component

type Metadata

type Metadata struct {
	GrpcHost string `env:"GRPC_HOST,default="`
	GrpcPort int    `env:"GRPC_PORT,default=9090"`
}

Metadata holds the metadata used by the gateway server

func (*Metadata) Get

func (m *Metadata) Get(key string) interface{}

Get returns the gateway metadata by key

type Middleware

type Middleware func(http.Handler) http.Handler

Middleware type

type Option

type Option func(*Gateway)

Option to pass as arg while creating new service

func WithHTTPServiceHandlerRegistrar

func WithHTTPServiceHandlerRegistrar(registrar HTTPServiceHandlerRegistrar) Option

WithHTTPServiceHandlerRegistrar add HTTP service handle registration callback

func WithMiddleware

func WithMiddleware(middleware ...Middleware) Option

WithMiddleware adds middleware to the rest handler

func WithMuxOptions

func WithMuxOptions(opts ...runtime.ServeMuxOption) Option

WithMuxOptions adds mux options

Jump to

Keyboard shortcuts

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