web

package
v1.6.9 Latest Latest
Warning

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

Go to latest
Published: May 5, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Overview

Package web provides web based vine services

Index

Constants

View Source
const (
	MethodGet     = "GET"     // RFC 7231, 4.3.1
	MethodHead    = "HEAD"    // RFC 7231, 4.3.2
	MethodPost    = "POST"    // RFC 7231, 4.3.3
	MethodPut     = "PUT"     // RFC 7231, 4.3.4
	MethodPatch   = "PATCH"   // RFC 5789
	MethodDelete  = "DELETE"  // RFC 7231, 4.3.5
	MethodConnect = "CONNECT" // RFC 7231, 4.3.6
	MethodOptions = "OPTIONS" // RFC 7231, 4.3.7
	MethodTrace   = "TRACE"   // RFC 7231, 4.3.8
	MethodAny     = "*"
)

Variables

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

	// for registration
	DefaultRegisterTTL      = time.Second * 90
	DefaultRegisterInterval = time.Second * 30

	// static directory
	DefaultStaticDir     = "html"
	DefaultRegisterCheck = func(context.Context) error { return nil }
)

Web basic Defaults

Functions

This section is empty.

Types

type Option

type Option func(o *Options)

Option for web

func Action

func Action(a func(*cobra.Command, []string)) Option

Action sets the command action.

func Address

func Address(a string) Option

Address to bind to - host:port

func Advertise(a string) Option

Advertise 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 App

func App(app *gin.Engine) Option

App for custom gin.Engine

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 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 FlagSet added in v1.4.20

func FlagSet(flagSet *pflag.FlagSet) Option

FlagSet sets the command flagSet.

func HandleSignal

func HandleSignal(b bool) Option

HandleSignal toggles automatic installation of the signal handler that traps TERM, INT, and QUIT. Users of this feature to disable the signal handler, should control liveness of the service through the context.

func Icon

func Icon(ico string) Option

Icon specifies an icon url to load in the UI

func Id

func Id(id string) Option

Id for Unique server id

func Metadata

func Metadata(md map[string]string) Option

Metadata associated with the service

func Name

func Name(n string) Option

Name of Web

func RegisterCheck

func RegisterCheck(fn func(context.Context) error) Option

RegisterCheck run func before registry service

func RegisterInterval

func RegisterInterval(t time.Duration) Option

RegisterInterval Register the service with at interval

func RegisterTTL

func RegisterTTL(t time.Duration) Option

RegisterTTL Register the service with a TTL

func Registry

func Registry(r registry.Registry) Option

Registry used for discovery

func Secure

func Secure(b bool) Option

Secure Use secure communication. If TLSConfig is not specified we use InsecureSkipVerify and generate a self signed cert

func StaticDir

func StaticDir(d string) Option

StaticDir sets the static file directory. This defaults to ./html

func TLSConfig

func TLSConfig(t *tls.Config) Option

TLSConfig to be used for the transport.

func Version

func Version(v string) Option

Version of the service

func VineService

func VineService(s vine.Service) Option

VineService sets the vine.Service used internally

type Options

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

	Action  func(*cobra.Command, []string)
	FlagSet *pflag.FlagSet

	RegisterTTL      time.Duration
	RegisterInterval time.Duration

	// RegisterCheck runs a check function before registering the service
	RegisterCheck func(context.Context) error

	App *gin.Engine

	// Alternative Options
	Context context.Context

	Registry registry.Registry
	Service  vine.Service

	Secure      bool
	TLSConfig   *tls.Config
	BeforeStart []func() error
	BeforeStop  []func() error
	AfterStart  []func() error
	AfterStop   []func() error

	// Static directory
	StaticDir string

	Signal bool
}

Options for web

type Service

type Service interface {
	Client() *http.Client
	Init(opts ...Option) error
	Options() Options
	Handle(method, pattern string, handler gin.HandlerFunc)
	Run() error
}

Service is a web service with service discovery built in

func NewService

func NewService(opts ...Option) Service

NewService returns a new web.Service

Jump to

Keyboard shortcuts

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