Documentation
¶
Overview ¶
Command monqgen generates monq.FieldPath constants from the bson tags of a struct.
Hand-written field paths are strings, so a renamed field or a mistyped path is found by a failing query rather than by the compiler. monqgen reads the struct that a collection stores and writes the paths out as typed constants, which every monq operator taking a path accepts as it is.
Run it through go:generate, next to the struct it describes:
//go:generate go run github.com/behzadsh/monq/cmd/monqgen -type User
type User struct {
Email string `bson:"email"`
}
The flags are:
-type the struct to read, required -var the value the paths land in, defaulting to the type name with Paths appended -out the file to write, defaulting to the type name lowercased with _paths.go appended -print write the path tree to standard output instead of generating a file
The remaining argument is the package directory, which defaults to the current one. Paths follow the driver's own tag rules, so a key is the field name lowercased unless a tag says otherwise, a tag of "-" drops the field, and an embedded struct nests under its own name unless it is tagged ",inline".
Directories
¶
| Path | Synopsis |
|---|---|
|
internal
|
|
|
example
Package example is a worked example of monqgen: a struct, the paths generated from it, and tests using those paths against the monq API.
|
Package example is a worked example of monqgen: a struct, the paths generated from it, and tests using those paths against the monq API. |