package pflagimport ()// BytesHex adapts []byte for use as a flag. Value of flag is HEX encodedtype bytesHexValue []byte// String implements pflag.Value.String.func ( bytesHexValue) () string {returnfmt.Sprintf("%X", []byte())}// Set implements pflag.Value.Set.func ( *bytesHexValue) ( string) error { , := hex.DecodeString(strings.TrimSpace())if != nil {return } * = returnnil}// Type implements pflag.Value.Type.func (*bytesHexValue) () string {return"bytesHex"}func newBytesHexValue( []byte, *[]byte) *bytesHexValue { * = return (*bytesHexValue)()}func bytesHexConv( string) (interface{}, error) { , := hex.DecodeString()if == nil {return , nil }returnnil, fmt.Errorf("invalid string being converted to Bytes: %s %s", , )}// GetBytesHex return the []byte value of a flag with the given namefunc ( *FlagSet) ( string) ([]byte, error) { , := .getFlagType(, "bytesHex", bytesHexConv)if != nil {return []byte{}, }return .([]byte), nil}// BytesHexVar defines an []byte flag with specified name, default value, and usage string.// The argument p points to an []byte variable in which to store the value of the flag.func ( *FlagSet) ( *[]byte, string, []byte, string) { .VarP(newBytesHexValue(, ), , "", )}// BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash.func ( *FlagSet) ( *[]byte, , string, []byte, string) { .VarP(newBytesHexValue(, ), , , )}// BytesHexVar defines an []byte flag with specified name, default value, and usage string.// The argument p points to an []byte variable in which to store the value of the flag.func ( *[]byte, string, []byte, string) {CommandLine.VarP(newBytesHexValue(, ), , "", )}// BytesHexVarP is like BytesHexVar, but accepts a shorthand letter that can be used after a single dash.func ( *[]byte, , string, []byte, string) {CommandLine.VarP(newBytesHexValue(, ), , , )}// BytesHex defines an []byte flag with specified name, default value, and usage string.// The return value is the address of an []byte variable that stores the value of the flag.func ( *FlagSet) ( string, []byte, string) *[]byte { := new([]byte) .BytesHexVarP(, , "", , )return}// BytesHexP is like BytesHex, but accepts a shorthand letter that can be used after a single dash.func ( *FlagSet) (, string, []byte, string) *[]byte { := new([]byte) .BytesHexVarP(, , , , )return}// BytesHex defines an []byte flag with specified name, default value, and usage string.// The return value is the address of an []byte variable that stores the value of the flag.func ( string, []byte, string) *[]byte {returnCommandLine.BytesHexP(, "", , )}// BytesHexP is like BytesHex, but accepts a shorthand letter that can be used after a single dash.func (, string, []byte, string) *[]byte {returnCommandLine.BytesHexP(, , , )}// BytesBase64 adapts []byte for use as a flag. Value of flag is Base64 encodedtype bytesBase64Value []byte// String implements pflag.Value.String.func ( bytesBase64Value) () string {returnbase64.StdEncoding.EncodeToString([]byte())}// Set implements pflag.Value.Set.func ( *bytesBase64Value) ( string) error { , := base64.StdEncoding.DecodeString(strings.TrimSpace())if != nil {return } * = returnnil}// Type implements pflag.Value.Type.func (*bytesBase64Value) () string {return"bytesBase64"}func newBytesBase64Value( []byte, *[]byte) *bytesBase64Value { * = return (*bytesBase64Value)()}func bytesBase64ValueConv( string) (interface{}, error) { , := base64.StdEncoding.DecodeString()if == nil {return , nil }returnnil, fmt.Errorf("invalid string being converted to Bytes: %s %s", , )}// GetBytesBase64 return the []byte value of a flag with the given namefunc ( *FlagSet) ( string) ([]byte, error) { , := .getFlagType(, "bytesBase64", bytesBase64ValueConv)if != nil {return []byte{}, }return .([]byte), nil}// BytesBase64Var defines an []byte flag with specified name, default value, and usage string.// The argument p points to an []byte variable in which to store the value of the flag.func ( *FlagSet) ( *[]byte, string, []byte, string) { .VarP(newBytesBase64Value(, ), , "", )}// BytesBase64VarP is like BytesBase64Var, but accepts a shorthand letter that can be used after a single dash.func ( *FlagSet) ( *[]byte, , string, []byte, string) { .VarP(newBytesBase64Value(, ), , , )}// BytesBase64Var defines an []byte flag with specified name, default value, and usage string.// The argument p points to an []byte variable in which to store the value of the flag.func ( *[]byte, string, []byte, string) {CommandLine.VarP(newBytesBase64Value(, ), , "", )}// BytesBase64VarP is like BytesBase64Var, but accepts a shorthand letter that can be used after a single dash.func ( *[]byte, , string, []byte, string) {CommandLine.VarP(newBytesBase64Value(, ), , , )}// BytesBase64 defines an []byte flag with specified name, default value, and usage string.// The return value is the address of an []byte variable that stores the value of the flag.func ( *FlagSet) ( string, []byte, string) *[]byte { := new([]byte) .BytesBase64VarP(, , "", , )return}// BytesBase64P is like BytesBase64, but accepts a shorthand letter that can be used after a single dash.func ( *FlagSet) (, string, []byte, string) *[]byte { := new([]byte) .BytesBase64VarP(, , , , )return}// BytesBase64 defines an []byte flag with specified name, default value, and usage string.// The return value is the address of an []byte variable that stores the value of the flag.func ( string, []byte, string) *[]byte {returnCommandLine.BytesBase64P(, "", , )}// BytesBase64P is like BytesBase64, but accepts a shorthand letter that can be used after a single dash.func (, string, []byte, string) *[]byte {returnCommandLine.BytesBase64P(, , , )}
The pages are generated with Goldsv0.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.