Skip to content

Commit

Permalink
Libs(Go): resolve some lints
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-onelson committed Jun 25, 2024
1 parent 0853f4f commit 769c999
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
28 changes: 11 additions & 17 deletions go/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,14 @@ func (a *Application) List(ctx context.Context, options *ApplicationListOptions)
req = req.Limit(*options.Limit)
}
if options.Order != nil {
req = req.Order(openapi.Ordering(*options.Order))
req = req.Order(*options.Order)
}
}
resp, res, err := req.Execute()
if err != nil {
return nil, wrapError(err, res)
}
ret := ListResponseApplicationOut(resp)
return &ret, nil
return &resp, nil
}

func (a *Application) Create(ctx context.Context, applicationIn *ApplicationIn) (*ApplicationOut, error) {
Expand All @@ -50,7 +49,7 @@ func (a *Application) Create(ctx context.Context, applicationIn *ApplicationIn)

func (a *Application) CreateWithOptions(ctx context.Context, applicationIn *ApplicationIn, options *PostOptions) (*ApplicationOut, error) {
req := a.api.ApplicationApi.V1ApplicationCreate(ctx)
req = req.ApplicationIn(openapi.ApplicationIn(*applicationIn))
req = req.ApplicationIn(*applicationIn)
if options != nil {
if options.IdempotencyKey != nil {
req = req.IdempotencyKey(*options.IdempotencyKey)
Expand All @@ -60,8 +59,7 @@ func (a *Application) CreateWithOptions(ctx context.Context, applicationIn *Appl
if err != nil {
return nil, wrapError(err, res)
}
ret := ApplicationOut(resp)
return &ret, nil
return &resp, nil
}

func (a *Application) GetOrCreate(ctx context.Context, applicationIn *ApplicationIn) (*ApplicationOut, error) {
Expand All @@ -70,7 +68,7 @@ func (a *Application) GetOrCreate(ctx context.Context, applicationIn *Applicatio

func (a *Application) GetOrCreateWithOptions(ctx context.Context, applicationIn *ApplicationIn, options *PostOptions) (*ApplicationOut, error) {
req := a.api.ApplicationApi.V1ApplicationCreate(ctx)
req = req.ApplicationIn(openapi.ApplicationIn(*applicationIn))
req = req.ApplicationIn(*applicationIn)
req = req.GetIfExists(true)
if options != nil {
if options.IdempotencyKey != nil {
Expand All @@ -81,8 +79,7 @@ func (a *Application) GetOrCreateWithOptions(ctx context.Context, applicationIn
if err != nil {
return nil, wrapError(err, res)
}
ret := ApplicationOut(resp)
return &ret, nil
return &resp, nil
}

func (a *Application) Get(ctx context.Context, appId string) (*ApplicationOut, error) {
Expand All @@ -91,30 +88,27 @@ func (a *Application) Get(ctx context.Context, appId string) (*ApplicationOut, e
if err != nil {
return nil, wrapError(err, res)
}
ret := ApplicationOut(resp)
return &ret, nil
return &resp, nil
}

func (a *Application) Update(ctx context.Context, appId string, applicationIn *ApplicationIn) (*ApplicationOut, error) {
req := a.api.ApplicationApi.V1ApplicationUpdate(ctx, appId)
req = req.ApplicationIn(openapi.ApplicationIn(*applicationIn))
req = req.ApplicationIn(*applicationIn)
resp, res, err := req.Execute()
if err != nil {
return nil, wrapError(err, res)
}
ret := ApplicationOut(resp)
return &ret, nil
return &resp, nil
}

func (a *Application) Patch(ctx context.Context, appId string, applicationPatch *ApplicationPatch) (*ApplicationOut, error) {
req := a.api.ApplicationApi.V1ApplicationPatch(ctx, appId)
req = req.ApplicationPatch(openapi.ApplicationPatch(*applicationPatch))
req = req.ApplicationPatch(*applicationPatch)
resp, res, err := req.Execute()
if err != nil {
return nil, wrapError(err, res)
}
ret := ApplicationOut(resp)
return &ret, nil
return &resp, nil
}

func (a *Application) Delete(ctx context.Context, appId string) error {
Expand Down
10 changes: 6 additions & 4 deletions go/svix.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,19 @@ func Int32(i int32) *int32 {
func New(token string, options *SvixOptions) *Svix {
conf := openapi.NewConfiguration()
conf.Scheme = "https"
conf.Host = "api.svix.com"
conf.HTTPClient = defaultHTTPClient

var tokenParts = strings.Split(token, ".")
var region = tokenParts[len(tokenParts)-1]
if region == "us" {
switch region {
case "us":
conf.Host = "api.us.svix.com"
} else if region == "eu" {
case "eu":
conf.Host = "api.eu.svix.com"
} else if region == "in" {
case "in":
conf.Host = "api.in.svix.com"
default:
conf.Host = "api.svix.com"
}

if options != nil {
Expand Down
4 changes: 2 additions & 2 deletions go/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Webhook struct {

const webhookSecretPrefix = "whsec_"

var tolerance time.Duration = 5 * time.Minute
var tolerance = 5 * time.Minute

var (
errRequiredHeaders = fmt.Errorf("Missing Required Headers")
Expand Down Expand Up @@ -86,7 +86,7 @@ func (wh *Webhook) verify(payload []byte, headers http.Header, enforceTolerance
}

if enforceTolerance {
if err := verifyTimestamp(timestamp); err != nil {
if err = verifyTimestamp(timestamp); err != nil {
return err
}
}
Expand Down
13 changes: 10 additions & 3 deletions go/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
var defaultMsgID = "msg_p5jXN8AQM9LWM0D4loKWxJek"
var defaultPayload = []byte(`{"test": 2432232314}`)
var defaultSecret = "MfKQ9r8GKYqrTwjUPD8ILPZIo2LaLaSw"
var tolerance time.Duration = 5 * time.Minute
var tolerance = 5 * time.Minute

type testPayload struct {
id string
Expand All @@ -32,8 +32,15 @@ func newTestPayload(timestamp time.Time) *testPayload {
tp.payload = defaultPayload
tp.secret = defaultSecret

wh, _ := svix.NewWebhook(tp.secret)
tp.signature, _ = wh.Sign(tp.id, tp.timestamp, tp.payload)
wh, err := svix.NewWebhook(tp.secret)
if err != nil {
panic(err)
}
signature, err := wh.Sign(tp.id, tp.timestamp, tp.payload)
if err != nil {
panic(err)
}
tp.signature = signature

tp.header = http.Header{}
tp.header.Set("svix-id", tp.id)
Expand Down

0 comments on commit 769c999

Please sign in to comment.