go-micro.dev/v5@v5.12.0/web/web.go (about)

     1  // Package web provides web based micro services
     2  package web
     3  
     4  import (
     5  	"context"
     6  	"net/http"
     7  	"time"
     8  
     9  	"github.com/google/uuid"
    10  )
    11  
    12  // Service is a web service with service discovery built in.
    13  type Service interface {
    14  	Client() *http.Client
    15  	Init(opts ...Option) error
    16  	Options() Options
    17  	Handle(pattern string, handler http.Handler)
    18  	HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
    19  	Start() error
    20  	Stop() error
    21  	Run() error
    22  }
    23  
    24  // Option for web.
    25  type Option func(o *Options)
    26  
    27  // Web basic Defaults.
    28  var (
    29  	// For serving.
    30  	DefaultName    = "go-web"
    31  	DefaultVersion = "latest"
    32  	DefaultId      = uuid.New().String()
    33  	DefaultAddress = ":0"
    34  
    35  	// for registration.
    36  	DefaultRegisterTTL      = time.Second * 90
    37  	DefaultRegisterInterval = time.Second * 30
    38  
    39  	// static directory.
    40  	DefaultStaticDir     = "html"
    41  	DefaultRegisterCheck = func(context.Context) error { return nil }
    42  )
    43  
    44  // NewService returns a new web.Service.
    45  func NewService(opts ...Option) Service {
    46  	return newService(opts...)
    47  }