Created
July 9, 2014 10:20
-
-
Save titimoby/75be04baf56324927672 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"encoding/json" | |
"log" | |
"io/ioutil" | |
"net/http" | |
) | |
// play with http://mholt.github.io/json-to-go/ | |
// this helped a lot | |
type BuildInfo struct { | |
Id string `json:"id"` | |
Number int `json:"number"` | |
Result string `json:"result"` | |
Timestamp int64 `json:"timestamp"` | |
Culprits []struct { | |
AbsoluteUrl string `json:"absoluteUrl"` | |
FullName string `json:"fullName"` | |
} `json:"culprits"` | |
} | |
type BuildType struct { | |
Builds []BuildInfo `json:"builds"` | |
} | |
func main() { | |
var username string = "YOUR USER" | |
var passwd string = "YOUR PASSWORD" | |
client := &http.Client{} | |
req, err := http.NewRequest("GET", "http://YOUR_SERVER/job/YOUR_JOB/api/json?pretty=true&tree=builds[number,result,timestamp,id,jsonMap,culprits[fullName,absoluteUrl]]", nil) | |
req.SetBasicAuth(username, passwd) | |
resp, err := client.Do(req) | |
if err != nil{ | |
log.Fatal(err) | |
} | |
defer resp.Body.Close() | |
body, err := ioutil.ReadAll(resp.Body) | |
var builds BuildType | |
json.Unmarshal(body, &builds) | |
fmt.Printf("builds : %v\n", builds) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment