Skip to content

Instantly share code, notes, and snippets.

@hayajo
Created July 28, 2014 07:25
Show Gist options
  • Save hayajo/5c591141680ec3380e41 to your computer and use it in GitHub Desktop.
Save hayajo/5c591141680ec3380e41 to your computer and use it in GitHub Desktop.
golangのflagで値をスライスであつかう
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)
}
@hayajo
Copy link
Author

hayajo commented Jul 28, 2014

flag.Var の Set() で実装する

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment