MCPcopy Index your code
hub / github.com/cloudfoundry/cli / UnmarshalYAML

Method UnmarshalYAML

util/manifestparser/process.go:35–69  ·  view source on GitHub ↗
(unmarshal func(v interface{}) error)

Source from the content-addressed store, hash-verified

33}
34
35func (process *Process) UnmarshalYAML(unmarshal func(v interface{}) error) error {
36 // This prevents infinite recursion. The Alias type does not implement the unmarshaller interface
37 // so by casting application to a alias pointer, it will unmarshal into the same memory without calling
38 // UnmarshalYAML on itself infinite times
39 type Alias Process
40 aliasPntr := (*Alias)(process)
41
42 err := unmarshal(aliasPntr)
43 if err != nil {
44 return err
45 }
46
47 err = unmarshal(&process.RemainingManifestFields)
48 if err != nil {
49 return err
50 }
51
52 value := reflect.ValueOf(*process)
53 removeDuplicateMapKeys(value, process.RemainingManifestFields)
54 // old style was `disk_quota` (underscore not hyphen)
55 // we maintain backwards-compatibility by supporting both flavors
56 if process.RemainingManifestFields["disk-quota"] != nil {
57 if process.DiskQuota != "" {
58 return errors.New("cannot define both `disk_quota` and `disk-quota`")
59 }
60 diskQuota, ok := process.RemainingManifestFields["disk-quota"].(string)
61 if !ok {
62 return errors.New("`disk-quota` must be a string")
63 }
64 process.DiskQuota = diskQuota
65 delete(process.RemainingManifestFields, "disk-quota")
66 }
67
68 return nil
69}
70
71func removeDuplicateMapKeys(model reflect.Value, fieldMap map[string]interface{}) {
72 for i := 0; i < model.NumField(); i++ {

Callers

nothing calls this directly

Calls 1

removeDuplicateMapKeysFunction · 0.85

Tested by

no test coverage detected