MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / outputJSONGo

Function outputJSONGo

tools/mage/go.go:79–95  ·  view source on GitHub ↗
(cmd string, args ...string)

Source from the content-addressed store, hash-verified

77}
78
79func outputJSONGo(cmd string, args ...string) ([]byte, error) {
80 var buf bytes.Buffer
81 if err := execGo(&buf, os.Stderr, cmd, args...); err != nil {
82 return nil, err
83 }
84 raw := buf.String()
85 jsonStartIdx := strings.Index(raw, "{")
86 if jsonStartIdx == -1 {
87 return nil, fmt.Errorf("No JSON found in output")
88 }
89 start := raw[jsonStartIdx:]
90 jsonEndIdx := strings.Index(start, "}")
91 if jsonEndIdx == -1 {
92 return nil, fmt.Errorf("No JSON found in output")
93 }
94 return []byte(start[:jsonEndIdx+1]), nil
95}
96
97func runGoTool(args ...string) error {
98 return runGoFrom("tools", append([]string{"-exec", "go run exec_from.go -dir .."}, args...)...)

Callers 1

InitStackMethod · 0.85

Calls 3

execGoFunction · 0.85
StringMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected