comment

package
v0.0.0-...-f4276bb Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2023 License: MIT Imports: 8 Imported by: 0

README

实现一个业务模块 同时支持 grpc接口实现与restful接口实现

// workspace目录:  /e/Projects/Golang/go11
protoc -I=. --go_out=. --go-grpc_out=. --go_opt=module="gitee.com/go-course/go11" --go-grpc_opt=module="gitee.com/go-course/go11" vblog/apps/*/pb/*.proto

protobuf自定义标签

  1. 安装自定义proto tag插件
go install github.com/favadi/protoc-go-inject-tag@latest
  1. 补充tag
message Comment {
    // 博客Id
    int64 blog_id = 1;
    // 文章具体的定义
    // @gotags: gorm:"embedded" json:"spec" bson:",inline"
    CreateCommentRequest spec = 2;
}
  1. 标签生成

正常生成

// workspace目录:  /e/Projects/Golang/go11
protoc -I=. --go_out=. --go-grpc_out=. --go_opt=module="gitee.com/go-course/go11" --go-grpc_opt=module="gitee.com/go-course/go11" vblog/apps/*/pb/*.proto
protoc-go-inject-tag -input="vblog/apps/*/*.pb.go"

Documentation

Index

Constants

View Source
const (
	AppName = "comment"
)
View Source
const (
	Rpc_CreateComment_FullMethodName = "/go11.vblog.comment.Rpc/CreateComment"
)

Variables

View Source
var File_vblog_apps_comment_pb_model_proto protoreflect.FileDescriptor
View Source
var File_vblog_apps_comment_pb_service_proto protoreflect.FileDescriptor
View Source
var Rpc_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "go11.vblog.comment.Rpc",
	HandlerType: (*RpcServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "CreateComment",
			Handler:    _Rpc_CreateComment_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "vblog/apps/comment/pb/service.proto",
}

Rpc_ServiceDesc is the grpc.ServiceDesc for Rpc service. It's only intended for direct use with grpc.RegisterService, and not to be introspected or modified (even as a copy)

Functions

func RegisterRpcServer

func RegisterRpcServer(s grpc.ServiceRegistrar, srv RpcServer)

Types

type Comment

type Comment struct {

	// 博客Id
	BlogId int64 `protobuf:"varint,1,opt,name=blog_id,json=blogId,proto3" json:"blog_id,omitempty"`
	// 文章具体的定义
	// @gotags: gorm:"embedded" json:"spec" bson:",inline"
	Spec *CreateCommentRequest `protobuf:"bytes,2,opt,name=spec,proto3" json:"spec" gorm:"embedded" bson:",inline"`
	// contains filtered or unexported fields
}

func (*Comment) Descriptor deprecated

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

Deprecated: Use Comment.ProtoReflect.Descriptor instead.

func (*Comment) GetBlogId

func (x *Comment) GetBlogId() int64

func (*Comment) GetSpec

func (x *Comment) GetSpec() *CreateCommentRequest

func (*Comment) ProtoMessage

func (*Comment) ProtoMessage()

func (*Comment) ProtoReflect

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

func (*Comment) Reset

func (x *Comment) Reset()

func (*Comment) String

func (x *Comment) String() string

type CreateCommentRequest

type CreateCommentRequest struct {

	// 用户Id
	UserId int64 `protobuf:"varint,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
	// 文章内容, 支持Markdown格式
	Content string `protobuf:"bytes,3,opt,name=content,proto3" json:"content,omitempty"`
	// contains filtered or unexported fields
}

func (*CreateCommentRequest) Descriptor deprecated

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

Deprecated: Use CreateCommentRequest.ProtoReflect.Descriptor instead.

func (*CreateCommentRequest) GetContent

func (x *CreateCommentRequest) GetContent() string

func (*CreateCommentRequest) GetUserId

func (x *CreateCommentRequest) GetUserId() int64

func (*CreateCommentRequest) ProtoMessage

func (*CreateCommentRequest) ProtoMessage()

func (*CreateCommentRequest) ProtoReflect

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

func (*CreateCommentRequest) Reset

func (x *CreateCommentRequest) Reset()

func (*CreateCommentRequest) String

func (x *CreateCommentRequest) String() string

type RpcClient

type RpcClient interface {
	CreateComment(ctx context.Context, in *CreateCommentRequest, opts ...grpc.CallOption) (*Comment, error)
}

RpcClient is the client API for Rpc service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

func NewRpcClient

func NewRpcClient(cc grpc.ClientConnInterface) RpcClient

type RpcServer

type RpcServer interface {
	CreateComment(context.Context, *CreateCommentRequest) (*Comment, error)
	// contains filtered or unexported methods
}

RpcServer is the server API for Rpc service. All implementations must embed UnimplementedRpcServer for forward compatibility

type UnimplementedRpcServer

type UnimplementedRpcServer struct {
}

UnimplementedRpcServer must be embedded to have forward compatible implementations.

func (UnimplementedRpcServer) CreateComment

type UnsafeRpcServer

type UnsafeRpcServer interface {
	// contains filtered or unexported methods
}

UnsafeRpcServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to RpcServer will result in compilation errors.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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