Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package main
import (
"encoding/json"
"flag"
"fmt"
)
type Profile struct {
Name string
Age uint
Verified bool
}
// new added
func (this *Profile) String() string {
b, _ := json.Marshal(*this)
return string(b)
}
// new added
func (this *Profile) Set(s string) error {
return json.Unmarshal([]byte(s), this)
}
func main() {
var version string
var profile Profile
flag.StringVar(&version, "setVersion", "1.0.0", "")
flag.Var(&profile, "setProfile", "")
flag.Parse()
fmt.Println("version = ", version)
fmt.Println("profile = ", profile)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment