Skip to content

E0206: Bad field attribute ​

A field attribute is a value (@Char{Max: 200}) written after its field, after the struct tag, on the field's line, on a field of a package-level struct type.

A generic struct's fields take attributes when it is live — it embeds ui.Live, or is a live .vuka.html shape: @ui.URL, @ui.Bind, @ui.Defer and the validate rules are written into its LiveSchema, a method of the generic type, so each instantiation (Table[Task], Table[User]) reads its own. Any other generic struct's attributes are an error: they are recorded for the type at package level (vuka.RegisterFields[T] at init, or a model's registration), which needs its type arguments. That covers plain value attributes such as @Char{Max: 200} and those of an orm model.

Wrong ​

vuka
type Post struct {
	Title string @Char{Max: 200} `json:"title"`
	@Char{}
	Body string
}

type Pair[K comparable, V any] struct {
	Key  K
	Note string @Char{Max: 50}
}
vuka
type Post struct {
	Title string `json:"title"` @Char{Max: 200}
	Body  string @Char{}
}

type Table[T any] struct {
	ui.Live
	Rows []T
	page int @ui.URL("page").Default(1)
}

Released under the MIT License. Vuka builds on Go and its tools, which are made by the Go Authors. Vuka is not affiliated with Google or the Go project. Go is a trademark of Google LLC.