models

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusUnknown = iota
	StatusCreated
	StatusRunning
	StatusFinished
	StatusStopped
	StatusError
)

Variables

View Source
var (
	// ErrNotFound returns when request record not found in db
	ErrNotFound = errors.New("record not found")
)

Functions

func DbIntoGin

func DbIntoGin(db *DB) gin.HandlerFunc

DbIntoGin inspired from `https://gqlgen.com/recipes/gin/#accessing-gincontext`

func NewNotFoundErr

func NewNotFoundErr(key string) error

NewNotFoundErr wrap not found error with specific msg

Types

type DB

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

func DBFromGin

func DBFromGin(c *gin.Context) *DB

DBFromGin inspired from `https://gqlgen.com/recipes/gin/#accessing-gincontext`

func NewDB

func NewDB(path string) (*DB, error)

func (*DB) DeleteTask

func (d *DB) DeleteTask(id string) error

DeleteTask delete a task by given ID from DB

func (*DB) GetTask

func (d *DB) GetTask(id string) (*Task, error)

GetTask get task from db and parsed into struct with specific ID

func (*DB) ListTasks

func (d *DB) ListTasks() ([]*Task, error)

ListTasks create a db iterator and conduct result tasks

func (*DB) SaveTask

func (d *DB) SaveTask(t *Task) error

SaveTask save a task into DB

type Endpoint

type Endpoint struct {
	Type    ServiceType `json:"type"`
	Path    string      `json:"path"`
	Options interface{} `json:"options,omitempty"`
}

Endpoint contains info to create an endpoint

type ServiceType

type ServiceType string

func (ServiceType) MarshalGQL

func (st ServiceType) MarshalGQL(w io.Writer)

func (*ServiceType) Parse

func (st *ServiceType) Parse(t string)

Parse type string into ServiceType

func (ServiceType) String

func (st ServiceType) String() string

String implement Stringer for ServiceType

func (*ServiceType) UnmarshalGQL

func (st *ServiceType) UnmarshalGQL(v interface{}) error

type Task

type Task struct {
	ID        string                 `json:"id"`
	Name      string                 `json:"name"`
	Type      TaskType               `json:"type"`
	Status    TaskStatus             `json:"status"`
	CreatedAt time.Time              `json:"created_at"`
	UpdatedAt time.Time              `json:"updated_at"`
	Src       Endpoint               `json:"src"`
	Dst       Endpoint               `json:"dst"`
	Options   map[string]interface{} `json:"options,omitempty"`
}

Task contains info of data migration task

func NewTask

func NewTask() *Task

NewTask created a task with default value

func (Task) FormatKey

func (t Task) FormatKey() []byte

FormatKey format db key for task

func (Task) FormatProtoTask

func (t Task) FormatProtoTask() (*proto.Task, error)

FormatProtoTask conduct task into *proto.Task

type TaskStatus

type TaskStatus int

TaskStatus represent status of task

func (*TaskStatus) IsRunning

func (ts *TaskStatus) IsRunning() bool

IsRunning assert whether task status is running

func (TaskStatus) MarshalGQL

func (ts TaskStatus) MarshalGQL(w io.Writer)

func (*TaskStatus) Parse

func (ts *TaskStatus) Parse(status string)

Parse status string into TaskStatus

func (TaskStatus) String

func (ts TaskStatus) String() string

String implement Stringer for TaskStatus

func (*TaskStatus) UnmarshalGQL

func (ts *TaskStatus) UnmarshalGQL(v interface{}) error

type TaskType

type TaskType uint32

func (TaskType) MarshalGQL

func (tt TaskType) MarshalGQL(w io.Writer)

func (*TaskType) Parse

func (tt *TaskType) Parse(t string)

Parse type string into TaskType

func (TaskType) String

func (tt TaskType) String() string

String implement Stringer for TaskType

func (*TaskType) UnmarshalGQL

func (tt *TaskType) UnmarshalGQL(v interface{}) error

Jump to

Keyboard shortcuts

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