Standard library / reflect

reflect.StructTag.Get()

Read the value for a tag key. Missing keys and explicitly empty values both produce an empty string. Malformed tag syntax has unspecified behavior. Expected stdout: 'id\n'.

Formal Syntax & Structure

go syntaxgo
func (tag StructTag) Get(key string) string

Parameters & Attributes

NameTypeDescription
keystringMap key type, or a struct tag key.

Return Value

string

Read the value for a tag key.

Working Example

Example Snippetgo
package main
import (  "fmt"  "reflect")
func main() { tag := reflect.StructTag(`json:"id"`); fmt.Println(tag.Get("json")) }
Go Reference