From 65a0cd6965771e9115735491df3f3183f9700a43 Mon Sep 17 00:00:00 2001 From: Derich Pacheco Date: Tue, 11 Jun 2024 11:10:07 -0300 Subject: [PATCH] feat: Use enum style TLS config (#35) --- domains.go | 13 ++++++++++--- domains_test.go | 2 +- examples/domains.go | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/domains.go b/domains.go index 4b0aef1..6d42ada 100644 --- a/domains.go +++ b/domains.go @@ -7,6 +7,13 @@ import ( "net/http" ) +type TlsOption = string + +const ( + Enforced TlsOption = "enforced" + Opportunistic TlsOption = "opportunistic" +) + type DomainsSvc interface { CreateWithContext(ctx context.Context, params *CreateDomainRequest) (CreateDomainResponse, error) Create(params *CreateDomainRequest) (CreateDomainResponse, error) @@ -46,9 +53,9 @@ type ListDomainsResponse struct { } type UpdateDomainRequest struct { - OpenTracking bool `json:"open_tracking,omitempty"` - ClickTracking bool `json:"click_tracking,omitempty"` - Tls string `json:"tls,omitempty"` + OpenTracking bool `json:"open_tracking,omitempty"` + ClickTracking bool `json:"click_tracking,omitempty"` + Tls TlsOption `json:"tls,omitempty"` } type Domain struct { diff --git a/domains_test.go b/domains_test.go index 6cd2b6d..7298974 100644 --- a/domains_test.go +++ b/domains_test.go @@ -229,7 +229,7 @@ func TestUpdateDomain(t *testing.T) { params := &UpdateDomainRequest{ OpenTracking: true, - Tls: "opportunistic", + Tls: Opportunistic, } updated, err := client.Domains.Update("d91cd9bd-1176-453e-8fc1-35364d380206", params) if err != nil { diff --git a/examples/domains.go b/examples/domains.go index 06bf9ad..a415ddd 100644 --- a/examples/domains.go +++ b/examples/domains.go @@ -8,7 +8,7 @@ import ( "github.com/resend/resend-go/v2" ) -func domainsExample() { +func domainExample() { ctx := context.TODO() apiKey := os.Getenv("RESEND_API_KEY") @@ -40,7 +40,7 @@ func domainsExample() { updateDomainParams := &resend.UpdateDomainRequest{ OpenTracking: true, ClickTracking: true, - Tls: "opportunistic", + Tls: resend.Enforced, } updated, err := client.Domains.UpdateWithContext(ctx, domain.Id, updateDomainParams)