When integrating gorm's gorm.Model fields into protobuf definitions, challenges arise due to the lack of datetime support in proto3. This article explores solutions to this problem.
CreatedAt, UpdatedAt: Use google.protobuf.Timestamp with the gogoproto.stdtime option.
DeletedAt: Handle it as an opaque timestamp field with a conversion function.
The protoc-gen-gorm project faced challenges with proto2 and proto3 compatibility.
To integrate gorm.Model fields, a post-processing script like gorm.sh can be used after go file generation. This script can update the generated code to include GORM-specific annotations.
Execute the script with ./gorm.sh file.pb.go on the generated pb.go file. The script will add annotations for id, name, etc., allowing GORM to properly interact with the model fields.
Integrating gorm.Model requires additional handling of datetime fields and customized code generation or post-processing. By following these steps, developers can successfully integrate GORM fields into their proto definitions.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3