GO
LogHive provides a simple REST API that you can use to push events and errors. Here is an example code for Dart:
Push Event
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func sendRequest() {
url := "https://api.loghive.app/v1/event/add"
headers := map[string]string{
"Content-Type": "application/json",
"Authorization": "ApiKey: your-api-key",
}
data := map[string]string{
"project": "yourprojectname",
"group": "yourgroupname",
"event": "your-event-name",
"description": "your-description",
"notify": false
}
jsonData, err := json.Marshal(data)
if err != nil {
// Handle error
return
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
if err != nil {
// Handle error
return
}
for key, value := range headers {
req.Header.Set(key, value)
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
// Handle error
return
}
defer resp.Body.Close()
// Handle response
}
Push Insight
package main
import (
"bytes"
"encoding/json"
"net/http"
)
func sendRequest() {
url := "https://api.loghive.app/v1/insight/add"
headers := map[string]string{
"Content-Type": "application/json",
"Authorization": "ApiKey: your-api-key",
}
data := map[string]string{
"project": "MySaas",
"insight": "system1-online",
"value": 1
}
jsonData, err := json.Marshal(data)
if err != nil {
// Handle error
return
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
if err != nil {
// Handle error
return
}
for key, value := range headers {
req.Header.Set(key, value)
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
// Handle error
return
}
defer resp.Body.Close()
// Handle response
}
Last updated