Integrating gorm.Model Fields into Protobuf Definitions
Question:
How to integrate gorm. Model fields (deleted_at, create_at, id, etc.) integrated into protobuf3 definition?
Answer:
protoc-gen-gorm project is not working properly. Couldn't run successfully due to some mixing of proto2 and proto3.
A script can be created to post-process the go files after generating them from protobuf as an alternative solution.
The following is the script (gorm.sh):
<code class="bash">#!/bin/bash g () { sed "s/json:\",omitempty\"/json:\",omitempty\" gorm:\"type:\"/" } cat \ | g "id" "primary_key" \ | g "name" "varchar(100)" \ > .tmp && mv {.tmp,}</code>
After generating the go file, execute the script on the file to integrate the gorm.Model field into the protobuf definition.
The above is the detailed content of This is an article title that you can refer to: How to Integrate gorm.Model Fields into Protobuf3 Definitions?. For more information, please follow other related articles on the PHP Chinese website!