server

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIdRequired                    = errors.New("id is required")
	ErrNameRequired                  = errors.New("name is required")
	ErrInvalidName                   = errors.New("name is invalid")
	ErrOneOptionRequired             = errors.New("one option is required")
	ErrOnlyOneOptionAllowed          = errors.New("only one option is allowed")
	ErrServerNotFound                = errors.New("server not found")
	ErrServerIdAlreadyExists         = errors.New("server id already exists")
	ErrServerNameAlreadyInUse        = errors.New("name is already in use")
	ErrInvalidMtu                    = errors.New("invalid MTU must be between 1280 and 1500")
	ErrCreateServerOptionsRequired   = errors.New("create server options are required")
	ErrUpdateServerOptionsRequired   = errors.New("update server options are required")
	ErrUpdateServerFieldMaskRequired = errors.New("update server field mask are required")
)

Functions

This section is empty.

Types

type CreateOptions

type CreateOptions struct {
	Name         string
	Description  string
	Enabled      bool
	PublicKey    string
	PrivateKey   string
	ListenPort   *int
	FirewallMark *int
	Address      string
	DNS          []string
	MTU          int
	Hooks        []*Hook
}

type FindOneOptions

type FindOneOptions struct {
	IdOption   *IdOption
	NameOption *NameOption
}

func (*FindOneOptions) Validate

func (options *FindOneOptions) Validate() error

type FindOptions

type FindOptions struct {
	Ids          []string
	Query        string
	Enabled      *bool
	CreateUserId *string
	UpdateUserId *string
}

type Hook

type Hook struct {
	Command     string
	RunOnCreate bool
	RunOnUpdate bool
	RunOnDelete bool
	RunOnStart  bool
	RunOnStop   bool
}

func (*Hook) ShouldExecute

func (h *Hook) ShouldExecute(action HookAction) bool

type HookAction

type HookAction string
var (
	HookActionCreate HookAction = "CREATE"
	HookActionUpdate HookAction = "UPDATE"
	HookActionDelete HookAction = "DELETE"
	HookActionStart  HookAction = "START"
	HookActionStop   HookAction = "STOP"
)

type IdOption

type IdOption struct {
	Id string
}

func (*IdOption) Validate

func (option *IdOption) Validate() error

type NameOption

type NameOption struct {
	Name string
}

func (*NameOption) Validate

func (option *NameOption) Validate() error

type Repository

type Repository interface {
	FindOne(ctx context.Context, options *FindOneOptions) (*Server, error)
	FindAll(ctx context.Context, options *FindOptions) ([]*Server, error)
	Create(ctx context.Context, server *Server) (*Server, error)
	Update(ctx context.Context, server *Server, fieldMask *UpdateFieldMask) (*Server, error)
	Delete(ctx context.Context, serverId string, deleteUserId string) (*Server, error)
}

type Server

type Server struct {
	Id           string
	Name         string
	Description  string
	Enabled      bool
	Running      bool
	PublicKey    string
	PrivateKey   string
	ListenPort   *int
	FirewallMark *int
	Address      string
	DNS          []string
	MTU          int
	Hooks        []*Hook
	CreateUserId string
	UpdateUserId string
	DeleteUserId string
	CreatedAt    time.Time
	UpdatedAt    time.Time
	DeletedAt    *time.Time
}

func (*Server) RunHooks

func (s *Server) RunHooks(action HookAction) error

type Service

type Service interface {
	FindServer(ctx context.Context, options *FindOneOptions) (*Server, error)
	FindServers(ctx context.Context, options *FindOptions) ([]*Server, error)
	CreateServer(ctx context.Context, options *CreateOptions, userId string) (*Server, error)
	UpdateServer(ctx context.Context, serverId string, options *UpdateOptions, fieldMask *UpdateFieldMask, userId string) (*Server, error)
	DeleteServer(ctx context.Context, serverId string, userId string) (*Server, error)
}

func NewService

func NewService(serverRepository Repository) Service

type UpdateFieldMask

type UpdateFieldMask struct {
	Description  bool
	Enabled      bool
	Running      bool
	PublicKey    bool
	PrivateKey   bool
	ListenPort   bool
	FirewallMark bool
	Address      bool
	DNS          bool
	MTU          bool
	UpdateUserId bool
	Hooks        bool
}

type UpdateOptions

type UpdateOptions struct {
	Description  string
	Enabled      bool
	Running      bool
	PublicKey    string
	PrivateKey   string
	ListenPort   *int
	FirewallMark *int
	Address      string
	DNS          []string
	MTU          int
	Hooks        []*Hook
}

Jump to

Keyboard shortcuts

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