pb

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2025 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package pb is a reverse proxy.

It translates gRPC into RESTful JSON APIs.

Index

Constants

View Source
const (
	Greeter_SayHello_FullMethodName = "/App.Grpc.Hello.Greeter/SayHello"
	Greeter_Info_FullMethodName     = "/App.Grpc.Hello.Greeter/Info"
)

Variables

View Source
var File_hello_proto protoreflect.FileDescriptor
View Source
var Greeter_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "App.Grpc.Hello.Greeter",
	HandlerType: (*GreeterServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "SayHello",
			Handler:    _Greeter_SayHello_Handler,
		},
		{
			MethodName: "Info",
			Handler:    _Greeter_Info_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "hello.proto",
}

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

Functions

func RegisterGreeterHandler

func RegisterGreeterHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error

RegisterGreeterHandler registers the http handlers for service Greeter to "mux". The handlers forward requests to the grpc endpoint over "conn".

func RegisterGreeterHandlerClient

func RegisterGreeterHandlerClient(ctx context.Context, mux *runtime.ServeMux, client GreeterClient) error

RegisterGreeterHandlerClient registers the http handlers for service Greeter to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "GreeterClient". Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "GreeterClient" doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in "GreeterClient" to call the correct interceptors. This client ignores the HTTP middlewares.

func RegisterGreeterHandlerFromEndpoint

func RegisterGreeterHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error)

RegisterGreeterHandlerFromEndpoint is same as RegisterGreeterHandler but automatically dials to "endpoint" and closes the connection when "ctx" gets done.

func RegisterGreeterHandlerServer

func RegisterGreeterHandlerServer(ctx context.Context, mux *runtime.ServeMux, server GreeterServer) error

RegisterGreeterHandlerServer registers the http handlers for service Greeter to "mux". UnaryRPC :call GreeterServer directly. StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterGreeterHandlerFromEndpoint instead. GRPC interceptors will not work for this type of registration. To use interceptors, you must use the "runtime.WithMiddlewares" option in the "runtime.NewServeMux" call.

func RegisterGreeterServer

func RegisterGreeterServer(s grpc.ServiceRegistrar, srv GreeterServer)

Types

type GreeterClient

type GreeterClient interface {
	SayHello(ctx context.Context, in *HelloReq, opts ...grpc.CallOption) (*HelloReply, error)
	Info(ctx context.Context, in *InfoReq, opts ...grpc.CallOption) (*InfoReply, error)
}

GreeterClient is the client API for Greeter 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.

Greeter service 定义开放调用的服务

func NewGreeterClient

func NewGreeterClient(cc grpc.ClientConnInterface) GreeterClient

type GreeterServer

type GreeterServer interface {
	SayHello(context.Context, *HelloReq) (*HelloReply, error)
	Info(context.Context, *InfoReq) (*InfoReply, error)
	// contains filtered or unexported methods
}

GreeterServer is the server API for Greeter service. All implementations must embed UnimplementedGreeterServer for forward compatibility.

Greeter service 定义开放调用的服务

type HelloReply

type HelloReply struct {

	// @inject_tag: json:"name"
	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name"`
	// @inject_tag: json:"message"
	Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message"`
	// contains filtered or unexported fields
}

定义服务端响应的数据格式

func (*HelloReply) Descriptor deprecated

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

Deprecated: Use HelloReply.ProtoReflect.Descriptor instead.

func (*HelloReply) GetMessage

func (x *HelloReply) GetMessage() string

func (*HelloReply) GetName

func (x *HelloReply) GetName() string

func (*HelloReply) ProtoMessage

func (*HelloReply) ProtoMessage()

func (*HelloReply) ProtoReflect

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

func (*HelloReply) Reset

func (x *HelloReply) Reset()

func (*HelloReply) String

func (x *HelloReply) String() string

type HelloReq

type HelloReq struct {

	// [修饰符] 类型 字段名 = 标识符;
	// @inject_tag: json:"id" validate:"required,min=1"
	Id int64 `protobuf:"varint,1,opt,name=id,proto3" json:"id" validate:"required,min=1"`
	// contains filtered or unexported fields
}

message 对应生成代码的 struct 定义客户端请求的数据格式 @validator=HelloReq

func (*HelloReq) Descriptor deprecated

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

Deprecated: Use HelloReq.ProtoReflect.Descriptor instead.

func (*HelloReq) GetId

func (x *HelloReq) GetId() int64

func (*HelloReq) ProtoMessage

func (*HelloReq) ProtoMessage()

func (*HelloReq) ProtoReflect

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

func (*HelloReq) Reset

func (x *HelloReq) Reset()

func (*HelloReq) String

func (x *HelloReq) String() string

func (*HelloReq) Validate

func (r *HelloReq) Validate() error

Validate HelloReq interceptor validator.

type InfoReply

type InfoReply struct {
	Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"`
	Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"`
	// contains filtered or unexported fields
}

InfoReply info reply

func (*InfoReply) Descriptor deprecated

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

Deprecated: Use InfoReply.ProtoReflect.Descriptor instead.

func (*InfoReply) GetAddress

func (x *InfoReply) GetAddress() string

func (*InfoReply) GetMessage

func (x *InfoReply) GetMessage() string

func (*InfoReply) ProtoMessage

func (*InfoReply) ProtoMessage()

func (*InfoReply) ProtoReflect

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

func (*InfoReply) Reset

func (x *InfoReply) Reset()

func (*InfoReply) String

func (x *InfoReply) String() string

type InfoReq

type InfoReq struct {

	// 主要用于grpc validator参数校验
	// @inject_tag: json:"name" validate:"required,min=1"
	Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name" validate:"required,min=1"`
	// contains filtered or unexported fields
}

@validator=InfoReq

func (*InfoReq) Descriptor deprecated

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

Deprecated: Use InfoReq.ProtoReflect.Descriptor instead.

func (*InfoReq) GetName

func (x *InfoReq) GetName() string

func (*InfoReq) ProtoMessage

func (*InfoReq) ProtoMessage()

func (*InfoReq) ProtoReflect

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

func (*InfoReq) Reset

func (x *InfoReq) Reset()

func (*InfoReq) String

func (x *InfoReq) String() string

func (*InfoReq) Validate

func (r *InfoReq) Validate() error

Validate InfoReq interceptor validator.

type UnimplementedGreeterServer

type UnimplementedGreeterServer struct{}

UnimplementedGreeterServer must be embedded to have forward compatible implementations.

NOTE: this should be embedded by value instead of pointer to avoid a nil pointer dereference when methods are called.

func (UnimplementedGreeterServer) Info

func (UnimplementedGreeterServer) SayHello

type UnsafeGreeterServer

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

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

Jump to

Keyboard shortcuts

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