Back to godoc.org

Package server

v0.1.4
Latest Go to latest

The latest major version is .

Published: Jul 26, 2020 | License: MIT | Module: github.com/better-go/pkg

Index

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

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
}

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier