https://github.com/exileed/uptimerobotapi
UptimeRobot API golang sdk
https://github.com/exileed/uptimerobotapi
api uptimerobotapi
Last synced: about 1 month ago
JSON representation
UptimeRobot API golang sdk
- Host: GitHub
- URL: https://github.com/exileed/uptimerobotapi
- Owner: exileed
- License: mit
- Created: 2021-10-14T12:45:34.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-11-11T09:33:23.000Z (over 3 years ago)
- Last Synced: 2023-07-27T22:05:58.066Z (almost 3 years ago)
- Topics: api, uptimerobotapi
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 2
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# uptimerobotapi [](https://github.com/exileed/uptimerobotapi/actions) [](https://pkg.go.dev/github.com/exileed/uptimerobotapi) [](https://goreportcard.com/report/github.com/exileed/uptimerobotapi)
A Go client for [UptimeRobot API](https://uptimerobot.com/api/).
## Usage
See the [full API reference on Go.dev](https://pkg.go.dev/github.com/exileed/uptimerobotapi).
### Client initialization
All API requests are made through [`uptimerobotapi.Client`](https://pkg.go.dev/github.com/exileed/uptimerobotapi#Client). Make sure to include an API token:
``` go
package main
import (
"os"
"github.com/exileed/uptimerobotapi"
)
func main() {
client := uptimerobotapi.NewClient(os.Getenv("UPTIMEROBOT_API_TOKEN"))
...
}
```
### Making API requests
Use an initialized client to make API requests:
``` go
package main
import (
"os"
"github.com/exileed/uptimerobotapi"
)
func main() {
client := uptimerobotapi.NewClient(os.Getenv("UPTIMEROBOT_API_TOKEN"))
accounts, err := client.Account.GetAccountDetails()
if err != nil {
panic(err)
}
...
}
```
#### API Error Responses
For cases where your request results in an error from the API, you can use the
`errors.As()` function from the standard library to extract the
`uptimerobotapi.APIError` error value and inspect more details about the error,
including the HTTP response code and UptimeRobot API Error Code.
```go
package main
import (
"fmt"
"github.com/exileed/uptimerobotapi"
)
func main() {
client := uptimerobotapi.NewClient("")
account, err := client.Account.GetAccountDetails()
var apiErr uptimerobotapi.APIError
if errors.As(err, &apiErr){
if apiErr.RateLimited() {
fmt.Println("rate limited")
return
}
fmt.Println("unknown status code:", apiErr.StatusCode)
}
panic(err)
}
fmt.Println(account)
}