
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
github.com/ChezCrawford/go-pagerduty
Advanced tools
go-pagerduty is a CLI and go client library for the PagerDuty v2 API.
First, download the source code
go get github.com/PagerDuty/go-pagerduty
Next build the application.
cd $GOPATH/src/github.com/PagerDuty/go-pagerduty
make install
The CLI requires an authentication token, which can be specified in .pd.yml
file in the home directory of the user, or passed as a command-line argument.
Example of config file:
---
authtoken: fooBar
pd command provides a single entrypoint for all the API endpoints, with individual
API represented by their own sub commands. For an exhaustive list of sub-commands, try:
pd --help
An example of the service sub-command
pd service list
package main
import (
"fmt"
"github.com/PagerDuty/go-pagerduty"
)
var authtoken = "" // Set your auth token here
func main() {
var opts pagerduty.ListEscalationPoliciesOptions
client := pagerduty.NewClient(authtoken)
eps, err := client.ListEscalationPolicies(opts)
if err != nil {
panic(err)
}
for _, p := range eps.EscalationPolicies {
fmt.Println(p.Name)
}
}
The PagerDuty API client also exposes its HTTP client as the HTTPClient field.
If you need to use your own HTTP client, for doing things like defining your own
transport settings, you can replace the default HTTP client with your own by
simply by setting a new value in the HTTPClient field.
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
pagerduty.APIError error value and inspect more details about the error,
including the HTTP response code and PagerDuty API Error Code.
package main
import (
"fmt"
"github.com/PagerDuty/go-pagerduty"
)
var authtoken = "" // Set your auth token here
func main() {
client := pagerduty.NewClient(authtoken)
user, err := client.GetUser("NOTREAL", pagerduty.GetUserOptions{})
if err != nil {
var aerr pagerduty.APIError
if errors.As(err, &aerr) {
if aerr.RateLimited() {
fmt.Println("rate limited")
return
}
fmt.Println("unknown status code:", aerr.StatusCode)
return
}
panic(err)
}
fmt.Println(user)
}
git checkout -b my-new-feature)git commit -am 'Add some feature')git push origin my-new-feature)FAQs
Unknown package
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.