forked from drone-plugins/drone-webhook
/
main.go
45 lines (38 loc) · 805 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"bytes"
"encoding/json"
"net/http"
"os"
"github.com/drone/drone-go/plugin"
"github.com/drone/drone-go/drone"
)
func main() {
var repo = drone.Repo{}
var build = drone.Build{}
var vargs = struct {
Urls []string `json:"urls"`
}{}
plugin.Param("repo", &repo)
plugin.Param("build", &build)
plugin.Param("vargs", &vargs)
plugin.Parse()
// data structure
data := struct {
Repo drone.Repo `json:"repo"`
Build drone.Build `json:"build"`
}{repo, build}
// json payload that will be posted
payload, err := json.Marshal(&data)
if err != nil {
os.Exit(1)
}
// post payload to each url
for _, url := range vargs.Urls {
resp, err := http.Post(url, "application/json", bytes.NewBuffer(payload))
if err != nil {
os.Exit(1)
}
resp.Body.Close()
}
}