Created
November 28, 2020 15:16
-
-
Save nna774/c2839eca89512918496643c2f615e63d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"strconv" | |
) | |
type myVar struct { | |
V int64 | |
SET bool // setされた もsetなのむずかしい。 | |
} | |
func (m *myVar) String() string { | |
return "piyopoyo" | |
} | |
func (m *myVar) Set(s string) error { | |
m.SET = true | |
v, err := strconv.ParseInt(s, 0, strconv.IntSize) | |
if err != nil { | |
return err | |
} | |
m.V = v | |
return nil | |
} | |
func main() { | |
mv := myVar{} | |
flag.Var(&mv, "a", "piyo") | |
flag.Parse() | |
fmt.Printf("set? %v\n", mv.SET) | |
fmt.Printf("%v\n", mv.V) | |
} |
Author
nna774
commented
Nov 28, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment