1
0
mirror of https://github.com/go-micro/go-micro.git synced 2024-12-18 08:26:38 +02:00
go-micro/web/web.go

48 lines
1015 B
Go
Raw Normal View History

2021-07-06 12:12:19 +02:00
// Package web provides web based micro services
package web
import (
"context"
"net/http"
"time"
"github.com/google/uuid"
)
2022-09-30 16:27:07 +02:00
// Service is a web service with service discovery built in.
2021-07-06 12:12:19 +02:00
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))
Start() error
Stop() error
2021-07-06 12:12:19 +02:00
Run() error
}
2022-09-30 16:27:07 +02:00
// Option for web.
2021-07-06 12:12:19 +02:00
type Option func(o *Options)
2022-09-30 16:27:07 +02:00
// Web basic Defaults.
2021-07-06 12:12:19 +02:00
var (
2022-09-30 16:27:07 +02:00
// For serving.
2021-07-06 12:12:19 +02:00
DefaultName = "go-web"
DefaultVersion = "latest"
DefaultId = uuid.New().String()
DefaultAddress = ":0"
2022-09-30 16:27:07 +02:00
// for registration.
2021-07-06 12:12:19 +02:00
DefaultRegisterTTL = time.Second * 90
DefaultRegisterInterval = time.Second * 30
2022-09-30 16:27:07 +02:00
// static directory.
2021-07-06 12:12:19 +02:00
DefaultStaticDir = "html"
DefaultRegisterCheck = func(context.Context) error { return nil }
)
2022-09-30 16:27:07 +02:00
// NewService returns a new web.Service.
2021-07-06 12:12:19 +02:00
func NewService(opts ...Option) Service {
return newService(opts...)
}