github.com/benma/gogen@v0.0.0-20160826115606-cf49914b915a/unmarshalmap/testpkg/composed_unmarshalmap.go (about)

     1  /*
     2  * CODE GENERATED AUTOMATICALLY WITH github.com/ernesto-jimenez/gogen/unmarshalmap
     3  * THIS FILE SHOULD NOT BE EDITED BY HAND
     4   */
     5  
     6  package testpkg
     7  
     8  import (
     9  	"fmt"
    10  )
    11  
    12  // UnmarshalMap takes a map and unmarshals the fieds into the struct
    13  func (s *Composed) UnmarshalMap(m map[string]interface{}) error {
    14  
    15  	// Anonymous Embedded
    16  	if scoped := true; scoped {
    17  		var s *Embedded = &s.Embedded
    18  		// Fill object
    19  
    20  		if v, ok := m["Field"].(string); ok {
    21  			s.Field = v
    22  
    23  		} else if v, exists := m["Field"]; exists && v != nil {
    24  			return fmt.Errorf("expected field Field to be string but got %T", m["Field"])
    25  		}
    26  
    27  	}
    28  
    29  	if v, ok := m["Base"].(string); ok {
    30  		s.Base = v
    31  
    32  	} else if v, exists := m["Base"]; exists && v != nil {
    33  		return fmt.Errorf("expected field Base to be string but got %T", m["Base"])
    34  	}
    35  
    36  	return nil
    37  }