Documentation ¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseStructTags ¶
ParseStructTags parses a struct's tags and returns a map of the struct's fields to an array of the tag values.
This is a convenience function that creates a new `TagParse` instance and calles its `Parse` method.
Types ¶
type TagParser ¶
type TagParser struct {
TagName string // They key to look for in the struct tags
}
TagParser is a struct used for parsing struct tags with the key `TagName`.
Example ¶
package main import ( "encoding/json" "fmt" "github.com/a-poor/tags" ) func main() { // Define a struct that we'll be getting the tags from user := struct { ID int `app:"user_id"` Name string `app:",omitempty"` Email string `app:"user_email,omitempty"` NotMe bool ImEmpty bool `app:""` }{} // Parse the struct's tags fields := tags.ParseStructTags("app", user) // Print out the results as JSON data, _ := json.MarshalIndent(fields, "", " ") fmt.Println(string(data)) }
Output: { "Email": [ "user_email", "omitempty" ], "ID": [ "user_id" ], "ImEmpty": [ "" ], "Name": [ "", "omitempty" ] }
Click to show internal directories.
Click to hide internal directories.