MCPcopy Index your code
hub / github.com/fatih/structtag

github.com/fatih/structtag @v1.2.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.2.0 ↗ · + Follow
28 symbols 96 edges 2 files 15 documented · 54% 86 cross-repo links updated 2y agov1.2.0 · 2019-12-06★ 6523 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

structtag GoDoc

structtag provides an easy way of parsing and manipulating struct tag fields. Please vendor the library as it might change in future versions.

Install

go get github.com/fatih/structtag

Example

package main

import (
    "fmt"
    "reflect"
    "sort"

    "github.com/fatih/structtag"
)

func main() {
    type t struct {
        t string `json:"foo,omitempty,string" xml:"foo"`
    }

    // get field tag
    tag := reflect.TypeOf(t{}).Field(0).Tag

    // ... and start using structtag by parsing the tag
    tags, err := structtag.Parse(string(tag))
    if err != nil {
        panic(err)
    }

    // iterate over all tags
    for _, t := range tags.Tags() {
        fmt.Printf("tag: %+v\n", t)
    }

    // get a single tag
    jsonTag, err := tags.Get("json")
    if err != nil {
        panic(err)
    }
    fmt.Println(jsonTag)         // Output: json:"foo,omitempty,string"
    fmt.Println(jsonTag.Key)     // Output: json
    fmt.Println(jsonTag.Name)    // Output: foo
    fmt.Println(jsonTag.Options) // Output: [omitempty string]

    // change existing tag
    jsonTag.Name = "foo_bar"
    jsonTag.Options = nil
    tags.Set(jsonTag)

    // add new tag
    tags.Set(&structtag.Tag{
        Key:     "hcl",
        Name:    "foo",
        Options: []string{"squash"},
    })

    // print the tags
    fmt.Println(tags) // Output: json:"foo_bar" xml:"foo" hcl:"foo,squash"

    // sort tags according to keys
    sort.Sort(tags)
    fmt.Println(tags) // Output: hcl:"foo,squash" json:"foo_bar" xml:"foo"
}

Core symbols most depended-on inside this repo

String
called by 30
tags.go
Parse
called by 10
tags.go
Get
called by 4
tags.go
Set
called by 3
tags.go
AddOptions
called by 3
tags.go
Tags
called by 3
tags.go
Value
called by 3
tags.go
DeleteOptions
called by 2
tags.go

Shape

Method 15
Function 11
Struct 2

Languages

Go100%

Modules by API surface

tags.go18 symbols
tags_test.go10 symbols

For agents

$ claude mcp add structtag \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page