...
1 package examples
2
3 import (
4 "encoding/json"
5 "fmt"
6 )
7
8 func GetBytes() []byte {
9 byteValue := []byte(`{
10 "[json]": {
11 "editor.defaultFormatter": "vscode.json-language-features",
12 "editor.formatOnSave": true
13 },
14 "[starlark]": {
15 "editor.formatOnSave": true,
16 "editor.tabSize": 4
17 },
18 "bazel.buildifierFixOnFormat": true,
19 "editor.rulers": [
20 80,
21 120
22 ],
23 "files.watcherExclude": {
24 "**/.git/objects/**": true,
25 "**/.git/subtree-cache/**": true,
26 "**/bazel-bin/*/**": true,
27 "**/bazel-out/*/**": true,
28 "**/bazel-testlogs/*/**": true,
29 "**/node_modules/*/**": true
30 },
31 "go.lintOnSave": "package",
32 "go.lintTool": "golangci-lint",
33 "go.useLanguageServer": true
34 }`)
35
36 return byteValue
37 }
38
39 func BytesToStruct() (map[string]interface{}, error) {
40 var result map[string]interface{}
41 byteValue := GetBytes()
42
43 if err := json.Unmarshal(byteValue, &result); err != nil {
44 return nil, fmt.Errorf("failed to unmarshal json: %w", err)
45 }
46
47 return result, nil
48 }
49
View as plain text