|
|
|
@ -9,11 +9,6 @@ import (
|
|
|
|
|
"go-micro.dev/v4/errors"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var (
|
|
|
|
|
errorRetrievingComponents = errors.InternalServerError("RETRIEVING_COMPONENTS", "error while retrieving components")
|
|
|
|
|
errorComponentsIsNil = errors.InternalServerError("COMPONENTS_NIL", "components is nil")
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type HealthInfo struct {
|
|
|
|
|
Message string `json:"message"`
|
|
|
|
|
IsError bool `json:"is_error"`
|
|
|
|
@ -21,8 +16,6 @@ type HealthInfo struct {
|
|
|
|
|
|
|
|
|
|
type HealthInfoMap map[string]HealthInfo
|
|
|
|
|
|
|
|
|
|
type RegistryKey struct{}
|
|
|
|
|
|
|
|
|
|
type Registry struct {
|
|
|
|
|
components map[string]Component
|
|
|
|
|
|
|
|
|
@ -30,28 +23,6 @@ type Registry struct {
|
|
|
|
|
flagPrefix string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Context(ctx context.Context) (*Registry, error) {
|
|
|
|
|
c, ok := ctx.Value(RegistryKey{}).(*Registry)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, errorRetrievingComponents
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if c == nil {
|
|
|
|
|
return nil, errorComponentsIsNil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return c, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Must(ctx context.Context) *Registry {
|
|
|
|
|
c, err := Context(ctx)
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return c
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func New(service micro.Service, flagPrefix string, components ...Component) *Registry {
|
|
|
|
|
com := &Registry{service: service, flagPrefix: flagPrefix, components: make(map[string]Component)}
|
|
|
|
|
|
|
|
|
|