Skip to content

Go

Send Message via REST API

go
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
)

func main() {
    data := map[string]string{
        "dock_id": "<Dock ID>",
        "secret_key": "<Secret Key>",
        "msg": "Hello from Go!",
    }

    body, _ := json.Marshal(data)
    resp, err := http.Post("https://api.pingdock.io/ping", "application/json", bytes.NewBuffer(body))
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()
    fmt.Println(resp.Status)
}

Send Message via Webhook

go
package main

import (
    "bytes"
    "encoding/json"
    "net/http"
)

func main() {
    data := map[string]string{"msg": "Webhook from Go!"}
    body, _ := json.Marshal(data)

    req, _ := http.NewRequest("POST", "https://api.pingdock.io/webhook", bytes.NewBuffer(body))
    req.SetBasicAuth("<Dock ID>", "<Secret Key>")
    req.Header.Set("Content-Type", "application/json")

    http.DefaultClient.Do(req)
}