package hostwrite import ( "context" "errors" "strings" ) var ErrUnavailable = errors.New("hostwrite: lifecycle provider unavailable") type Identity struct { Config string Release string } type Work interface { With(context.Context, Identity, func() error) error } type Selector interface { Select(context.Context, string, string) (Work, error) } type Config struct { Enabled bool Selector Selector } func Enabled(getenv func(string) string) bool { return strings.TrimSpace(getenv("CARLOS_HOST_CLAIM")) != "" } func (c Config) Select(ctx context.Context, host, action string) (Work, error) { if !c.Enabled { return legacy{}, nil } if c.Selector == nil { return nil, ErrUnavailable } return c.Selector.Select(ctx, host, action) } type legacy struct{} // Legacy reports whether w is the flag-off pass-through work, so callers // can keep their exact pre-claim behaviour when the flag is unset. func Legacy(w Work) bool { _, ok := w.(legacy) return ok } func (legacy) With(_ context.Context, _ Identity, fn func() error) error { return fn() }