IdentifyFormat does best effort to identify the format of the raw contract by going the unmarshalling path in the following order: json, yaml. NOTE that we are just validating the format, not the content using regular marshalling not even proto marshalling, that comes later once we know the format.
(raw []byte)
| 110 | // not even proto marshalling, that comes later once we know the format. |
| 111 | // CUE is intentionally not detected: it is no longer a supported contract format. |
| 112 | func IdentifyFormat(raw []byte) (RawFormat, error) { |
| 113 | // json marshalling first |
| 114 | var sink any |
| 115 | if err := json.Unmarshal(raw, &sink); err == nil { |
| 116 | return RawFormatJSON, nil |
| 117 | } |
| 118 | |
| 119 | // yaml marshalling last |
| 120 | if err := yaml.Unmarshal(raw, &sink); err == nil { |
| 121 | return RawFormatYAML, nil |
| 122 | } |
| 123 | |
| 124 | return "", errors.New("format not found") |
| 125 | } |
| 126 | |
| 127 | // LoadJSONBytes Extracts raw data in JSON format from different sources, i.e yaml or json files |
| 128 | func LoadJSONBytes(rawData []byte, extension string) ([]byte, error) { |
no outgoing calls