diff --git a/README.md b/README.md index 4cebc26..2c8fafd 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/go.mod b/go.mod index 8b08db8..6dcbd8d 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 0a33795..76ed76d 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/test/helper.go b/test/helper.go index ff7c431..e8b2e33 100644 --- a/test/helper.go +++ b/test/helper.go @@ -1,11 +1,10 @@ package test import ( - "context" - "net/http" "os" "testing" + "github.com/oapi-codegen/oapi-codegen/v2/pkg/securityprovider" "github.com/rootlyhq/rootly-go" ) @@ -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) }