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