hello

package
v0.0.0-...-8e0b234 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2024 License: OSL-3.0 Imports: 6 Imported by: 0

README

Protobuf编解码

参考 Protobuf编解码

IDE(Vscode)

  • vscode-proto3

如果是windows: import "google/protobuf/any.proto"

{
    "protoc": {
        "path": "/path/to/protoc",
        "compile_on_save": false,
        "options": [
            "--proto_path=<google 规范目录, incloude>",
        ]
    }
}

编译

# hello 目录
protoc -I=. --go_out=. hello.proto
# gitee.com/baicaijc/vblog/vblogtest/protobuf/hello"
# gitee.com/baicaijc/vblog/vblogtest
protoc -I=. --go_out=. --go_opt=module="gitee.com/baicaijc/vblog/vblogtest/protobuf/hello" hello.proto

go mod 的项目目录(标准) 在vblogtest 目录下main

protoc -I=. --go_out=. --go_opt=module="gitee.com/baicaijc/vblog/vblogtest" protobuf/hello/hello.proto

  • -I:-IPATH, --proto_path=PATH, 指定proto文件搜索的路径, 如果有多个路径 可以多次使用-I 来指定, 如果不指定默认为当前目录
  • --go_out: --go指插件的名称, 我们安装的插件为: protoc-gen-go, 而protoc-gen是插件命名规范, go是插件名称, 因此这里是--go, 而--go_out 表示的是 go插件的 out参数, 这里指编译产物的存放目录
  • --go_opt: protoc-gen-go插件opt参数, 这里的module指定了go module, 生成的go pkg 会去除掉module路径,生成对应pkg pb/hello.proto: 我们proto文件路径
message QueryBlogRequest {
    // 分页大小, 一个多少个
    // page_size -> PageSize
    int64 page_size = 1;
    // 当前页, 查询哪一页的数据
    int64 page_number = 2;
    // 谁创建的文章
    string create_by = 3;
    // 通过文字名字进行关键字搜索
    string keywords = 4;
}
type QueryBlogRequest struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	// 分页大小, 一个多少个
	// page_size -> PageSize
	PageSize int64 `protobuf:"varint,1,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`
	// 当前页, 查询哪一页的数据
	PageNumber int64 `protobuf:"varint,2,opt,name=page_number,json=pageNumber,proto3" json:"page_number,omitempty"`
	// 谁创建的文章
	CreateBy string `protobuf:"bytes,3,opt,name=create_by,json=createBy,proto3" json:"create_by,omitempty"`
	// 通过文字名字进行关键字搜索
	Keywords string `protobuf:"bytes,4,opt,name=keywords,proto3" json:"keywords,omitempty"`
}
enum STATUS {
    // 草稿
    DRAFT = 0;
    // 已发布
    PUBLISHED = 1;
}
type STATUS int32

const (
	// 草稿
	STATUS_DRAFT STATUS = 0
	// 已发布
	STATUS_PUBLISHED STATUS = 1
)

// Enum value maps for STATUS.
var (
	STATUS_name = map[int32]string{
		0: "DRAFT",
		1: "PUBLISHED",
	}
	STATUS_value = map[string]int32{
		"DRAFT":     0,
		"PUBLISHED": 1,
	}
)
message QueryBlogRequestSet {
    // 多个请求 items : []QueryBlogRequest
    repeated QueryBlogRequest items = 1;
}
type QueryBlogRequestSet struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	// 多个请求 items : []QueryBlogRequest
	Items []*QueryBlogRequest `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"`
}
message Sub1 {
    string name = 1;
}

message Sub2 {
    string name = 1;
}

message SampleMessage {
    oneof test_oneof {
        Sub1 sub1 = 1;
        Sub2 sub2 = 2;
    }
}
// Oneof
type Sub1 struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
}

type Sub2 struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
}

type SampleMessage struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	// Types that are assignable to TestOneof:
	//
	//	*SampleMessage_Sub1
	//	*SampleMessage_Sub2
	TestOneof isSampleMessage_TestOneof `protobuf_oneof:"test_oneof"`
}

type isSampleMessage_TestOneof interface {
	isSampleMessage_TestOneof()
}

type SampleMessage_Sub1 struct {
	Sub1 *Sub1 `protobuf:"bytes,1,opt,name=sub1,proto3,oneof"`
}

type SampleMessage_Sub2 struct {
	Sub2 *Sub2 `protobuf:"bytes,2,opt,name=sub2,proto3,oneof"`
}

func (*SampleMessage_Sub1) isSampleMessage_TestOneof() {}

func (*SampleMessage_Sub2) isSampleMessage_TestOneof() {}

func (x *SampleMessage) GetSub1() *Sub1 {
	if x, ok := x.GetTestOneof().(*SampleMessage_Sub1); ok {
		return x.Sub1
	}
	return nil
}

