Skip to content

Instantly share code, notes, and snippets.

@guesslin
Created November 12, 2016 09:04
Show Gist options
  • Save guesslin/3c5691262b70e6d8e0ae3cefa50d694d to your computer and use it in GitHub Desktop.
Save guesslin/3c5691262b70e6d8e0ae3cefa50d694d to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"reflect"
)
type Docs struct {
Github string
Linkedin string
Google string
Facebook string
}
func main() {
whatever := Docs{
Github: "https://github.com/whatever",
Linkedin: "https://linkednin.com/whatever",
Google: "https://plus.google.com/+whatever",
Facebook: "https://facebook.com/whatever+Ever",
}
modifier := Docs{
Github: "+goesGithub",
Linkedin: "+goesLinkedin",
Google: "+goesGoogle",
Facebook: "+goesFacebook",
}
fmt.Println(whatever)
fmt.Println(modifier)
fmt.Printf("%##v\n", whatever)
v := reflect.ValueOf(whatever)
for i := 0; i < v.NumField(); i++ {
fmt.Println(v.Type().Field(i).Name, v.Field(i).String())
tmp := v.Field(i).String() + reflect.ValueOf(&modifier).Elem().FieldByName(v.Type().Field(i).Name).String()
reflect.ValueOf(&whatever).Elem().FieldByName(v.Type().Field(i).Name).SetString(tmp)
}
fmt.Println(whatever)
fmt.Printf("%##v\n", whatever)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment