operations

package
v0.8.0-beta.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 23, 2023 License: AGPL-3.0 Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Operations

func Operations() map[string]Operation

func Register

func Register(name string, op Operation) error

Types

type Base

type Base struct {
}

func (*Base) Do

func (b *Base) Do(ctx context.Context, request *OpsRequest) (*OpsResponse, error)

func (*Base) Init

func (b *Base) Init(ctx context.Context) error

func (*Base) IsReadonly

func (b *Base) IsReadonly(ctx context.Context) bool

func (*Base) PreCheck

func (b *Base) PreCheck(ctx context.Context, request *OpsRequest) error

type FakeFuncType

type FakeFuncType string
const (
	FakeInit       FakeFuncType = "fake-init"
	FakeIsReadOnly FakeFuncType = "fake-is-read-only"
	FakePreCheck   FakeFuncType = "fake-pre-check"
	FakeDo         FakeFuncType = "fake-do"
	FakeDefault    FakeFuncType = "fake-default"
)

type FakeOperations

type FakeOperations struct {
	InitFunc       func(ctx context.Context) error
	IsReadOnlyFunc func(ctx context.Context) bool
	PreCheckFunc   func(ctx context.Context, request *OpsRequest) error
	DoFunc         func(ctx context.Context, request *OpsRequest) (*OpsResponse, error)
}

func NewFakeOperations

func NewFakeOperations(funcType FakeFuncType, fakeFunc interface{}) *FakeOperations

func (*FakeOperations) Do

func (f *FakeOperations) Do(ctx context.Context, request *OpsRequest) (*OpsResponse, error)

func (*FakeOperations) Init

func (f *FakeOperations) Init(ctx context.Context) error

func (*FakeOperations) IsReadonly

func (f *FakeOperations) IsReadonly(ctx context.Context) bool

func (*FakeOperations) PreCheck

func (f *FakeOperations) PreCheck(ctx context.Context, request *OpsRequest) error

type Operation

type Operation interface {
	Init(context.Context) error
	IsReadonly(context.Context) bool
	PreCheck(context.Context, *OpsRequest) error
	Do(context.Context, *OpsRequest) (*OpsResponse, error)
}

type Ops

type Ops struct {
	// contains filtered or unexported fields
}

func (*Ops) Operations

func (ops *Ops) Operations() map[string]Operation

func (*Ops) Register

func (ops *Ops) Register(name string, op Operation) error

type OpsMetadata

type OpsMetadata struct {
	Operation util.OperationKind `json:"operation,omitempty"`
	StartTime string             `json:"startTime,omitempty"`
	EndTime   string             `json:"endTime,omitempty"`
	Extra     string             `json:"extra,omitempty"`
}

type OpsRequest

type OpsRequest struct {
	Data       []byte         `json:"data,omitempty"`
	Parameters map[string]any `json:"parameters,omitempty"`
}

OpsRequest is the request for Operation

func (*OpsRequest) GetString

func (r *OpsRequest) GetString(key string) string

type OpsResponse

type OpsResponse struct {
	Data     map[string]any    `json:"data,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

OpsResponse is the response for Operation

func NewOpsResponse

func NewOpsResponse(operation util.OperationKind) *OpsResponse

func (*OpsResponse) WithError

func (resp *OpsResponse) WithError(err error) (*OpsResponse, error)

func (*OpsResponse) WithSuccess

func (resp *OpsResponse) WithSuccess(msg string) (*OpsResponse, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL