github.com/annwntech/go-micro/v2@v2.9.5/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  	Run() error
    20  }
    21  
    22  //Option for web
    23  type Option func(o *Options)
    24  
    25  //Web basic Defaults
    26  var (
    27  	// For serving
    28  	DefaultName    = "go-web"
    29  	DefaultVersion = "latest"
    30  	DefaultId      = uuid.New().String()
    31  	DefaultAddress = ":0"
    32  
    33  	// for registration
    34  	DefaultRegisterTTL      = time.Second * 90
    35  	DefaultRegisterInterval = time.Second * 30
    36  
    37  	// static directory
    38  	DefaultStaticDir     = "html"
    39  	DefaultRegisterCheck = func(context.Context) error { return nil }
    40  )
    41  
    42  // NewService returns a new web.Service
    43  func NewService(opts ...Option) Service {
    44  	return newService(opts...)
    45  }