Skip to content

Commit 4134a60

Browse files
ChBLAKimNorgaard
authored andcommitted
chore: rename ToMapOptions to ToMapOption
1 parent 44c231a commit 4134a60

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

xstructs/map.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ var tagCategories = []string{"json", "yaml"}
1414
// WithTags allows you to specify custom tag categories to check for.
1515
// It can be used to override the default "json" and "yaml" tags.
1616
// The tags are checked in the order they are provided.
17-
func WithTags(tags ...string) ToMapOptions {
17+
func WithTags(tags ...string) ToMapOption {
1818
return func(h *handler) {
1919
h.tags = tags
2020
}
2121
}
2222

2323
// WithAllowNoTags allows you to specify whether to allow fields without tags.
2424
// If used, fields without tags will be included in the output map.
25-
func WithAllowNoTags() ToMapOptions {
25+
func WithAllowNoTags() ToMapOption {
2626
return func(h *handler) {
2727
h.allowNoTags = true
2828
}
2929
}
3030

31-
// ToMapOptions is a function that modifies the handler.
32-
type ToMapOptions func(*handler)
31+
// ToMapOption is a function that modifies the handler.
32+
type ToMapOption func(*handler)
3333

3434
// handler is a struct that contains the options for the ToMap function.
3535
// It contains a list of tags to check for and a flag to allow fields
@@ -53,7 +53,7 @@ type tagWrapper struct {
5353
// It also initializes the allowNoTags flag to false.
5454
// It can be modified using the ToMapOptions functions.
5555
// It returns a pointer to the handler.
56-
func newHandler(opts ...ToMapOptions) *handler {
56+
func newHandler(opts ...ToMapOption) *handler {
5757
h := &handler{
5858
tags: tagCategories,
5959
allowNoTags: false,
@@ -76,7 +76,7 @@ func newHandler(opts ...ToMapOptions) *handler {
7676
//
7777
// If the input is nil, it returns nil.
7878
// If the input is not a struct or map, it returns an error.
79-
func ToMap(obj any, opts ...ToMapOptions) (map[string]any, error) {
79+
func ToMap(obj any, opts ...ToMapOption) (map[string]any, error) {
8080
handler := newHandler(opts...)
8181

8282
if obj == nil {

xstructs/map_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func TestToMap(t *testing.T) {
1313
tests := []struct {
1414
name string
1515
data any
16-
opts []xstructs.ToMapOptions
16+
opts []xstructs.ToMapOption
1717
expected map[string]any
1818
wantErr bool
1919
}{
@@ -278,7 +278,7 @@ func TestToMap(t *testing.T) {
278278
},
279279
E: []string{"one", "two"},
280280
},
281-
opts: []xstructs.ToMapOptions{
281+
opts: []xstructs.ToMapOption{
282282
xstructs.WithTags("yaml", "json"),
283283
},
284284
expected: map[string]any{
@@ -310,7 +310,7 @@ func TestToMap(t *testing.T) {
310310
},
311311
E: []string{"one", "two"},
312312
},
313-
opts: []xstructs.ToMapOptions{
313+
opts: []xstructs.ToMapOption{
314314
xstructs.WithTags("custom"),
315315
},
316316
expected: map[string]any{},
@@ -325,7 +325,7 @@ func TestToMap(t *testing.T) {
325325
A: 1,
326326
B: "test",
327327
},
328-
opts: []xstructs.ToMapOptions{
328+
opts: []xstructs.ToMapOption{
329329
xstructs.WithAllowNoTags(),
330330
},
331331
expected: map[string]any{

0 commit comments

Comments
 (0)