68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package datastore
|
|
|
|
import "context"
|
|
|
|
type AgentRepository interface {
|
|
Create(ctx context.Context, remoteID string, state AgentStatus) (*Agent, error)
|
|
Get(ctx context.Context, id AgentID) (*Agent, error)
|
|
Update(ctx context.Context, id AgentID, updates ...AgentUpdateOptionFunc) (*Agent, error)
|
|
Query(ctx context.Context, opts ...AgentQueryOptionFunc) ([]*Agent, int, error)
|
|
Delete(ctx context.Context, id AgentID) error
|
|
|
|
UpdateSpec(ctx context.Context, id AgentID, name string, revision int, data map[string]any) (*Spec, error)
|
|
GetSpecs(ctx context.Context, id AgentID) ([]*Spec, error)
|
|
DeleteSpec(ctx context.Context, id AgentID, name string) error
|
|
}
|
|
|
|
type AgentQueryOptionFunc func(*AgentQueryOptions)
|
|
|
|
type AgentQueryOptions struct {
|
|
Limit *int
|
|
Offset *int
|
|
RemoteIDs []string
|
|
IDs []AgentID
|
|
Statuses []AgentStatus
|
|
}
|
|
|
|
func WithAgentQueryLimit(limit int) AgentQueryOptionFunc {
|
|
return func(opts *AgentQueryOptions) {
|
|
opts.Limit = &limit
|
|
}
|
|
}
|
|
|
|
func WithAgentQueryOffset(offset int) AgentQueryOptionFunc {
|
|
return func(opts *AgentQueryOptions) {
|
|
opts.Offset = &offset
|
|
}
|
|
}
|
|
|
|
func WithAgentQueryRemoteID(remoteIDs ...string) AgentQueryOptionFunc {
|
|
return func(opts *AgentQueryOptions) {
|
|
opts.RemoteIDs = remoteIDs
|
|
}
|
|
}
|
|
|
|
func WithAgentQueryID(ids ...AgentID) AgentQueryOptionFunc {
|
|
return func(opts *AgentQueryOptions) {
|
|
opts.IDs = ids
|
|
}
|
|
}
|
|
|
|
func WithAgentQueryStatus(statuses ...AgentStatus) AgentQueryOptionFunc {
|
|
return func(opts *AgentQueryOptions) {
|
|
opts.Statuses = statuses
|
|
}
|
|
}
|
|
|
|
type AgentUpdateOptionFunc func(*AgentUpdateOptions)
|
|
|
|
type AgentUpdateOptions struct {
|
|
Status *AgentStatus
|
|
}
|
|
|
|
func WithAgentUpdateStatus(status AgentStatus) AgentUpdateOptionFunc {
|
|
return func(opts *AgentUpdateOptions) {
|
|
opts.Status = &status
|
|
}
|
|
}
|