Skip to content

Commit

Permalink
go: Replace most of the lib with generated code (#1632)
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-jplatte authored Jan 10, 2025
2 parents 18cf625 + 5eda884 commit 8be02dc
Show file tree
Hide file tree
Showing 9 changed files with 525 additions and 263 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
* Libs/Rust **(Breaking)**: Add optional `EventTypeDeleteOptions` parameter to `EventType::delete`
* Libs/Rust **(Breaking)**: Add optional `PostOptions` parameter to `Endpoint::recover`,
`Endpoint::rotate_secret`, `Integration::rotate_key` and `MessageAttempt::resend`
* Libs/Go **(Breaking)**: Rename `Statistics.AggregateAppStats` to `AggregateAppStatsWithOptions`;
the old name is used for a version of the method without the `PostOptions`, like elsewhere
* Libs/Go: Add `Authentication.ExpireAll` (and `ExpireAllWithOptions`)

## Version 1.56.0
* Skipping versions: we had an issue with our CI that created duplicated Go
Expand Down
62 changes: 23 additions & 39 deletions go/application.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// this file is @generated
package svix

import (
Expand Down Expand Up @@ -84,33 +85,6 @@ func (application *Application) CreateWithOptions(
return ret, nil
}

func (a *Application) GetOrCreate(
ctx context.Context,
applicationIn *ApplicationIn,
) (*ApplicationOut, error) {
return a.GetOrCreateWithOptions(ctx, applicationIn, nil)
}

func (a *Application) GetOrCreateWithOptions(
ctx context.Context,
applicationIn *ApplicationIn,
options *PostOptions,
) (*ApplicationOut, error) {
req := a.api.ApplicationAPI.V1ApplicationCreate(ctx)
req = req.ApplicationIn(*applicationIn)
req = req.GetIfExists(true)
if options != nil {
if options.IdempotencyKey != nil {
req = req.IdempotencyKey(*options.IdempotencyKey)
}
}
ret, res, err := req.Execute()
if err != nil {
return nil, wrapError(err, res)
}
return ret, nil
}

// Get an application.
func (application *Application) Get(
ctx context.Context,
Expand Down Expand Up @@ -148,25 +122,35 @@ func (application *Application) Update(
return ret, nil
}

func (a *Application) Patch(
// Delete an application.
func (application *Application) Delete(
ctx context.Context,
appId string,
) error {
req := application.api.ApplicationAPI.V1ApplicationDelete(
ctx,
appId,
)

res, err := req.Execute()
return wrapError(err, res)
}

// Partially update an application.
func (application *Application) Patch(
ctx context.Context,
appId string,
applicationPatch *ApplicationPatch,
) (*ApplicationOut, error) {
req := a.api.ApplicationAPI.V1ApplicationPatch(ctx, appId)
req = req.ApplicationPatch(*applicationPatch)
req := application.api.ApplicationAPI.V1ApplicationPatch(
ctx,
appId,
).ApplicationPatch(*applicationPatch)

ret, res, err := req.Execute()
if err != nil {
return nil, wrapError(err, res)
}
return ret, nil
}

func (a *Application) Delete(
ctx context.Context,
appId string,
) error {
req := a.api.ApplicationAPI.V1ApplicationDelete(ctx, appId)
res, err := req.Execute()
return wrapError(err, res)
return ret, nil
}
33 changes: 33 additions & 0 deletions go/application_ext.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// non-generated extension for application.go
package svix

import (
"context"
)

func (a *Application) GetOrCreate(
ctx context.Context,
applicationIn *ApplicationIn,
) (*ApplicationOut, error) {
return a.GetOrCreateWithOptions(ctx, applicationIn, nil)
}

func (a *Application) GetOrCreateWithOptions(
ctx context.Context,
applicationIn *ApplicationIn,
options *PostOptions,
) (*ApplicationOut, error) {
req := a.api.ApplicationAPI.V1ApplicationCreate(ctx)
req = req.ApplicationIn(*applicationIn)
req = req.GetIfExists(true)
if options != nil {
if options.IdempotencyKey != nil {
req = req.IdempotencyKey(*options.IdempotencyKey)
}
}
ret, res, err := req.Execute()
if err != nil {
return nil, wrapError(err, res)
}
return ret, nil
}
37 changes: 37 additions & 0 deletions go/authentication.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// this file is @generated
package svix

import (
Expand Down Expand Up @@ -50,6 +51,42 @@ func (authentication *Authentication) AppPortalAccessWithOptions(
return ret, nil
}

// Expire all of the tokens associated with a specific application.
func (authentication *Authentication) ExpireAll(
ctx context.Context,
appId string,
applicationTokenExpireIn *ApplicationTokenExpireIn,
) error {
return authentication.ExpireAllWithOptions(
ctx,
appId,
applicationTokenExpireIn,
nil,
)
}

// Expire all of the tokens associated with a specific application.
func (authentication *Authentication) ExpireAllWithOptions(
ctx context.Context,
appId string,
applicationTokenExpireIn *ApplicationTokenExpireIn,
options *PostOptions,
) error {
req := authentication.api.AuthenticationAPI.V1AuthenticationExpireAll(
ctx,
appId,
).ApplicationTokenExpireIn(*applicationTokenExpireIn)

if options != nil {
if options.IdempotencyKey != nil {
req = req.IdempotencyKey(*options.IdempotencyKey)
}
}

res, err := req.Execute()
return wrapError(err, res)
}

// DEPRECATED: Please use `app-portal-access` instead.
//
// Use this function to get magic links (and authentication codes) for connecting your users to the Consumer Application Portal.
Expand Down
Loading

0 comments on commit 8be02dc

Please sign in to comment.