web

package module
v0.0.0-...-493d739 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2019 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// For serving
	DefaultName    = "go-web"
	DefaultVersion = "latest"
	DefaultId      = uuid.NewUUID().String()
	DefaultAddress = ":0"

	// for registration
	DefaultRegisterTTL      = time.Minute
	DefaultRegisterInterval = time.Second * 30
)

Functions

This section is empty.

Types

type Option

type Option func(o *Options)

func Action

func Action(a func(*cli.Context)) Option

Action sets the command action.

func Address

func Address(a string) Option

Address to bind to - host:port

func Advertise(a string) Option

The address to advertise for discovery - host:port

func AfterStart

func AfterStart(fn func() error) Option

AfterStart is executed after server start.

func AfterStop

func AfterStop(fn func() error) Option

AfterStop is executed after server stop.

func BeforeStart

func BeforeStart(fn func() error) Option

BeforeStart is executed before the server starts.

func BeforeStop

func BeforeStop(fn func() error) Option

BeforeStop is executed before the server stops.

func Cmd

func Cmd(c cmd.Cmd) Option

Cmd sets the command instance.

func Context

func Context(ctx context.Context) Option

Context specifies a context for the service. Can be used to signal shutdown of the service. Can be used for extra option values.

func Flags

func Flags(flags ...cli.Flag) Option

Flags sets the command flags.

func Handler

func Handler(h http.Handler) Option

func Id

func Id(id string) Option

Unique server id

func Metadata

func Metadata(md map[string]string) Option

Metadata associated with the service

func Name

func Name(n string) Option

Server name

func RegisterInterval

func RegisterInterval(t time.Duration) Option

func RegisterTTL

func RegisterTTL(t time.Duration) Option

func Registry

func Registry(r registry.Registry) Option

Set registry to be used by the service

func Server

func Server(srv *http.Server) Option

func Version

func Version(v string) Option

Version of the service

type Options

type Options struct {
	Name      string
	Version   string
	Id        string
	Metadata  map[string]string
	Address   string
	Advertise string

	RegisterTTL      time.Duration
	RegisterInterval time.Duration

	Server  *http.Server
	Handler http.Handler

	// Alternative Options
	Context context.Context

	Cmd         cmd.Cmd
	BeforeStart []func() error
	BeforeStop  []func() error
	AfterStart  []func() error
	AfterStop   []func() error
}

type Service

type Service interface {
	Client() *http.Client
	Init(opts ...Option) error
	Handle(pattern string, handler http.Handler)
	HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
	Run() error
	Options() Options
}

func NewService

func NewService(opts ...Option) Service

Jump to

Keyboard shortcuts

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