MCPcopy Index your code
hub / github.com/coder/coder / parseVariableValuesFromJSON

Function parseVariableValuesFromJSON

codersdk/templatevariables.go:160–182  ·  view source on GitHub ↗

parseVariableValuesFromJSON converts the .tfvars.json content into template variables. The function visits only root-level properties as template variables do not support nested structures.

(content []byte)

Source from the content-addressed store, hash-verified

158// The function visits only root-level properties as template variables do not support nested
159// structures.
160func parseVariableValuesFromJSON(content []byte) ([]VariableValue, error) {
161 var data map[string]interface{}
162 err := json.Unmarshal(content, &data)
163 if err != nil {
164 return nil, err
165 }
166
167 stringData := map[string]string{}
168 for key, value := range data {
169 switch value.(type) {
170 case string, int, bool:
171 stringData[key] = fmt.Sprintf("%v", value)
172 default:
173 m, err := json.Marshal(value)
174 if err != nil {
175 return nil, err
176 }
177 stringData[key] = string(m)
178 }
179 }
180
181 return convertMapIntoVariableValues(stringData), nil
182}
183
184func convertMapIntoVariableValues(m map[string]string) []VariableValue {
185 var parsed []VariableValue

Callers 1

Calls 3

UnmarshalMethod · 0.45
MarshalMethod · 0.45

Tested by

no test coverage detected