Skip to content

Commit be1d2f6

Browse files
authored
Merge pull request #5 from jaypipes/defaults-handler
support api.DefaultsHandler
2 parents 4238470 + 7bbc798 commit be1d2f6

4 files changed

Lines changed: 24 additions & 8 deletions

File tree

defaults.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@ type Defaults struct {
2727
httpDefaults
2828
}
2929

30+
// Merge merges the supplies map of key/value combinations with the set of
31+
// handled defaults for the plugin. The supplied key/value map will NOT be
32+
// unpacked from its top-most plugin named element. So, for example, the
33+
// kube plugin should expect to get a map that looks like
34+
// "kube:namespace:<namespace>" and not "namespace:<namespace>".
35+
func (d *Defaults) Merge(vals map[string]any) {
36+
kubeValsAny, ok := vals[pluginName]
37+
if !ok {
38+
return
39+
}
40+
kubeVals, ok := kubeValsAny.(map[string]string)
41+
if !ok {
42+
return
43+
}
44+
url, ok := kubeVals["base_url"]
45+
if ok {
46+
d.BaseURL = url
47+
}
48+
}
49+
3050
func (d *Defaults) UnmarshalYAML(node *yaml.Node) error {
3151
if node.Kind != yaml.MappingNode {
3252
return parse.ExpectedMapAt(node)

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/gdt-dev/http
33
go 1.24.3
44

55
require (
6-
github.com/gdt-dev/core v1.10.0
6+
github.com/gdt-dev/core v1.11.0
77
github.com/google/uuid v1.6.0
88
github.com/samber/lo v1.51.0
99
github.com/stretchr/testify v1.11.1
@@ -15,7 +15,6 @@ require (
1515
require (
1616
github.com/cenkalti/backoff v2.2.1+incompatible // indirect
1717
github.com/davecgh/go-spew v1.1.1 // indirect
18-
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
1918
github.com/pmezard/go-difflib v1.0.0 // indirect
2019
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
2120
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect

go.sum

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QH
33
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
44
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
55
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6-
github.com/gdt-dev/core v1.10.0 h1:yX0MG2Tt+O34JGDFWcS63LV47lWpizto4HAyR/ugAC0=
7-
github.com/gdt-dev/core v1.10.0/go.mod h1:Bw8J6kUW0b7MUL8qW5e7qSbxb4SI9EAWQ0a4cAoPVpo=
8-
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
9-
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
6+
github.com/gdt-dev/core v1.11.0 h1:jEKDMZ8eoQIQMlTB2C6Ai6q7CfgHJ3y9MVFSzdgc208=
7+
github.com/gdt-dev/core v1.11.0/go.mod h1:Bw8J6kUW0b7MUL8qW5e7qSbxb4SI9EAWQ0a4cAoPVpo=
108
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
119
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
1210
github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=

plugin.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package http
77
import (
88
"github.com/gdt-dev/core/api"
99
gdtplugin "github.com/gdt-dev/core/plugin"
10-
"gopkg.in/yaml.v3"
1110
)
1211

1312
var (
@@ -39,7 +38,7 @@ func (p *plugin) Info() api.PluginInfo {
3938
}
4039
}
4140

42-
func (p *plugin) Defaults() yaml.Unmarshaler {
41+
func (p *plugin) Defaults() api.DefaultsHandler {
4342
return &Defaults{}
4443
}
4544

0 commit comments

Comments
 (0)