Support arbitrary tag names [GH-3]
diff --git a/mapstructure.go b/mapstructure.go
index 231df40..2941a51 100644
--- a/mapstructure.go
+++ b/mapstructure.go
@@ -30,6 +30,10 @@
// Result is a pointer to the struct that will contain the decoded
// value.
Result interface{}
+
+ // The tag name that mapstructure reads for field names. This
+ // defaults to "mapstructure"
+ TagName string
}
// A Decoder takes a raw interface value and turns it into structured
@@ -83,6 +87,10 @@
return nil, errors.New("result must be addressable (a pointer)")
}
+ if config.TagName == "" {
+ config.TagName = "mapstructure"
+ }
+
result := &Decoder{
config: config,
}
@@ -325,7 +333,7 @@
fieldType := valType.Field(i)
fieldName := fieldType.Name
- tagValue := fieldType.Tag.Get("mapstructure")
+ tagValue := fieldType.Tag.Get(d.config.TagName)
if tagValue != "" {
fieldName = tagValue
}