Source File
args.go
Belonging Package
/examples/cli_daemon/types
package typesimport (amhelpam)func init() {gob.Register(&ARpc{})}// ///// ///// /////// ///// ARGS// ///// ///// /////// TODO add RPC args example from pkg/nodeconst APrefix = "daemon"// A is a struct for node arguments. It's a typesafe alternative to [am.A].type A struct {Duration time.Duration `log:"duration"`}// ARpc is a subset of A, that can be passed over RPC.type ARpc struct {Duration time.Duration `log:"duration"`}// ParseArgs extracts A from [am.Event.Args][APrefix].func ( am.A) *A {if , := [APrefix].(*ARpc); {return amhelp.ArgsToArgs(, &A{})} else if , := [APrefix].(ARpc); {return amhelp.ArgsToArgs(&, &A{})}if , := [APrefix].(*A); != nil {return}return &A{}}// Pass prepares [am.A] from A to pass to further mutations.func ( *A) am.A {return am.A{APrefix: }}// PassRpc prepares [am.A] from A to pass over RPC.func ( *ARpc) am.A {return am.A{APrefix: amhelp.ArgsToArgs(, &ARpc{})}}// LogArgs is an args logger for A.func ( am.A) map[string]string {:= ParseArgs()if == nil {return nil}return amhelp.ArgsToLogMap(, 0)}// ParseRpc parses am.A to *ARpc wrapped in am.A. Useful for REPLs.func ( am.A) am.A {:= am.A{APrefix: &ARpc{}}, := json.Marshal()if == nil {json.Unmarshal(, [APrefix])}return}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |