gidpb

package
v0.0.0-...-5c62cfe Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package gidpb is a reverse proxy.

It translates gRPC into RESTful JSON APIs.

Index

Constants

View Source
const (
	Id_Generate_FullMethodName   = "/gid.Id/Generate"
	Id_TypeStream_FullMethodName = "/gid.Id/TypeStream"
	Id_Types_FullMethodName      = "/gid.Id/Types"
)

Variables

View Source
var (
	SrvCode_name = map[int32]string{
		0:   "OK",
		100: "IDGenerateFailed",
	}
	SrvCode_value = map[string]int32{
		"OK":               0,
		"IDGenerateFailed": 100,
	}
)

Enum value maps for SrvCode.

View Source
var (
	GenType_name = map[int32]string{
		0: "default",
		1: "uuid",
		2: "snowflake",
		3: "bigflake",
		4: "shortid",
	}
	GenType_value = map[string]int32{
		"default":   0,
		"uuid":      1,
		"snowflake": 2,
		"bigflake":  3,
		"shortid":   4,
	}
)

Enum value maps for GenType.

View Source
var ErrCodeIDGenerateFailed = &errorpb.ErrCode{
	BizCode: int32(100),
	Code:    errorpb.Code_Internal,
	Name:    "gid.err_code.id_generate_failed",
	Reason:  "id generate error",
}
View Source
var ErrCodeOK = &errorpb.ErrCode{
	BizCode: int32(0),
	Code:    errorpb.Code_OK,
	Name:    "gid.err_code.ok",
	Reason:  "ok",
}
View Source
var File_gid_id_proto protoreflect.FileDescriptor
View Source
var Id_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "gid.Id",
	HandlerType: (*IdServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "Generate",
			Handler:    _Id_Generate_Handler,
		},
		{
			MethodName: "Types",
			Handler:    _Id_Types_Handler,
		},
	},
	Streams: []grpc.StreamDesc{
		{
			StreamName:    "TypeStream",
			Handler:       _Id_TypeStream_Handler,
			ServerStreams: true,
		},
	},
	Metadata: "gid/id.proto",
}

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

Functions

func RegisterIdHandler

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

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

func RegisterIdHandlerClient

func RegisterIdHandlerClient(ctx context.Context, mux *runtime.ServeMux, client IdClient) error

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

func RegisterIdHandlerFromEndpoint

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

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

func RegisterIdHandlerServer

func RegisterIdHandlerServer(ctx context.Context, mux *runtime.ServeMux, server IdServer) error

RegisterIdHandlerServer registers the http handlers for service Id to "mux". UnaryRPC :call IdServer 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 RegisterIdHandlerFromEndpoint instead.

func RegisterIdServer

func RegisterIdServer(s grpc.ServiceRegistrar, srv IdServer)

Types

type GenType

type GenType int32
const (
	GenType_default   GenType = 0
	GenType_uuid      GenType = 1
	GenType_snowflake GenType = 2
	GenType_bigflake  GenType = 3
	GenType_shortid   GenType = 4
)

func (GenType) Descriptor

func (GenType) Descriptor() protoreflect.EnumDescriptor

func (GenType) Enum

func (x GenType) Enum() *GenType

func (GenType) EnumDescriptor deprecated

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

Deprecated: Use GenType.Descriptor instead.

func (GenType) Number

func (x GenType) Number() protoreflect.EnumNumber

func (GenType) String

func (x GenType) String() string

func (GenType) Type

func (GenType) Type() protoreflect.EnumType

type GenerateRequest

type GenerateRequest struct {

	// type of id e.g uuid, shortid, snowflake (64 bit), bigflake (128 bit)
	Type GenType `protobuf:"varint,1,opt,name=type,proto3,enum=gid.GenType" json:"type,omitempty"`
	// contains filtered or unexported fields
}

Generate a unique ID. Defaults to uuid.

func (*GenerateRequest) Descriptor deprecated

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

Deprecated: Use GenerateRequest.ProtoReflect.Descriptor instead.

func (*GenerateRequest) GetType

func (x *GenerateRequest) GetType() GenType

func (*GenerateRequest) ProtoMessage

func (*GenerateRequest) ProtoMessage()

func (*GenerateRequest) ProtoReflect

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

func (*GenerateRequest) Reset

func (x *GenerateRequest) Reset()

func (*GenerateRequest) String

func (x *GenerateRequest) String() string

type GenerateResponse

