Home  >  Article  >  Backend Development  >  This is an article title that you can refer to: How to Integrate gorm.Model Fields into Protobuf3 Definitions?

This is an article title that you can refer to: How to Integrate gorm.Model Fields into Protobuf3 Definitions?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-27 03:54:30890browse

这是一个可以参考的文章标题:

How to Integrate gorm.Model Fields into Protobuf3 Definitions?

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 &quot;s/json:\&quot;,omitempty\&quot;/json:\&quot;,omitempty\&quot; gorm:\&quot;type:\&quot;/&quot;
}

cat  \
| g &quot;id&quot; &quot;primary_key&quot; \
| g &quot;name&quot; &quot;varchar(100)&quot; \
> .tmp &amp;&amp; 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn