×


Using Go
We don't currently have a custom package available, however you can use our generic api at https://relay.errlog.io/api/v1/log to provide your own logging mechanism to your ErrLog.IO account.
For a look at the fields you can include with your API calls check out Payload Variables
Requirements
The example below uses the following packages:
net/http
fmt
bytes
io/ioutil
Usage
Imports
Ensure you include the following imports directives in your code before using ErrLog.IO.
import ("net/http"
        "fmt"
        "bytes"
        "io/ioutil"
    );
Craft your Payload
You can control what data goes into the package. This is probably best done as part of a try ... except ... block where you can pull values out of an Exception object.
You can see a full list of available fields here.
 var jsonStr = []byte(`
    {
    "message": "This is a test message from Go",
    "apikey": "[Your-api-key]",
    "applicationname": "Sample Go Application",
    "type": "RandomlyGeneratedException",
    "filename": "ErrLogSampleGo.go",
    "method": "main()",
    "lineno": 12,
    "colno": 34
    }`)
Specify the end-point and headers
Here the URL needs to be defined as below and the Content-Type needs to be application/json.
Otherwise you will receive a 415 Unsupported Media Type response.
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
req.Header.Set("Content-Type", "application/json")
Preform the Request
After successfully loggin an error, you will receive an HTTP 200 response from the web request and your exception will have been logged to your ErrLog.IO dashboard.
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
    panic(err)
}
defer resp.Body.Close()

fmt.Println("response Status:", resp.Status)
fmt.Println("response Body:", string(body))
Complete Code Sample
package main;
import ("net/http"
        "fmt"
        "bytes"
        "io/ioutil"
    );

func main() {
     url := "https://relay.errlog.io/api/v1/log"
    fmt.Println("URL:>", url)


    var jsonStr = []byte(`
    {
    "message": "This is a test message",
    "apikey": "[Your-api-key]",
    "applicationname": "Test Application",
    "type": "RandomlyGeneratedException",
    "filename": "ErrLogSampleGo.go",
    "method": "main()",
    "lineno": 12,
    "colno": 34
    }`)
 
    req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
    req.Header.Set("Content-Type", "application/json")

    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    fmt.Println("response Status:", resp.Status)
    fmt.Println("response Headers:", resp.Header)
    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println("response Body:", string(body))
}
Additional Resources
Go - Language
Go - Language Specification
Go - Package Reference