Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( Version string // `git describe --tags` Author string // zhengxiaoyao0716 Homepage string // https://zhengxiaoyao0716.github.io/zmodule Repository string // https://github.com/zhengxiaoyao0716/zmodule License string // https://github.com/zhengxiaoyao0716/zmodule/blob/master/LICENSE Built string // `date +%FT%T%z` GitCommit string // `git rev-parse --short HEAD` GoVersion string // `go version` )
Those values should be assigned during compile statement. ``` bash m=github.com/zhengxiaoyao0716/zmodule v=`git describe --tags` b=`date +%FT%T%z` go run -ldflags "-X $m.Version=$v -X $m.Built=$b ..." zexample.go version ``` But some of them may not need to changed frequently. So you can also set them in your code directly.
View Source
var Args = map[string]Argument{
"config": {"", "Config json file path."},
"work_dir": {"", "Directory to find or storage files."},
"log": {"", "Path to storage logger files."},
}
Args . You can add your custom args directly, and then they would be parsed into config. Please don't change both the name and the type of the args reserved below.
View Source
var Cmds = map[string]Command{ "": { "Quick run with last args.", func(parsed string, args []string) { if !config.HasSavedCfg() { parseFlag(args) } if err := srv.Run(); err != nil { if !service.Interactive() { file, err := os.OpenFile(filepath.Join(info.WorkDir(), "error.log"), os.O_APPEND|os.O_CREATE, 0666) if err != nil { } defer file.Close() log.SetOutput(file) } log.Fatalln(err) } }, }, "run": { "Run.", func(parsed string, args []string) { parseFlag(args) if err := srv.Run(); err != nil { log.Fatalln(err) } }, }, "version": { "Show the version.", func(string, []string) { console.Log(info.Version()) }, }, "info": { "Show the info.", func(string, []string) { console.Log(info.Info()) }, }, "service": { "Control the system service.", func() func(string, []string) { var handler func(string, []string) handler = func(parsed string, args []string) { control := func(arg string) { err := service.Control(srv, arg) if err != nil { log.Fatal(err) } } cmdHandler := ParseCmd(map[string]Command{ "": { "Quick start with last args.", func(parsed string, args []string) { if !config.HasSavedCfg() { parseFlag(args) } control("start") }, }, "start": { "Start the service.", func(parsed string, args []string) { parseFlag(args) control("start") }, }, "stop": { "Stop the service.", func(string, []string) { control("stop") }, }, "restart": { "Restart the service.", func(string, []string) { control("restart") }, }, "install": { "Install the service.", func(string, []string) { control("install") }, }, "uninstall": { "Uninstall the service.", func(string, []string) { control("uninstall") }, }, }) handler = func(parsed string, args []string) { if len(args) == 0 { args = []string{""} } cmdHandler(parsed, args) } handler(parsed, args) } return handler }(), }, }
Cmds .
Functions ¶
Types ¶
Click to show internal directories.
Click to hide internal directories.