type GenerateResponse struct {

	// the unique id generated
	Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	// the type of id generated
	Type string `protobuf:"bytes,2,opt,name=type,proto3" json:"type,omitempty"`
	// contains filtered or unexported fields
}

func (*GenerateResponse) Descriptor deprecated

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

Deprecated: Use GenerateResponse.ProtoReflect.Descriptor instead.

func (*GenerateResponse) GetId

func (x *GenerateResponse) GetId() string

func (*GenerateResponse) GetType

func (x *GenerateResponse) GetType() string

func (*GenerateResponse) ProtoMessage

func (*GenerateResponse) ProtoMessage()

func (*GenerateResponse) ProtoReflect

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

func (*GenerateResponse) Reset

func (x *GenerateResponse) Reset()

func (*GenerateResponse) String

func (x *GenerateResponse) String() string

type IdClient

type IdClient interface {
	// Generate 生成ID
	Generate(ctx context.Context, in *GenerateRequest, opts ...grpc.CallOption) (*GenerateResponse, error)
	TypeStream(ctx context.Context, in *TypesRequest, opts ...grpc.CallOption) (Id_TypeStreamClient, error)
	// Types id类型
	Types(ctx context.Context, in *TypesRequest, opts ...grpc.CallOption) (*TypesResponse, error)
}

IdClient is the client API for Id 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 NewIdClient

func NewIdClient(cc grpc.ClientConnInterface) IdClient

type IdServer

type IdServer interface {
	// Generate 生成ID
	Generate(context.Context, *GenerateRequest) (*GenerateResponse, error)
	TypeStream(*TypesRequest, Id_TypeStreamServer) error
	// Types id类型
	Types(context.Context, *TypesRequest) (*TypesResponse, error)
}

IdServer is the server API for Id service. All implementations should embed UnimplementedIdServer for forward compatibility

type Id_TypeStreamClient

type Id_TypeStreamClient interface {
	Recv() (*TypesResponse, error)
	grpc.ClientStream
}

type Id_TypeStreamServer

type Id_TypeStreamServer interface {
	Send(*TypesResponse) error
	grpc.ServerStream
}

type SrvCode

type SrvCode int32
const (
	SrvCode_OK SrvCode = 0
	// id generate error
	SrvCode_IDGenerateFailed SrvCode = 100
)

func (SrvCode) Descriptor

func (SrvCode) Descriptor() protoreflect.EnumDescriptor

func (SrvCode) Enum

func (x SrvCode) Enum() *SrvCode

func (SrvCode) EnumDescriptor deprecated

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

Deprecated: Use SrvCode.Descriptor instead.

func (SrvCode) Number

func (x SrvCode) Number() protoreflect.EnumNumber

func (SrvCode) String

func (x SrvCode) String() string

func (SrvCode) Type

func (SrvCode) Type() protoreflect.EnumType

type TypesRequest

type TypesRequest struct {
	// contains filtered or unexported fields
}

List the types of IDs available. No query params needed.

func (*TypesRequest) Descriptor deprecated

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

Deprecated: Use TypesRequest.ProtoReflect.Descriptor instead.

func (*TypesRequest) ProtoMessage

func (*TypesRequest) ProtoMessage()

func (*TypesRequest) ProtoReflect

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

func (*TypesRequest) Reset

func (x *TypesRequest) Reset()

func (*TypesRequest) String

func (x *TypesRequest) String() string

type TypesResponse

type TypesResponse struct {
	Types []string `protobuf:"bytes,1,rep,name=types,proto3" json:"types,omitempty"`
	// contains filtered or unexported fields
}

TypesResponse 返回值类型

func (*TypesResponse) Descriptor deprecated

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

Deprecated: Use TypesResponse.ProtoReflect.Descriptor instead.

func (*TypesResponse) GetTypes

func (x *TypesResponse) GetTypes() []string

func (*TypesResponse) ProtoMessage

func (*TypesResponse) ProtoMessage()

func (*TypesResponse) ProtoReflect

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

func (*TypesResponse) Reset

func (x *TypesResponse) Reset()

func (*TypesResponse) String

func (x *TypesResponse) String() string

type UnimplementedIdServer

type UnimplementedIdServer struct {
}

UnimplementedIdServer should be embedded to have forward compatible implementations.

func (UnimplementedIdServer) Generate

func (UnimplementedIdServer) TypeStream

func (UnimplementedIdServer) Types

type UnsafeIdServer

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

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

Jump to

Keyboard shortcuts

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