Created
July 28, 2014 07:25
-
-
Save hayajo/5c591141680ec3380e41 to your computer and use it in GitHub Desktop.
golangのflagで値をスライスであつかう
This file contains 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" | |
"log" | |
) | |
type items []string | |
func (i *items) String() string { | |
return fmt.Sprint("%v", *i) | |
} | |
func (i *items) Set(v string) error { | |
*i = append(*i, v) | |
return nil | |
} | |
func main() { | |
var i items | |
flag.Var(&i, "item", "") | |
flag.Parse() | |
log.Println(i) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
flag.Var の Set() で実装する