command

package
v0.0.0-...-dd73c42 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActionString

func ActionString(action Action) string

ActionString converts an action value into its string representation

func GenServiceMethod

func GenServiceMethod(action Action, target Target) string

GenServiceMethod converts a pair of target and action codes into a "Target.Action" string

func ParseServiceMethod

func ParseServiceMethod(sm string) (Action, Target)

ParseServiceMethod converts a "Target.Action" string into a pair of target and action codes

func TargetString

func TargetString(target Target) string

TargetString converts an target value into its string representation

Types

type Action

type Action int

Action is what the gourd client is requesting to be done

const (
	// NOACTION is a request with no action
	NOACTION Action = iota
	// PING is a request to recieve a PONG response
	PING
	// ECHO is a request to have text echoed back
	ECHO
	// INSTALL is a request to download software from the internet
	INSTALL
)

func ActionCode

func ActionCode(action string) Action

ActionCode converts an action string into its code representation

type Command

type Command struct {
	Header
	Body interface{} `json:"body"`
}

Command is a data structure that represents a command issued by a gourd client

func NewCommand

func NewCommand(action Action, target Target, body interface{}) Command

NewCommand creates a new command

func NewHostEcho

func NewHostEcho(msg string) Command

NewHostEcho creates a new echo command for the local gourdd

func NewHostInstall

func NewHostInstall(item string) Command

NewHostInstall creates a new install command for the local gourdd

func NewHostPing

func NewHostPing() Command

NewHostPing creates a new ping command for the local gourdd

func (*Command) Clear

func (c *Command) Clear()

Clear sets all of the command fields to empty values

func (*Command) Set

func (c *Command) Set(action Action, target Target, body interface{})

Set updates the data for a command

func (*Command) SetFromRequest

func (c *Command) SetFromRequest(r Request)

SetFromRequest updates the command data using a request

func (*Command) String

func (c *Command) String() string

type EchoRequest

type EchoRequest struct {
	Action  Action `json:"action"`
	Target  Target `json:"target"`
	Message string `json:"message"`
}

EchoRequest is what a clients use to issue new echo commands

func (*EchoRequest) GetAction

func (r *EchoRequest) GetAction() Action

func (*EchoRequest) GetParams

func (r *EchoRequest) GetParams() interface{}

func (*EchoRequest) GetTarget

func (r *EchoRequest) GetTarget() Target

type EchoResponse

type EchoResponse struct {
	ID      string `json:"id"`
	Error   string `json:"error"`
	Message string `json:"message"`
}

EchoResponse is what a client will recieve after issuing an echo command

func (*EchoResponse) GetData

func (r *EchoResponse) GetData() interface{}

func (*EchoResponse) GetError

func (r *EchoResponse) GetError() string

func (*EchoResponse) GetId

func (r *EchoResponse) GetId() string
type Header struct {
	ID        string `json:"id"`
	Timestamp int64  `json:"timestamp"`
	Action    Action `json:"action"`
	Target    Target `json:"target"`
}

Header contains all of the metadata for a command

type InstallRequest

type InstallRequest struct {
	Action Action `json:"action"`
	Target Target `json:"target"`
	Item   string `json:"item"`
	User   string `json:"user"`
}

InstallRequest is what a clients use to issue new install commands

func (*InstallRequest) GetAction

func (r *InstallRequest) GetAction() Action

func (*InstallRequest) GetParams

func (r *InstallRequest) GetParams() interface{}

func (*InstallRequest) GetTarget

func (r *InstallRequest) GetTarget() Target

type InstallRequestParams

type InstallRequestParams struct {
	Item string `json:"item"`
	User string `json:"user"`
}

InstallRequestParams identify what to install and who to install it for

func (*InstallRequestParams) Read

func (p *InstallRequestParams) Read() (string, string)

type InstallResponse

type InstallResponse struct {
	ID      string `json:"id"`
	Error   string `json:"error"`
	Message string `json:"message"`
}

InstallResponse is what a client will recieve after issuing a install command

func (*InstallResponse) GetData

func (r *InstallResponse) GetData() interface{}

func (*InstallResponse) GetError

func (r *InstallResponse) GetError() string

func (*InstallResponse) GetId

func (r *InstallResponse) GetId() string

type PingRequest

type PingRequest struct {
	Action Action `json:"action"`
	Target Target `json:"target"`
}

PingRequest is what a clients use to issue new ping commands

func (*PingRequest) GetAction

func (r *PingRequest) GetAction() Action

func (*PingRequest) GetParams

func (r *PingRequest) GetParams() interface{}

func (*PingRequest) GetTarget

func (r *PingRequest) GetTarget() Target

type PingResponse

type PingResponse struct {
	ID      string `json:"id"`
	Error   string `json:"error"`
	Message string `json:"message"`
}

PingResponse is what a client will recieve after issuing a ping command

func (*PingResponse) GetData

func (r *PingResponse) GetData() interface{}

func (*PingResponse) GetError

func (r *PingResponse) GetError() string

func (*PingResponse) GetId

func (r *PingResponse) GetId() string

type Request

type Request interface {
	GetAction() Action
	GetTarget() Target
	GetParams() interface{}
}

Request is what a clients use to issue new commands

func NewRequest

func NewRequest(action Action, target Target, params interface{}) Request

NewRequest creates a new command request

type Response

type Response interface {
	GetId() string
	GetError() string
	GetData() interface{}
}

Response is what a server will send back to a client after a command

func NewResponse

func NewResponse(cmd *Command, err string) Response

NewResponse creates a new command response

type Target

type Target int

Target is what should be affected the action of a command

const (
	// NOTARGET means no target
	NOTARGET Target = iota
	// HOST is a target that represents the local gourdd
	HOST
)

func TargetCode

func TargetCode(target string) Target

TargetCode converts an target string into its code representation

Jump to

Keyboard shortcuts

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