ktrl

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2024 License: MIT Imports: 16 Imported by: 3

Documentation

Index

Constants

View Source
const (
	OptionTypeString  FlagType = "string"
	OptionTypeBool    FlagType = "bool"
	OptionTypeInt     FlagType = "int"
	OptionTypeFloat   FlagType = "float"
	ContextTypeClient int8     = 1
	ContextTypeServer int8     = 2
	QueryArgsName     string   = "queryArgs"
)
View Source
const (
	PingRoute    string = "/ping/"
	PingResponse string = "pong"
)
View Source
const (
	SockName string = "ktrl_ishell.sock"
)

Variables

This section is empty.

Functions

func FormatRoute

func FormatRoute(name, parent string) string

Types

type FlagType

type FlagType string

type Ktrl

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

func NewKtrl

func NewKtrl(cfg *KtrlConf) (k *Ktrl)

func (*Ktrl) AddCommand

func (k *Ktrl) AddCommand(kcmd *KtrlCommand)

func (*Ktrl) GetResult

func (k *Ktrl) GetResult(ctx *KtrlContext)

func (*Ktrl) GetShell

func (k *Ktrl) GetShell() (sh *shell.IShell)

func (*Ktrl) PreServerStart

func (k *Ktrl) PreServerStart()

func (*Ktrl) PreShellStart

func (k *Ktrl) PreShellStart()

func (*Ktrl) SendMsg

func (k *Ktrl) SendMsg(name, parent string, options []*shell.Flag, args ...string) (r []byte)

Send msg to server manually.

func (k *Ktrl) SetPrintLogo(f func(_ *console.Console))

func (*Ktrl) StartServer

func (k *Ktrl) StartServer()

func (*Ktrl) StartShell

func (k *Ktrl) StartShell() error

type KtrlCommand

type KtrlCommand struct {
	Name          string                 // cmd name
	Parent        string                 // parent cmd name
	HelpStr       string                 // Short for cobra cmd
	LongHelpStr   string                 // Long for cobra cmd
	Options       []*shell.Flag          // flags for cobra
	SendInRunFunc bool                   // Send request in RunFunc
	RunFunc       func(ctx *KtrlContext) // Not Nil. Hook for cobra.
	Handler       func(ctx *KtrlContext) // Not Nil. Handler for server.
}

func (*KtrlCommand) GetRoute

func (kc *KtrlCommand) GetRoute() string

Route for current cmd.

type KtrlConf

type KtrlConf struct {
	SockDir         string // unix socket file directory
	SockName        string // unix socket file name
	ServerPort      int    // remote server port
	ServerHost      string // remote server host
	HistoryFilePath string // gshell history file path
	MaxHistoryLines int    // max history lines to store
}

type KtrlContext

type KtrlContext struct {
	GinCtx  *gin.Context
	Command *cobra.Command
	Route   string

	Options []*shell.Flag
	Result  []byte
	Type    int8
	// contains filtered or unexported fields
}

func (*KtrlContext) GetArgs

func (kctx *KtrlContext) GetArgs() []string

parse flags and args for server.

func (*KtrlContext) GetBool

func (kctx *KtrlContext) GetBool(name string) (r bool)

func (*KtrlContext) GetFloat

func (kctx *KtrlContext) GetFloat(name string) (r float64)

func (*KtrlContext) GetInt

func (kctx *KtrlContext) GetInt(name string) (r int)

func (*KtrlContext) GetString

func (kctx *KtrlContext) GetString(name string) (r string)

func (*KtrlContext) SendResponse

func (kctx *KtrlContext) SendResponse(content interface{}, code ...int)

Send reponse back to client.

func (*KtrlContext) SetArgs

func (kctx *KtrlContext) SetArgs(args ...string)

type Option

type Option struct {
	Name    string   // flag name
	Short   string   // flag shorthand
	Type    FlagType // flag type
	Default string   // default value
	Usage   string   // flag help info
}

Cobra Flags

Jump to

Keyboard shortcuts

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