Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,24 @@ import (
"context"
"fmt"
"net/http"


"github.com/oapi-codegen/oapi-codegen/v2/pkg/securityprovider"
"github.com/rootlyhq/rootly-go"
)

func main() {
// Set up our auth provider
authFn, err := securityprovider.NewSecurityProviderBearerToken("YOUR_TOKEN")
if err != nil {
panic(err)
}

// Create a new client
client, err := rootly.NewClient("https://api.rootly.com", rootly.WithRequestEditorFn(
func(ctx context.Context, req *http.Request) error {
req.Header.Set("Authorization", "Bearer YOUR_API_TOKEN")
return nil
},
))
client, err := rootly.NewClient("https://api.rootly.com", rootly.WithRequestEditorFn(authFn.Intercept))
if err != nil {
panic(err)
}

// Use the client to make API calls
ctx := context.Background()
// Example: List incidents
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ require (
github.com/getkin/kin-openapi v0.135.0
github.com/google/uuid v1.6.0
github.com/oapi-codegen/nullable v1.1.0
github.com/oapi-codegen/oapi-codegen/v2 v2.6.0
github.com/oapi-codegen/runtime v1.4.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/oapi-codegen/nullable v1.1.0 h1:eAh8JVc5430VtYVnq00Hrbpag9PFRGWLjxR1/3KntMs=
github.com/oapi-codegen/nullable v1.1.0/go.mod h1:KUZ3vUzkmEKY90ksAmit2+5juDIhIZhfDl+0PwOQlFY=
github.com/oapi-codegen/oapi-codegen/v2 v2.6.0 h1:4i+F2cvwBFZeplxCssNdLy3MhNzUD87mI3HnayHZkAU=
github.com/oapi-codegen/oapi-codegen/v2 v2.6.0/go.mod h1:eWHeJSohQJIINJZzzQriVynfGsnlQVh0UkN2UYYcw4Q=
github.com/oapi-codegen/runtime v1.4.0 h1:KLOSFOp7UzkbS7Cs1ms6NBEKYr0WmH2wZG0KKbd2er4=
github.com/oapi-codegen/runtime v1.4.0/go.mod h1:5sw5fxCDmnOzKNYmkVNF8d34kyUeejJEY8HNT2WaPec=
github.com/oasdiff/yaml v0.0.9 h1:zQOvd2UKoozsSsAknnWoDJlSK4lC0mpmjfDsfqNwX48=
Expand Down
13 changes: 7 additions & 6 deletions test/helper.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package test

import (
"context"
"net/http"
"os"
"testing"

"github.com/oapi-codegen/oapi-codegen/v2/pkg/securityprovider"
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should create a helper in rootly-go, instead to simplify this

"github.com/rootlyhq/rootly-go"
)

Expand All @@ -17,10 +16,12 @@ func SetupClient(t *testing.T) *rootly.ClientWithResponses {
t.Skip("Skipping integration test: ROOTLY_API_TOKEN not set")
}

client, err := rootly.NewClientWithResponses(rootly.ServerURLProduction, rootly.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error {
req.Header.Set("Authorization", "Bearer "+apiToken)
return nil
}))
authFn, err := securityprovider.NewSecurityProviderBearerToken(apiToken)
if err != nil {
t.Fatalf("Failed to create SecurityProvider: %v", err)
}

client, err := rootly.NewClientWithResponses(rootly.ServerURLProduction, rootly.WithRequestEditorFn(authFn.Intercept))
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
Expand Down