Documentation
¶
Index ¶
- Constants
- func GetSockFilePath(sockName string) (p string)
- func ParseOptionsProperties(valType reflect.Type, k *KCommand)
- func ParseShellOptions(o KtrlOpt, k *KCommand) (KtrlOpt, *ParserPlus)
- func SetStructValue(field reflect.Value, fValue string, found bool)
- func ShowHelpStr(o KtrlOpt) (help string)
- type Context
- type ContextType
- type KCommand
- type Ktrl
- type KtrlClient
- type KtrlOpt
- type KtrlServer
- type KtrlShell
- type KtrlTable
- type Options
- type ParserPlus
- type UnixSocket
Constants ¶
View Source
const ( ContextClient ContextType = 1 // 客户端 ContextServer ContextType = 2 // 服务端 ArgsFormatStr string = "args%sargs" )
View Source
const ( Alias = "alias" NeedParse = "needparse" Required = "required" Description = "descr" )
View Source
const ( HeadersInJson = "headers" RowsInJson = "rows" )
View Source
const (
GoKtrlSockDirEnv string = "GOKTRL_SOCK_DIR"
)
View Source
const (
TableFieldOrderFlag = "order"
)
Variables ¶
This section is empty.
Functions ¶
func GetSockFilePath ¶ added in v1.3.7
func ParseOptionsProperties ¶
func ParseShellOptions ¶
func ParseShellOptions(o KtrlOpt, k *KCommand) (KtrlOpt, *ParserPlus)
func ShowHelpStr ¶
Types ¶
type Context ¶
type Context struct {
*gin.Context
ShellContext *ishell.Context
Type ContextType
Options KtrlOpt
Args []string
Parser *ParserPlus
Table *KtrlTable
KtrlPath string
Client *KtrlClient
DefaultSocket string
ShellCmdName string
Result []byte
}
type ContextType ¶
type ContextType int
type KCommand ¶
type KCommand struct {
Name string // shell 命令名称
Help string // shell 命令解释
Func func(c *Context) // shell 命令钩子函数
Opts KtrlOpt // shell 命令可选参数配置
KtrlHandler func(c *Context) // Ktrl服务端视图函数
SocketName string // 默认Unix套接字名称
ArgsDescription string // 位置参数说明
ArgsRequired bool // 位置参数是否至少要传一个
Auto bool // 是否自动发送请求并处理结果
TableObject interface{} // 空的表格对象
ShowTable bool // 结果是否在命令行中以表格显示
ArgsHook func([]string) []string // 在shell中处理Args, 然后向Server发送处理之后的Args
// contains filtered or unexported fields
}
func (*KCommand) GetKtrlPath ¶
type Ktrl ¶
type Ktrl struct {
CtrlServer *KtrlServer // 服务端
CtrlShell *KtrlShell // 客户端交互式shell
Multiple bool // 是否客户端和服务端在不同进程中执行
}
func (*Ktrl) AddKtrlCommand ¶
type KtrlClient ¶
type KtrlClient struct {
UnixSocket
Client *http.Client
// contains filtered or unexported fields
}
func NewKtrlClient ¶
func NewKtrlClient() *KtrlClient
func (*KtrlClient) ParseParams ¶
func (that *KtrlClient) ParseParams(params map[string]string)
func (*KtrlClient) SetUnixSocket ¶
func (that *KtrlClient) SetUnixSocket(sockName string)
type KtrlServer ¶
type KtrlServer struct {
UnixSocket
Router *gin.Engine // UnixSockHttp 服务端
}
func NewKtrlServer ¶
func NewKtrlServer() *KtrlServer
func (*KtrlServer) AddHandler ¶
func (that *KtrlServer) AddHandler(kcmd *KCommand)
AddHandler 为KtrlServer添加视图函数
func (*KtrlServer) CheckUnixSocket ¶
func (that *KtrlServer) CheckUnixSocket()
func (*KtrlServer) SetUnixSocket ¶
func (that *KtrlServer) SetUnixSocket(sockName string)
func (*KtrlServer) Start ¶
func (that *KtrlServer) Start(sockName ...string) error
type KtrlTable ¶
func NewKtrlTable ¶
func NewKtrlTable() *KtrlTable
func (*KtrlTable) AddRowsByJsonString ¶
AddRowsByJsonString 为表格添加数据行; jsonString 格式: {headers: ["", "", ""], rows: [["", "", ""], ["", "", ""], ["", "", ""]]}
func (*KtrlTable) AddRowsByListObject ¶
func (that *KtrlTable) AddRowsByListObject(dataList interface{})
AddRowsByListObject 为表格添加数据行;
dataList 数据类型格式: []Data 或 []*Data;
Data为struct, 结构示例如下:
type Data struct {
FieldOne string `order:"1"`
FieldTwo string `order:"2"`
}
func (*KtrlTable) ParseHeadersFromObject ¶
func (*KtrlTable) ParseHeadersFromString ¶
type Options ¶
type Options struct {
OptList g.MapStrBool // 是否解析参数的值
Required g.MapStrBool // 是否必传
}
type UnixSocket ¶
Unix套接字
Source Files
¶
Click to show internal directories.
Click to hide internal directories.
