go-micro: github.com/micro/go-micro/web Index | Files

package web

import "github.com/micro/go-micro/web"

Package web provides web based micro services

Index

Package Files

options.go service.go web.go

Variables

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

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

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

type Option Uses

type Option func(o *Options)

func Action Uses

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

Action sets the command action.

func Address Uses

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 Uses

func AfterStart(fn func() error) Option

AfterStart is executed after server start.

func AfterStop Uses

func AfterStop(fn func() error) Option

AfterStop is executed after server stop.

func BeforeStart Uses

func BeforeStart(fn func() error) Option

BeforeStart is executed before the server starts.

func BeforeStop Uses

func BeforeStop(fn func() error) Option

BeforeStop is executed before the server stops.

func Context Uses

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 Uses

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

Flags sets the command flags.

func HandleSignal Uses

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 Handler Uses

func Handler(h http.Handler) Option

func Icon Uses

func Icon(ico string) Option

Icon specifies an icon url to load in the UI

func Id Uses

func Id(id string) Option

Unique server id

func Metadata Uses

func Metadata(md map[string]string) Option

Metadata associated with the service

func MicroService Uses

func MicroService(s micro.Service) Option

MicroService sets the micro.Service used internally

func Name Uses

func Name(n string) Option

Server name

func RegisterCheck Uses

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

RegisterCheck run func before registry service

func RegisterInterval Uses

func RegisterInterval(t time.Duration) Option

Register the service with at interval

func RegisterTTL Uses

func RegisterTTL(t time.Duration) Option

Register the service with a TTL

func Registry Uses

func Registry(r registry.Registry) Option

Registry used for discovery

func Secure Uses

func Secure(b bool) Option

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

func Server Uses

func Server(srv *http.Server) Option

func StaticDir Uses

func StaticDir(d string) Option

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

func TLSConfig Uses

func TLSConfig(t *tls.Config) Option

TLSConfig to be used for the transport.

func Version Uses

func Version(v string) Option

Version of the service

type Options Uses

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

    Action func(*cli.Context)
    Flags  []cli.Flag

    RegisterTTL      time.Duration
    RegisterInterval time.Duration

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

    Server  *http.Server
    Handler http.Handler

    // Alternative Options
    Context context.Context

    Registry registry.Registry
    Service  micro.Service

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

    // Static directory
    StaticDir string

    Signal bool
}

type Service Uses

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

Service is a web service with service discovery built in

func NewService Uses

func NewService(opts ...Option) Service

NewService returns a new web.Service

Package web imports 22 packages (graph) and is imported by 22 packages. Updated 2020-01-30. Refresh now. Tools for package owners.