server

package
v0.0.0-...-f56a457 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init(opt ...Option)

Init initialises the default server with options passed in

func String

func String() string

String returns name of Server implementation

Types

type Handler

type Handler interface {
	Name() string
	Handler() interface{}
	Options() HandlerOptions
}

Handler interface represents a request handler. It's generated by passing any type of public concrete object with endpoints into server.NewHandler. Most will pass in a struct.

Example:

type Greeter struct {}

func (g *Greeter) Hello(context, request, response) error {
        return nil
}

type HandlerOption

type HandlerOption func(*HandlerOptions)

type HandlerOptions

type HandlerOptions struct {
	Internal bool
	Metadata map[string]map[string]string
}

type Option

type Option func(*Options)

type Options

type Options struct {
	Network      string
	Addr         string
	Timeout      string
	ReadTimeout  string
	WriteTimeout string

	On   bool      // pref switch
	Once sync.Once // do once

	//
	//
	//
	Metadata map[string]string
	Name     string
	Id       string
	Version  string

	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type Server

type Server interface {
	// Initialise options
	Init(...Option) error
	// Retrieve the options
	Options() Options

	// Start the server
	Start() error
	// Stop the server
	Stop(ctx context.Context) error
	// Server implementation
	String() string
}

Server is a simple micro server abstraction

var (
	DefaultServer Server = newGinServer()
	// NewServer creates a new server
	NewServer func(...Option) Server = newGinServer
)

type Subscriber

type Subscriber interface {
	Topic() string
	Subscriber() interface{}
	Options() SubscriberOptions
}

Subscriber interface represents a subscription to a given topic using a specific subscriber function or object with endpoints. It mirrors the handler in its behaviour.

type SubscriberOption

type SubscriberOption func(*SubscriberOptions)

type SubscriberOptions

type SubscriberOptions struct {
	// AutoAck defaults to true. When a handler returns
	// with a nil error the message is acked.
	AutoAck  bool
	Queue    string
	Internal bool
	Context  context.Context
}

Jump to

Keyboard shortcuts

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