Created
March 3, 2021 00:30
-
-
Save podhmo/8f41339893f71a7327e9949596dc18bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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