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

Mary-Kate Olsen
Release: 2024-10-27 03:54:30
Original
889 people have browsed it

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

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!