Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lilsahil/feature/endpoint metadata #47

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
33 changes: 30 additions & 3 deletions endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package convoy_go

import (
"context"
"encoding/json"
"errors"
"fmt"
"time"
Expand Down Expand Up @@ -34,11 +35,37 @@ type CreateEndpointRequest struct {
RateLimitDuration string `json:"rate_limit_duration,omitempty"`
}

// customString is a reusable type to handle JSON values that can be either strings or integers.
// It unmarshals JSON data into a string representation, regardless of whether the input is a string or an integer.
type customString string

func (c *customString) UnmarshalJSON(b []byte) error {
var strValue string
var intValue int

if err := json.Unmarshal(b, &strValue); err == nil {
*c = customString(strValue)
return nil
}

if err := json.Unmarshal(b, &intValue); err == nil {
*c = customString(fmt.Sprintf("%d", intValue))
return nil
}

return fmt.Errorf("customstring: cannot unmarshal %v into Go value", string(b))
}

func (c *customString) MarshalJSON() ([]byte, error) {
return json.Marshal(string(*c))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually on second thought, does it make sense to return these as integers instead as specified in the API?

image

}

type EndpointResponse struct {
UID string `json:"uid"`
GroupID string `json:"group_id"`
OwnerID string `json:"owner_id"`
TargetUrl string `json:"target_url"`
URL string `json:"url"`
Title string `json:"title"`
Description string `json:"description"`

Expand All @@ -49,9 +76,9 @@ type EndpointResponse struct {
SupportEmail string `json:"support_email"`
IsDisabled bool `json:"is_disabled"`

HttpTimeout string `json:"http_timeout"`
RateLimit int `json:"rate_limit"`
RateLimitDuration string `json:"rate_limit_duration"`
HttpTimeout customString `json:"http_timeout"`
RateLimit customString `json:"rate_limit"`
RateLimitDuration customString `json:"rate_limit_duration"`

Authentication *EndpointAuth `json:"authentication"`
Events int64 `json:"events"`
Expand Down
3 changes: 2 additions & 1 deletion subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ type SubscriptionResponse struct {
Type string `json:"type"`
Status string `json:"status"`

Source *SourceResponse `json:"source_metadata,omitempty"`
Source *SourceResponse `json:"source_metadata,omitempty"`
EndpointMetaData *EndpointResponse `json:"endpoint_metadata"`

// subscription config
AlertConfig *AlertConfiguration `json:"alert_config,omitempty"`
Expand Down
Loading