api

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package api is for building api gateways

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(e *Endpoint) map[string]string

Encode encodes an endpoint to endpoint metadata

func Validate

func Validate(e *Endpoint) error

Validate validates an endpoint to guarantee it won't blow up when being served

func WithEndpoint

func WithEndpoint(e *Endpoint) server.HandlerOption

WithEndpoint returns a server.HandlerOption with endpoint metadata set

Usage:

proto.RegisterHandler(service.Server(), new(Handler), api.WithEndpoint(
	&api.Endpoint{
		Name: "Greeter.Hello",
		Path: []string{"/greeter"},
	},
))

Types

type Api

type Api interface {
	// Initialise options
	Init(...Option) error
	// Get the options
	Options() Options
	// Register an endpoint
	Register(*Endpoint) error
	// Deregister an endpoint
	Deregister(*Endpoint) error
	// Run the api
	Run(context.Context) error
	// Implemenation of api e.g http
	String() string
}

The gateway interface provides a way to create composable API gateways

func NewApi

func NewApi(opts ...Option) Api

NewApi returns a new api gateway

type Endpoint

type Endpoint struct {
	// RPC Method e.g. Greeter.Hello
	Name string
	// Description e.g what's this endpoint for
	Description string
	// API Handler e.g rpc, proxy
	Handler string
	// HTTP Host e.g example.com
	Host []string
	// HTTP Methods e.g GET, POST
	Method []string
	// HTTP Path e.g /greeter. Expect POSIX regex
	Path []string
	// Stream flag
	Stream bool
}

Endpoint is a mapping between an RPC method and HTTP endpoint

func Decode

func Decode(e map[string]string) *Endpoint

Decode decodes endpoint metadata into an endpoint

type Option

type Option func(*Options) error

func WithRouter

func WithRouter(r router.Router) Option

WithRouter sets the router to use e.g static or registry

type Options

type Options struct {
	// Address of the server
	Address string
	// Router for resolving routes
	Router router.Router
}

func NewOptions

func NewOptions(opts ...Option) Options

type Service

type Service struct {
	// Name of service
	Name string
	// The endpoint for this service
	Endpoint *Endpoint
	// Versions of this service
	Versions []*registry.Service
}

Service represents an API service

Directories

Path Synopsis
Package client provides an api client
Package client provides an api client
Package handler provides http handlers
Package handler provides http handlers
internal
Package resolver resolves a http request to an endpoint
Package resolver resolves a http request to an endpoint
Package router provides api service routing
Package router provides api service routing
Package server provides an API gateway server which handles inbound requests
Package server provides an API gateway server which handles inbound requests

Jump to

Keyboard shortcuts

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