demopb

package
v0.0.0-...-0bd687e Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2022 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

Package demopb is a reverse proxy.

It translates gRPC into RESTful JSON APIs.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWrongArgType  = errors.New("wrong argument type for this method")
	ErrUnknownMethod = errors.New("unknown method name")
	ErrEmptyResponse = errors.New("empty response to register")
)
View Source
var (
	Person_Type_name = map[int32]string{
		0: "unknown_type",
		1: "individual",
		2: "company",
	}
	Person_Type_value = map[string]int32{
		"unknown_type": 0,
		"individual":   1,
		"company":      2,
	}
)

Enum value maps for Person_Type.

View Source
var (
	Person_Animal_name = map[int32]string{
		0: "unknown_animal",
		1: "cat",
		2: "dog",
		3: "parrot",
		4: "mouse",
		5: "capybara",
		6: "giraffe",
		7: "sheep",
	}
	Person_Animal_value = map[string]int32{
		"unknown_animal": 0,
		"cat":            1,
		"dog":            2,
		"parrot":         3,
		"mouse":          4,
		"capybara":       5,
		"giraffe":        6,
		"sheep":          7,
	}
)

Enum value maps for Person_Animal.

View Source
var Api_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "demopb.Api",
	HandlerType: (*ApiServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "ListPersons",
			Handler:    _Api_ListPersons_Handler,
		},
		{
			MethodName: "GetPerson",
			Handler:    _Api_GetPerson_Handler,
		},
		{
			MethodName: "CreatePerson",
			Handler:    _Api_CreatePerson_Handler,
		},
		{
			MethodName: "DeletePerson",
			Handler:    _Api_DeletePerson_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "demo.proto",
}

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

Functions

func RegisterApiHandler

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

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

func RegisterApiHandlerClient

func RegisterApiHandlerClient(ctx context.Context, mux *runtime.ServeMux, client ApiClient) error

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

func RegisterApiHandlerFromEndpoint

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

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

func RegisterApiHandlerServer

func RegisterApiHandlerServer(ctx context.Context, mux *runtime.ServeMux, server ApiServer) error

RegisterApiHandlerServer registers the http handlers for service Api to "mux". UnaryRPC :call ApiServer 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 RegisterApiHandlerFromEndpoint instead.

func RegisterApiServer

func RegisterApiServer(s grpc.ServiceRegistrar, srv ApiServer)

Types

type ApiClient