func (x *SampleMessage) GetSub2() *Sub2 {
	if x, ok := x.GetTestOneof().(*SampleMessage_Sub2); ok {
		return x.Sub2
	}
	return nil
}
Any
// Any
message ErrorStatus {
    string message = 1;
    repeated google.protobuf.Any details = 2;
}
// Any
type ErrorStatus struct {
	state         protoimpl.MessageState
	sizeCache     protoimpl.SizeCache
	unknownFields protoimpl.UnknownFields

	Message string       `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
	Details []*anypb.Any `protobuf:"bytes,2,rep,name=details,proto3" json:"details,omitempty"`
}
# go mod 的项目目录(标准) 在skill 目录下main
# 文件统配
protoc -I=. --go_out=. --go_opt=module="gitee.com/baicaijc/vblog/vblogtest" protobuf/*/*.proto 

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	STATUS_name = map[int32]string{
		0: "DRAFT",
		1: "PUBLISHED",
	}
	STATUS_value = map[string]int32{
		"DRAFT":     0,
		"PUBLISHED": 1,
	}
)

Enum value maps for STATUS.

View Source
var File_protobuf_hello_hello_proto protoreflect.FileDescriptor

Functions

This section is empty.

Types

type ErrorStatus

type ErrorStatus struct {
	Message string       `protobuf:"bytes,1,opt,name=message,proto3" json:"message,omitempty"`
	Details []*anypb.Any `protobuf:"bytes,2,rep,name=details,proto3" json:"details,omitempty"`
	// contains filtered or unexported fields
}

Any

func (*ErrorStatus) Descriptor deprecated

func (*ErrorStatus) Descriptor() ([]byte, []int)

Deprecated: Use ErrorStatus.ProtoReflect.Descriptor instead.

func (*ErrorStatus) GetDetails

func (x *ErrorStatus) GetDetails() []*anypb.Any

func (*ErrorStatus) GetMessage

func (x *ErrorStatus) GetMessage() string

func (*ErrorStatus) ProtoMessage

func (*ErrorStatus) ProtoMessage()

func (*ErrorStatus) ProtoReflect

func (x *ErrorStatus) ProtoReflect() protoreflect.Message

func (*ErrorStatus) Reset

func (x *ErrorStatus) Reset()

func (*ErrorStatus) String

func (x *ErrorStatus) String() string

type QueryBlogRequest

type QueryBlogRequest struct {

	// 分页大小, 一个多少个
	// page_size -> PageSize
	PageRequest *common.PageRequest `protobuf:"bytes,1,opt,name=page_request,json=pageRequest,proto3" json:"page_request,omitempty"`
	// 当前页, 查询哪一页的数据
	PageNumber int64 `protobuf:"varint,2,opt,name=page_number,json=pageNumber,proto3" json:"page_number,omitempty"`
	// 谁创建的文章
	CreateBy string `protobuf:"bytes,3,opt,name=create_by,json=createBy,proto3" json:"create_by,omitempty"`
	// 通过文字名字进行关键字搜索
	Keywords string `protobuf:"bytes,4,opt,name=keywords,proto3" json:"keywords,omitempty"`
	// label   {key=value}
	Label map[string]string `` /* 151-byte string literal not displayed */
	// contains filtered or unexported fields
}

func (*QueryBlogRequest) Descriptor deprecated

func (*QueryBlogRequest) Descriptor() ([]byte, []int)

Deprecated: Use QueryBlogRequest.ProtoReflect.Descriptor instead.

func (*QueryBlogRequest) GetCreateBy

func (x *QueryBlogRequest) GetCreateBy() string

func (*QueryBlogRequest) GetKeywords

func (x *QueryBlogRequest) GetKeywords() string

func (*QueryBlogRequest) GetLabel

func (x *QueryBlogRequest) GetLabel() map[string]string

func (*QueryBlogRequest) GetPageNumber

func (x *QueryBlogRequest) GetPageNumber() int64

func (*QueryBlogRequest) GetPageRequest

func (x *QueryBlogRequest) GetPageRequest() *common.PageRequest

func (*QueryBlogRequest) ProtoMessage

func (*QueryBlogRequest) ProtoMessage()

func (*QueryBlogRequest) ProtoReflect

func (x *QueryBlogRequest) ProtoReflect() protoreflect.Message

func (*QueryBlogRequest) Reset

func (x *QueryBlogRequest) Reset()

func (*QueryBlogRequest) String

func (x *QueryBlogRequest) String() string

type QueryBlogRequestSet

type QueryBlogRequestSet struct {

	// 多个请求 items : []QueryBlogRequest
	Items []*QueryBlogRequest `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"`
	// contains filtered or unexported fields
}

func (*QueryBlogRequestSet) Descriptor deprecated

func (*QueryBlogRequestSet) Descriptor() ([]byte, []int)

