2019-06-03 21:30:43 +03:00
|
|
|
// Package web provides web based micro services
|
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
2019-12-05 17:15:35 +03:00
|
|
|
"context"
|
2019-06-03 21:30:43 +03:00
|
|
|
"net/http"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Service is a web service with service discovery built in
|
|
|
|
type Service interface {
|
|
|
|
Init(opts ...Option) error
|
|
|
|
Options() Options
|
|
|
|
Handle(pattern string, handler http.Handler)
|
|
|
|
HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request))
|
|
|
|
Run() error
|
|
|
|
}
|
|
|
|
|
2020-04-05 13:15:38 +03:00
|
|
|
//Option for web
|
2019-06-03 21:30:43 +03:00
|
|
|
type Option func(o *Options)
|
|
|
|
|
2020-04-05 13:15:38 +03:00
|
|
|
//Web basic Defaults
|
2019-06-03 21:30:43 +03:00
|
|
|
var (
|
|
|
|
// For serving
|
|
|
|
DefaultName = "go-web"
|
|
|
|
DefaultVersion = "latest"
|
|
|
|
DefaultId = uuid.New().String()
|
|
|
|
DefaultAddress = ":0"
|
|
|
|
|
|
|
|
// for registration
|
2020-05-20 13:49:09 +03:00
|
|
|
DefaultRegisterTTL = time.Second * 90
|
2019-06-03 21:30:43 +03:00
|
|
|
DefaultRegisterInterval = time.Second * 30
|
|
|
|
|
|
|
|
// static directory
|
2019-12-05 17:15:35 +03:00
|
|
|
DefaultStaticDir = "html"
|
|
|
|
DefaultRegisterCheck = func(context.Context) error { return nil }
|
2019-06-03 21:30:43 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// NewService returns a new web.Service
|
|
|
|
func NewService(opts ...Option) Service {
|
|
|
|
return newService(opts...)
|
|
|
|
}
|