protoc
To use protoc-gen-gorm with protoc, make sure protoc-gen-gorm
is in your path (see Install) and invoke protoc
with --gorm_out=dir
, where dir is your desired output directory for the files that protoc-gen-gorm generates.
For this example we invoke (go generate
):
protoc -Iprotos --go_out=./ --gorm_out=./ protos/models.proto
This compiles our GORM v2 model (and Go bindings) that we make use of in main.go:
alice := &pb.UserModel{Name: "Alice"}
db.Create(alice)
When run:
$ go generate
$ go run main.go
...
Created first user: Alice
$ go run main.go
The first user is: Alice