Skip to content

Instantly share code, notes, and snippets.

@mmirolim
Created March 9, 2015 11:16
Show Gist options
  • Select an option

  • Save mmirolim/342553c800fa0c796990 to your computer and use it in GitHub Desktop.

Select an option

Save mmirolim/342553c800fa0c796990 to your computer and use it in GitHub Desktop.
gitlab post issue in Go
func main() {
// private token for authentications
token := "5p94RchB-9pXWRE71Hv2"
ts := Issue{}
ts.PID = "root%2Fhrkb"
ts.Title = "Auto Issue"
ts.Desc = "Description should be added"
ts.Labels = "UI"
// url of gitlab issues
url := "http://office.newmax.uz:7775/api/v3/projects/" + ts.PID + "/issues"
fmt.Println("URL", url)
data, err := json.Marshal(&ts)
if err != nil {
log.Fatal(err)
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(data))
if err != nil {
log.Fatal(err)
}
req.Header.Set("PRIVATE-TOKEN", token)
req.Header.Set("Content-Type", "application/json")
// make request
client := &http.Client{}
res, err := client.Do(req)
if err != nil {
log.Fatal(err)
}
defer res.Body.Close()
fmt.Println("Status", res.Status)
fmt.Println("Headers", res.Header)
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println("Body", string(body))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment