api

package
v0.0.0-...-4af97ca Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package api is a reverse proxy.

It translates gRPC into RESTful JSON APIs.

Index

Constants

View Source
const (
	UrlShortener_Shorten_FullMethodName  = "/api.UrlShortener/Shorten"
	UrlShortener_Redirect_FullMethodName = "/api.UrlShortener/Redirect"
)

Variables

View Source
var File_url_shortener_proto protoreflect.FileDescriptor
View Source
var UrlShortener_ServiceDesc = grpc.ServiceDesc{
	ServiceName: "api.UrlShortener",
	HandlerType: (*UrlShortenerServer)(nil),
	Methods: []grpc.MethodDesc{
		{
			MethodName: "Shorten",
			Handler:    _UrlShortener_Shorten_Handler,
		},
		{
			MethodName: "Redirect",
			Handler:    _UrlShortener_Redirect_Handler,
		},
	},
	Streams:  []grpc.StreamDesc{},
	Metadata: "url-shortener.proto",
}

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

Functions

func RegisterUrlShortenerHandler

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

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

func RegisterUrlShortenerHandlerClient

func RegisterUrlShortenerHandlerClient(ctx context.Context, mux *runtime.ServeMux, client UrlShortenerClient) error

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

func RegisterUrlShortenerHandlerFromEndpoint

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

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

func RegisterUrlShortenerHandlerServer

func RegisterUrlShortenerHandlerServer(ctx context.Context, mux *runtime.ServeMux, server UrlShortenerServer) error

RegisterUrlShortenerHandlerServer registers the http handlers for service UrlShortener to "mux". UnaryRPC :call UrlShortenerServer 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 RegisterUrlShortenerHandlerFromEndpoint instead.

func RegisterUrlShortenerServer

func RegisterUrlShortenerServer(s grpc.ServiceRegistrar, srv UrlShortenerServer)

Types

type RedirectRequest

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

func (*RedirectRequest) Descriptor deprecated

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

Deprecated: Use RedirectRequest.ProtoReflect.Descriptor instead.

func (*RedirectRequest) GetShortedUrl

func (x *RedirectRequest) GetShortedUrl() string

func (*RedirectRequest) ProtoMessage

func (*RedirectRequest) ProtoMessage()

func (*RedirectRequest) ProtoReflect

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

func (*RedirectRequest) Reset

func (x *RedirectRequest) Reset()

func (*RedirectRequest) String

func (x *RedirectRequest) String() string

type RedirectResponse

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

func (*RedirectResponse) Descriptor deprecated

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

Deprecated: Use RedirectResponse.ProtoReflect.Descriptor instead.

func (*RedirectResponse) GetOriginalUrl

func (x *RedirectResponse) GetOriginalUrl() string

func (*RedirectResponse) ProtoMessage

func (*RedirectResponse) ProtoMessage()

func (*RedirectResponse) ProtoReflect

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

func (*RedirectResponse) Reset

func (x *RedirectResponse) Reset()

func (*RedirectResponse) String

func (x *RedirectResponse) String() string

type ShortenRequest

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

func (*ShortenRequest) Descriptor deprecated

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

Deprecated: Use ShortenRequest.ProtoReflect.Descriptor instead.

func (*ShortenRequest) GetOriginalUrl

func (x *ShortenRequest) GetOriginalUrl() string

func (*ShortenRequest) ProtoMessage

func (*ShortenRequest) ProtoMessage()

func (*ShortenRequest) ProtoReflect

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

func (*ShortenRequest) Reset

func (x *ShortenRequest) Reset()

func (*ShortenRequest) String

func (x *ShortenRequest) String() string

type ShortenResponse

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

func (*ShortenResponse) Descriptor deprecated

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

Deprecated: Use ShortenResponse.ProtoReflect.Descriptor instead.

func (*ShortenResponse) GetShortedUrl

func (x *ShortenResponse) GetShortedUrl() string

func (*ShortenResponse) ProtoMessage

func (*ShortenResponse) ProtoMessage()

func (*ShortenResponse) ProtoReflect

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

func (*ShortenResponse) Reset

func (x *ShortenResponse) Reset()

func (*ShortenResponse) String

func (x *ShortenResponse) String() string

type UnimplementedUrlShortenerServer

type UnimplementedUrlShortenerServer struct {
}

UnimplementedUrlShortenerServer must be embedded to have forward compatible implementations.

func (UnimplementedUrlShortenerServer) Redirect

func (UnimplementedUrlShortenerServer) Shorten

type UnsafeUrlShortenerServer

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

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

type UrlShortenerClient

type UrlShortenerClient interface {
	Shorten(ctx context.Context, in *ShortenRequest, opts ...grpc.CallOption) (*ShortenResponse, error)
	Redirect(ctx context.Context, in *RedirectRequest, opts ...grpc.CallOption) (*RedirectResponse, error)
}

UrlShortenerClient is the client API for UrlShortener 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.

type UrlShortenerServer

type UrlShortenerServer interface {
	Shorten(context.Context, *ShortenRequest) (*ShortenResponse, error)
	Redirect(context.Context, *RedirectRequest) (*RedirectResponse, error)
	// contains filtered or unexported methods
}

UrlShortenerServer is the server API for UrlShortener service. All implementations must embed UnimplementedUrlShortenerServer for forward compatibility

Jump to

Keyboard shortcuts

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