Skip to content

Instantly share code, notes, and snippets.

Created Nov 28, 2020
What would you like to do?
package main
import (
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")
fmt.Printf("set? %v\n", mv.SET)
fmt.Printf("%v\n", mv.V)

This comment has been minimized.

Copy link
Owner Author

@nna774 nna774 commented Nov 28, 2020

$ ./tmp  
set? false
$ ./tmp  -a 42
set? true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment