package main import ( "fmt" "github.com/ungerik/go-start/model" ) type Person struct { Name string `meta:"type:text;label:Name"` Age int `meta:"type:number;min:0;max:150;label:Age"` Email string `meta:"type:text;label:Email"` Password string `meta:"type:password;label:Password"` } func main() { p := Person{Name: "John Doe", Age: 30, Email: "[email protected]", Password: "secret"} // Selecting meta data md := model.MetaData(&p) // Getting the metadata for the 'Name' field fmt.Println(md.Get("Name")) // Getting the metadata for the 'Age' field fmt.Println(md.Get("Age")) // Getting the metadata for the 'Email' field fmt.Println(md.Get("Email")) // Getting the metadata for the 'Password' field fmt.Println(md.Get("Password")) }
package main import ( "fmt" "github.com/ungerik/go-start/model" ) type Product struct { Name string `meta:"type:text;label:Name"` Price float64 `meta:"type:number;min:0;max:1000;label:Price"` Quantity int `meta:"type:number;min:0;max:1000;label:Quantity"` } func main() { p1 := Product{Name: "Product1", Price: 25.0, Quantity: 100} p2 := Product{Name: "Product2", Price: 50.0, Quantity: 50} p3 := Product{Name: "Product3", Price: 75.0, Quantity: 25} // Selecting meta data for a slice of products md := model.SliceMetaData(&[]Product{p1, p2, p3}) // Getting the metadata for the 'Name' field of the first product fmt.Println(md.GetSliceItem(0, "Name")) // Getting the metadata for the 'Price' field of the second product fmt.Println(md.GetSliceItem(1, "Price")) // Getting the metadata for the 'Quantity' field of the third product fmt.Println(md.GetSliceItem(2, "Quantity")) }In this example, we defined a Product struct with some fields that have structured tags. We created three instances of the Product struct and then used the SliceMetaData() function of the `github.com.ungerik.go-start.model` package to select the metadata for a slice of products. We then used the GetSliceItem() function to get the metadata for each field in each product.