go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/logdog/client/bootstrapResult/result.go (about) 1 // Copyright 2015 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package bootstrapResult defines a common way to express the result of 16 // bootstrapping a command via JSON. 17 package bootstrapResult 18 19 import ( 20 "encoding/json" 21 "os" 22 ) 23 24 // Result is the bootstrap result data. 25 type Result struct { 26 // ReturnCode is the process' return code. 27 ReturnCode int `json:"return_code"` 28 // Command, is present, is the bootstrapped command that was run. 29 Command []string `json:"command,omitempty"` 30 } 31 32 // WriteJSON writes Result as a JSON document to the specified path. 33 func (r *Result) WriteJSON(path string) error { 34 fd, err := os.Create(path) 35 if err != nil { 36 return err 37 } 38 defer fd.Close() 39 return json.NewEncoder(fd).Encode(r) 40 }