tagparse

package
Version: v0.0.0-...-b425644 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2019 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package to parse a tag.

Tags are annotation with struct fields, that allow for some elegant solutions for different problems. Examples are validation and alike. This is an example on what that might look like:

type Example struct {
	AField string `tagName1:"tagValue1" tagName2:"tagValue2"`
}

As the syntax is somewhat weird and the tag interface only supports a getter, this tag parser was written. It will use go's tag parser to retrieve the tag for a given prefix, parse the value, and return a map of strings to strings. Keys and values are separated by an equal sign '=', values might be quoted using single quotes "'", and key-value pairs are separated using whitespace.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Parse

func Parse(field reflect.StructField, prefix string, customHander func(string) (string, string, error)) (result map[string]string, e error)

Parse tag with the given prefix of the given field. Return a map of strings to strings. If errors occur they are returned accordingly.

func ParseCustom

func ParseCustom(field reflect.StructField, prefix string, customF CustomSplitter) (result map[string]string, e error)

Like Parse, but with a custom splitter used for tag values that don't have the form `key=value`.

Types

type CustomSplitter

type CustomSplitter func(string) (string, string, error)

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL