Guest User

Untitled

a guest
Nov 20th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. type Config struct {
  2. path: string
  3. id: string
  4. key: string
  5. addr: string
  6. size: uint64
  7. }
  8.  
  9. func merge(default *Config, file *Config) (*Config) {
  10. b := reflect.ValueOf(default)
  11. o := reflect.ValueOf(file)
  12.  
  13. for i := 0; i < b.NumField(); i++ {
  14. defaultField := b.Field(i)
  15. fileField := o.Field(i)
  16. if defaultField.Interface() != reflect.Zero(fileField.Type()).Interface() {
  17. defaultField.Set(reflect.ValueOf(fileField))
  18. }
  19. }
  20.  
  21. return default
  22. }
Add Comment
Please, Sign In to add comment