ExecTag stands for the path of executable file in command. If we want this util works , we must add Exec in the struct and use NewExec() to initialize it, because the default way to initialize Exec means None in code.
const ExecTag = "exec"
ParaTag stands for parameters in command. We can use it in struct fields as a tag. Just like Port below
type Iptables Struct { Exec Port string `para:"-p"` }
If the field is not string type or []string type , it will bring an error. If the tag value like "-p" is empty string , the para will just add the field value into the command just as some single value parameter in command. If the value of field is empty string or empty string slice or empty slice, the field and tag will all be skipped.
const ParaTag = "para"
SubCommandTag stands for the sub command in common command. We can use it in struct fields as a tag. Just like MatchExtension below
type Iptables Struct { Exec MatchExtension Match `sub_command:""` } type Match Struct { Exec Port string `para:"-p"` }
Field with SubcommandTag needs to be a struct with Exec.
const SubCommandTag = "sub_command"
func Marshal(i interface{}) (string, []string, error)
func SearchKey(value reflect.Value) (string, bool)
func ToCommand(i interface{}) (*exec.Cmd, error)
Exec is the interface of a command. We need to inherit it in the struct of command. User must add ExecTag as the tag of Exec field. Example:
type Iptables struct { Exec `exec:"iptables"` Tables string `para:"-t"` }
type Exec struct {
// contains filtered or unexported fields
}
func NewExec() Exec