type ApiClient interface {
	// ListPersons lists the persons present in the database.
	ListPersons(ctx context.Context, in *ListPersonsRequest, opts ...grpc.CallOption) (*ListPersonsResponse, error)
	// GetPerson retrives one person from the database.
	GetPerson(ctx context.Context, in *GetPersonRequest, opts ...grpc.CallOption) (*Person, error)
	// CreatePerson creates a new person and stores it in the database.
	CreatePerson(ctx context.Context, in *CreatePersonRequest, opts ...grpc.CallOption) (*Person, error)
	// DeletePerson remove a person from the database
	DeletePerson(ctx context.Context, in *DeletePersonRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
}

ApiClient is the client API for Api 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 NewApiClient

func NewApiClient(cc grpc.ClientConnInterface) ApiClient

type ApiServer

type ApiServer interface {
	// ListPersons lists the persons present in the database.
	ListPersons(context.Context, *ListPersonsRequest) (*ListPersonsResponse, error)
	// GetPerson retrives one person from the database.
	GetPerson(context.Context, *GetPersonRequest) (*Person, error)
	// CreatePerson creates a new person and stores it in the database.
	CreatePerson(context.Context, *CreatePersonRequest) (*Person, error)
	// DeletePerson remove a person from the database
	DeletePerson(context.Context, *DeletePersonRequest) (*emptypb.Empty, error)
	// contains filtered or unexported methods
}

ApiServer is the server API for Api service. All implementations must embed UnimplementedApiServer for forward compatibility

type CreatePersonRequest

type CreatePersonRequest struct {
	ProjectId *wrapperspb.StringValue `protobuf:"bytes,1,opt,name=project_id,json=projectId,proto3" json:"project_id,omitempty"`
	Person    *Person                 `protobuf:"bytes,2,opt,name=person,proto3" json:"person,omitempty"`
	// contains filtered or unexported fields
}

func (*CreatePersonRequest) Descriptor deprecated

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

Deprecated: Use CreatePersonRequest.ProtoReflect.Descriptor instead.

func (*CreatePersonRequest) GetPerson

func (x *CreatePersonRequest) GetPerson() *Person

func (*CreatePersonRequest) GetProjectId

func (x *CreatePersonRequest) GetProjectId() *wrapperspb.StringValue

func (*CreatePersonRequest) ProtoMessage

func (*CreatePersonRequest) ProtoMessage()

func (*CreatePersonRequest) ProtoReflect

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

func (*CreatePersonRequest) Reset

func (x *CreatePersonRequest) Reset()

func (*CreatePersonRequest) String

func (x *CreatePersonRequest) String() string

type DeletePersonRequest

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

func (*DeletePersonRequest) Descriptor deprecated

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

Deprecated: Use DeletePersonRequest.ProtoReflect.Descriptor instead.

func (*DeletePersonRequest) GetPersonId

func (x *DeletePersonRequest) GetPersonId() string

func (*DeletePersonRequest) ProtoMessage

func (*DeletePersonRequest) ProtoMessage()

func (*DeletePersonRequest) ProtoReflect

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

func (*DeletePersonRequest) Reset

func (x *DeletePersonRequest) Reset()

func (*DeletePersonRequest) String

func (x *DeletePersonRequest) String() string

type GetPersonRequest

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

func (*GetPersonRequest) Descriptor deprecated

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

Deprecated: Use GetPersonRequest.ProtoReflect.Descriptor instead.

func (*GetPersonRequest) GetPersonId

func (x *GetPersonRequest) GetPersonId() string

func (*GetPersonRequest) ProtoMessage

func (*GetPersonRequest) ProtoMessage()

func (*GetPersonRequest) ProtoReflect

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

func (*GetPersonRequest) Reset

func (x *GetPersonRequest) Reset()

func (*GetPersonRequest) String

func (x *GetPersonRequest) String() string

type ListPersonsRequest

type ListPersonsRequest struct {
	ProjectId *wrapperspb.StringValue `protobuf:"bytes,1,opt,name=project_id,json=projectId,proto3" json:"project_id,omitempty"`
	// page is an optional field to get a particular page in listings
	Page *wrapperspb.Int32Value `protobuf:"bytes,10,opt,name=page,proto3" json:"page,omitempty"`
	// page_size is an optional field to set the page size in listings
	PageSize *wrapperspb.Int32Value `protobuf:"bytes,11,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`
	// contains filtered or unexported fields
}

ListPersonRequests is the request to list the content of the database

func (*ListPersonsRequest) Descriptor deprecated

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

Deprecated: Use ListPersonsRequest.ProtoReflect.Descriptor instead.

func (*ListPersonsRequest) GetPage

func (*ListPersonsRequest) GetPageSize

func (x *ListPersonsRequest) GetPageSize() *wrapperspb.Int32Value

func (*ListPersonsRequest) GetProjectId

func (x *ListPersonsRequest) GetProjectId() *wrapperspb.StringValue

func (*ListPersonsRequest) ProtoMessage

func (*ListPersonsRequest) ProtoMessage()

func (*ListPersonsRequest) ProtoReflect

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

func (*ListPersonsRequest) Reset

func (x *ListPersonsRequest) Reset()

func (*ListPersonsRequest) String

func (x *ListPersonsRequest) String() string

type ListPersonsResponse

type ListPersonsResponse struct {
	Persons    []*Person `protobuf:"bytes,1,rep,name=persons,proto3" json:"persons,omitempty"`
	TotalCount uint32    `protobuf:"varint,10,opt,name=total_count,json=totalCount,proto3" json:"total_count,omitempty"`
	// contains filtered or unexported fields
}

ListPersonsReponse is the result sent back from the listing

func (*ListPersonsResponse) Descriptor deprecated

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

Deprecated: Use ListPersonsResponse.ProtoReflect.Descriptor instead.

func (*ListPersonsResponse) GetPersons

func (x *ListPersonsResponse) GetPersons() []*Person

func (*ListPersonsResponse) GetTotalCount

func (x *ListPersonsResponse) GetTotalCount() uint32

func (*ListPersonsResponse) ProtoMessage

func (*ListPersonsResponse) ProtoMessage()

func (*ListPersonsResponse) ProtoReflect

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

func (*ListPersonsResponse) Reset

func (x *ListPersonsResponse) Reset()

func (*ListPersonsResponse) String

func (x *ListPersonsResponse) String() string

type MockApiServer

type MockApiServer struct {
	UnimplementedApiServer
	// contains filtered or unexported fields
}

func RegisterMockApiServer

func RegisterMockApiServer(s grpc.ServiceRegistrar) *MockApiServer

func (*MockApiServer) CreatePerson

func (ms *MockApiServer) CreatePerson(ctx context.Context, req *CreatePersonRequest) (*Person, error)

func (*MockApiServer) DeletePerson

func (ms *MockApiServer) DeletePerson(ctx context.Context, req *DeletePersonRequest) (*emptypb.Empty, error)

func (*MockApiServer) GetPerson

func (ms *MockApiServer) GetPerson(ctx context.Context, req *GetPersonRequest) (*Person, error)

func (*MockApiServer) ListPersons

func (*MockApiServer) RegisterJSONMockContent

func (ms *MockApiServer) RegisterJSONMockContent(method string, payload []byte) error

RegisterJSONMockContent registers a JSON string as a Mock content, making sure that the format is respected

func (*MockApiServer) RegisterJSONMockStatus

func (ms *MockApiServer) RegisterJSONMockStatus(method string, payload []byte) error

RegisterJSONMockStatus registers a JSON string as a Mock status, making sure that the format is respected

func (*MockApiServer) RegisterMockCallback

func (ms *MockApiServer) RegisterMockCallback(method string, callback func(*MockApiServer)) error

RegisterMockCallback registers a callback that is called after method invocation.

func (*MockApiServer) RegisterMockResponse

func (ms *MockApiServer) RegisterMockResponse(method string, response any) error

RegisterMockResponse registers a response that is returned at method invocation.

type Person

type Person struct {
	Id          string            `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	Name        string            `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
	Email       string            `protobuf:"bytes,3,opt,name=email,proto3" json:"email,omitempty"`
	Type        Person_Type       `protobuf:"varint,4,opt,name=type,proto3,enum=demopb.Person_Type" json:"type,omitempty"`
	Attributes  map[string]string `` /* 161-byte string literal not displayed */
	Hardware    string            `protobuf:"bytes,6,opt,name=hardware,proto3" json:"hardware,omitempty"`
	Planet      string            `protobuf:"bytes,7,opt,name=planet,proto3" json:"planet,omitempty"`
	PlanetId    uint32            `protobuf:"varint,8,opt,name=planet_id,json=planetId,proto3" json:"planet_id,omitempty"`
	PlanetIdStr string            `protobuf:"bytes,9,opt,name=planet_id_str,json=planetIdStr,proto3" json:"planet_id_str,omitempty"`
	Freeform    string            `protobuf:"bytes,10,opt,name=freeform,proto3" json:"freeform,omitempty"`
	Active      bool              `protobuf:"varint,11,opt,name=active,proto3" json:"active,omitempty"`
	Animal      Person_Animal     `protobuf:"varint,12,opt,name=animal,proto3,enum=demopb.Person_Animal" json:"animal,omitempty"`
	// contains filtered or unexported fields
}

Person represents a person

func (*Person) Descriptor deprecated

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

Deprecated: Use Person.ProtoReflect.Descriptor instead.

func (*Person) GetActive

func (x *Person) GetActive() bool

func (*Person) GetAnimal

func (x *Person) GetAnimal() Person_Animal

func (*Person) GetAttributes

func (x *Person) GetAttributes() map[string]string

func (*Person) GetEmail

func (x *Person) GetEmail() string

func (*Person) GetFreeform

func (x *Person) GetFreeform() string

func (*Person) GetHardware

func (x *Person) GetHardware() string

func (*Person) GetId

func (x *Person) GetId() string

func (*Person) GetName

func (x *Person) GetName() string

func (*Person) GetPlanet

func (x *Person) GetPlanet() string

func (*Person) GetPlanetId

func (x *Person) GetPlanetId() uint32

func (*Person) GetPlanetIdStr

func (x *Person) GetPlanetIdStr() string

func (*Person) GetType

func (x *Person) GetType() Person_Type

func (*Person) ProtoMessage

func (*Person) ProtoMessage()

func (*Person) ProtoReflect

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

func (*Person) Reset

func (x *Person) Reset()

func (*Person) String

func (x *Person) String() string

type Person_Animal

type Person_Animal int32
const (
	Person_unknown_animal Person_Animal = 0
	Person_cat            Person_Animal = 1
	Person_dog            Person_Animal = 2
	Person_parrot         Person_Animal = 3
	Person_mouse          Person_Animal = 4
	Person_capybara       Person_Animal = 5
	Person_giraffe        Person_Animal = 6
	Person_sheep          Person_Animal = 7
)

func (Person_Animal) Descriptor

func (Person_Animal) Enum

func (x Person_Animal) Enum() *Person_Animal

func (Person_Animal) EnumDescriptor deprecated

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

Deprecated: Use Person_Animal.Descriptor instead.

func (Person_Animal) Number

func (Person_Animal) String

func (x Person_Animal) String() string

func (Person_Animal) Type

type Person_Type

type Person_Type int32
const (
	Person_unknown_type Person_Type = 0
	Person_individual   Person_Type = 1
	Person_company      Person_Type = 2
)

func (Person_Type) Descriptor

func (Person_Type) Enum

func (x Person_Type) Enum() *Person_Type

func (Person_Type) EnumDescriptor deprecated

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

Deprecated: Use Person_Type.Descriptor instead.

func (Person_Type) Number

func (x Person_Type) Number() protoreflect.EnumNumber

func (Person_Type) String

func (x Person_Type) String() string

func (Person_Type) Type

type UnimplementedApiServer

type UnimplementedApiServer struct {
}

UnimplementedApiServer must be embedded to have forward compatible implementations.

func (UnimplementedApiServer) CreatePerson

func (UnimplementedApiServer) DeletePerson

func (UnimplementedApiServer) GetPerson

func (UnimplementedApiServer) ListPersons

type UnsafeApiServer

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

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

Jump to

Keyboard shortcuts

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