Deprecated: Use QueryBlogRequestSet.ProtoReflect.Descriptor instead.

func (*QueryBlogRequestSet) GetItems

func (x *QueryBlogRequestSet) GetItems() []*QueryBlogRequest

func (*QueryBlogRequestSet) ProtoMessage

func (*QueryBlogRequestSet) ProtoMessage()

func (*QueryBlogRequestSet) ProtoReflect

func (x *QueryBlogRequestSet) ProtoReflect() protoreflect.Message

func (*QueryBlogRequestSet) Reset

func (x *QueryBlogRequestSet) Reset()

func (*QueryBlogRequestSet) String

func (x *QueryBlogRequestSet) String() string

type STATUS

type STATUS int32
const (
	// 草稿
	STATUS_DRAFT STATUS = 0
	// 已发布
	STATUS_PUBLISHED STATUS = 1
)

func (STATUS) Descriptor

func (STATUS) Descriptor() protoreflect.EnumDescriptor

func (STATUS) Enum

func (x STATUS) Enum() *STATUS

func (STATUS) EnumDescriptor deprecated

func (STATUS) EnumDescriptor() ([]byte, []int)

Deprecated: Use STATUS.Descriptor instead.

func (STATUS) Number

func (x STATUS) Number() protoreflect.EnumNumber

func (STATUS) String

func (x STATUS) String() string

func (STATUS) Type

func (STATUS) Type() protoreflect.EnumType

type SampleMessage

type SampleMessage struct {

	// Types that are assignable to TestOneof:
	//
	//	*SampleMessage_Sub1
	//	*SampleMessage_Sub2
	TestOneof isSampleMessage_TestOneof `protobuf_oneof:"test_oneof"`
	// contains filtered or unexported fields
}

func (*SampleMessage) Descriptor deprecated

func (*SampleMessage) Descriptor() ([]byte, []int)

Deprecated: Use SampleMessage.ProtoReflect.Descriptor instead.

func (*SampleMessage) GetSub1

func (x *SampleMessage) GetSub1() *Sub1

func (*SampleMessage) GetSub2

func (x *SampleMessage) GetSub2() *Sub2

func (*SampleMessage) GetTestOneof

func (m *SampleMessage) GetTestOneof() isSampleMessage_TestOneof

func (*SampleMessage) ProtoMessage

func (*SampleMessage) ProtoMessage()

func (*SampleMessage) ProtoReflect

func (x *SampleMessage) ProtoReflect() protoreflect.Message

func (*SampleMessage) Reset

func (x *SampleMessage) Reset()

func (*SampleMessage) String

func (x *SampleMessage) String() string

type SampleMessage_Sub1

type SampleMessage_Sub1 struct {
	Sub1 *Sub1 `protobuf:"bytes,1,opt,name=sub1,proto3,oneof"`
}

type SampleMessage_Sub2

type SampleMessage_Sub2 struct {
	Sub2 *Sub2 `protobuf:"bytes,2,opt,name=sub2,proto3,oneof"`
}

type String

type String struct {
	Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"`
	// contains filtered or unexported fields
}

func (*String) Descriptor deprecated

func (*String) Descriptor() ([]byte, []int)

Deprecated: Use String.ProtoReflect.Descriptor instead.

func (*String) GetValue

func (x *String) GetValue() string

func (*String) ProtoMessage

func (*String) ProtoMessage()

func (*String) ProtoReflect

func (x *String) ProtoReflect() protoreflect.Message

func (*String) Reset

func (x *String) Reset()

func (*String) String

func (x *String) String() string

type Sub1

type Sub1 struct {
	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	// contains filtered or unexported fields
}

Oneof

func (*Sub1) Descriptor deprecated

func (*Sub1) Descriptor() ([]byte, []int)

Deprecated: Use Sub1.ProtoReflect.Descriptor instead.

func (*Sub1) GetName

func (x *Sub1) GetName() string

func (*Sub1) ProtoMessage

func (*Sub1) ProtoMessage()

func (*Sub1) ProtoReflect

func (x *Sub1) ProtoReflect() protoreflect.Message

func (*Sub1) Reset

func (x *Sub1) Reset()

func (*Sub1) String

func (x *Sub1) String() string

type Sub2

type Sub2 struct {
	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
	// contains filtered or unexported fields
}

func (*Sub2) Descriptor deprecated

func (*Sub2) Descriptor() ([]byte, []int)

Deprecated: Use Sub2.ProtoReflect.Descriptor instead.

func (*Sub2) GetName

func (x *Sub2) GetName() string

func (*Sub2) ProtoMessage

func (*Sub2) ProtoMessage()

func (*Sub2) ProtoReflect

func (x *Sub2) ProtoReflect() protoreflect.Message

func (*Sub2) Reset

func (x *Sub2) Reset()

func (*Sub2) String

func (x *Sub2) String() string

Jump to

Keyboard shortcuts

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