forked from go-micro/go-micro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.go
45 lines (37 loc) · 977 Bytes
/
web.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Package web provides web based micro services
package web
import (
"context"
"net/http"
"time"
"github.com/google/uuid"
)
// Service is a web service with service discovery built in
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
}
//Option for web
type Option func(o *Options)
//Web basic Defaults
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 }
)
// NewService returns a new web.Service
func NewService(opts ...Option) Service {
return newService(opts...)
}