From ab951d51f22bf827e2ef041d4b41e4901ae92010 Mon Sep 17 00:00:00 2001 From: Ryan Grant Date: Tue, 8 Oct 2024 17:56:53 -0700 Subject: [PATCH] alias `WithTrafficPolicy` to `WithPolicyString` --- CHANGELOG.md | 6 ++++++ config/policy.go | 18 ++++++++++++++---- config/policy_test.go | 4 ++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 025e22c..9ac5c61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 1.11.0 + +Changes: + +- Adds `WithTrafficPolicy` function, replacing `WithPolicyString` + ## 1.10.0 Enhancements: diff --git a/config/policy.go b/config/policy.go index 319fd8e..b6756b9 100644 --- a/config/policy.go +++ b/config/policy.go @@ -15,10 +15,10 @@ type rule po.Rule type action po.Action type trafficPolicy string -// WithPolicyString configures this edge with the provided policy configuration -// passed as a json or yaml string and overwrites any previously-set traffic policy +// WithTrafficPolicy configures this edge with the provided policy configuration +// passed as a json or yaml string and overwrites any previously-set traffic policy. // https://ngrok.com/docs/http/traffic-policy -func WithPolicyString(str string) interface { +func WithTrafficPolicy(str string) interface { HTTPEndpointOption TLSEndpointOption TCPEndpointOption @@ -29,6 +29,16 @@ func WithPolicyString(str string) interface { return trafficPolicy(str) } +// WithPolicyString is deprecated, use WithTrafficPolicy instead. +// https://ngrok.com/docs/http/traffic-policy/ +func WithPolicyString(str string) interface { + HTTPEndpointOption + TLSEndpointOption + TCPEndpointOption +} { + return WithTrafficPolicy(str) +} + func (p trafficPolicy) ApplyTLS(opts *tlsOptions) { opts.TrafficPolicy = string(p) } @@ -51,7 +61,7 @@ func isYamlStr(yamlStr string) bool { return yaml.Unmarshal([]byte(yamlStr), &yml) == nil } -// WithPolicy is deprecated, use WithPolicyString instead. +// WithPolicy is deprecated, use WithTrafficPolicy instead. // https://ngrok.com/docs/http/traffic-policy/ func WithPolicy(p po.Policy) interface { HTTPEndpointOption diff --git a/config/policy_test.go b/config/policy_test.go index a0f34c5..5ef3ffd 100644 --- a/config/policy_test.go +++ b/config/policy_test.go @@ -89,7 +89,7 @@ inbound: { name: "with valid JSON policy string", opts: optsFunc( - WithPolicyString(` + WithTrafficPolicy(` { "inbound":[ { @@ -145,7 +145,7 @@ inbound: { name: "with valid YAML policy string", opts: optsFunc( - WithPolicyString(yamlPolicy)), + WithTrafficPolicy(yamlPolicy)), expectOpts: func(t *testing.T, opts *O) { actual := getPolicies(opts) require.NotEmpty(t, actual)