Skip to content

Instantly share code, notes, and snippets.

@podhmo
Created March 3, 2021 00:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save podhmo/8f41339893f71a7327e9949596dc18bf to your computer and use it in GitHub Desktop.
Save podhmo/8f41339893f71a7327e9949596dc18bf to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"reflect"
"github.com/jmoiron/sqlx/reflectx"
)
type Person struct {
Name string `db:"name,unique"`
Age int64 `db:"age,default=20"`
}
func main() {
mapper := reflectx.NewMapper("db")
tmap := mapper.TypeMap(reflect.TypeOf(Person{}))
for i, info := range tmap.Index {
fmt.Printf("%d\t%s\ttags=%+#v\n", i, info.Name, info.Options)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment