protobuf

module
v0.0.0-...-35254e1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2018 License: BSD-3-Clause

README

安装

// 安装对应平台的 protoc 工具
MaxOS:
brew install protobuf

Linux:
https://github.com/google/protobuf/releases

// 下载 go 语言对应的生成器
go get -v -u code.aliyun.com/kaoyaya.com/protobuf/{proto,protoc-gen-go}

// 安装生成器
go install $GOPATH/src/code.aliyun.com/kaoyaya.com/protobuf/protoc-gen-go

自定义标签 Retag

编译时需要指定 --go_out=plugins=micro+retag 插件名。

使用只需要在字段后面加上 // tag 内容

message Staff {
    string ID = 1;    //`json:"id,omitempty"   xml:"id,omitempty"`
    string Name = 2;  //`json:"name,omitempty" xml:"name,omitempty"`
    int64 Age = 3;    //`json:"age,omitempty"  xml:"age,omitempty"`
}

output:

type Staff struct {
    ID   string `protobuf:"bytes,1,opt,name=ID"     json:"id,omitempty"    xml:"id,omitempty"`
    Name string `protobuf:"bytes,2,opt,name=Name"   json:"name,omitempty"  xml:"name,omitempty"`
    Age  int64  `protobuf:"varint,3,opt,name=Age"   json:"age,omitempty"   xml:"age,omitempty"`
}

Makefile

micro 插件后面添加 retag 插件。

protos:
	for d in $(shell ls -d proto/*); do \
		for f in $$d/*.proto; do \
			protoc --go_out=plugins=micro+retag:. $$f; \
			echo compiled: $$f; \
		done \
	done

Debug

protoc  --go_out=plugins=micro+retag:. test.proto

Directories

Path Synopsis
conformance implements the conformance test subprocess protocol as documented in conformance.proto.
conformance implements the conformance test subprocess protocol as documented in conformance.proto.
conformance_proto
Package conformance is a generated protocol buffer package.
Package conformance is a generated protocol buffer package.
Package descriptor provides functions for obtaining protocol buffer descriptors for generated Go types.
Package descriptor provides functions for obtaining protocol buffer descriptors for generated Go types.
Package jsonpb provides marshaling and unmarshaling between protocol buffers and JSON.
Package jsonpb provides marshaling and unmarshaling between protocol buffers and JSON.
jsonpb_test_proto
Package jsonpb is a generated protocol buffer package.
Package jsonpb is a generated protocol buffer package.
Package proto converts data structures to and from the wire format of protocol buffers.
Package proto converts data structures to and from the wire format of protocol buffers.
proto3_proto
Package proto3_proto is a generated protocol buffer package.
Package proto3_proto is a generated protocol buffer package.
protoc-gen-go
descriptor
Package descriptor is a generated protocol buffer package.
Package descriptor is a generated protocol buffer package.
generator
The code generator for the plugin for the Google protocol buffer compiler.
The code generator for the plugin for the Google protocol buffer compiler.
grpc
Package grpc outputs gRPC service descriptions in Go code.
Package grpc outputs gRPC service descriptions in Go code.
plugin
Package plugin_go is a generated protocol buffer package.
Package plugin_go is a generated protocol buffer package.
retag/example
Package staff is a generated protocol buffer package.
Package staff is a generated protocol buffer package.
Package ptypes contains code for interacting with well-known types.
Package ptypes contains code for interacting with well-known types.
any
Package any is a generated protocol buffer package.
Package any is a generated protocol buffer package.
duration
Package duration is a generated protocol buffer package.
Package duration is a generated protocol buffer package.
empty
Package empty is a generated protocol buffer package.
Package empty is a generated protocol buffer package.
struct
Package structpb is a generated protocol buffer package.
Package structpb is a generated protocol buffer package.
timestamp
Package timestamp is a generated protocol buffer package.
Package timestamp is a generated protocol buffer package.
wrappers
Package wrappers is a generated protocol buffer package.
Package wrappers is a generated protocol buffer package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL