goproxyrpc

package module
v0.0.0-...-ddd20ef Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2019 License: Apache-2.0 Imports: 11 Imported by: 0

README

GoProxyRPC

Overview

Config (./config.yaml)

Example:
jwt_key: "supersecret-jwt-signing key"
endpoint: "localhost:3000"
cors:
  allow-origin:
  allow-credentials:
  allow-methods:
  allow-headers:
proxy:
  port: 8080
  api-prefix: "/"

Registering a Grpc Gaterway Service

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

//Eazy Peazy with Golang first class functions
func RegisterFunc() goproxyrpc.RegisterFunc {
	return func(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) {
		return echopb.RegisterEchoServiceHandlerFromEndpoint(ctx, mux, endpoint, opts)
		//^^^generated from grpc gateway plugin	
    }
}

Starting the GoProxyRPC server

Dials the endpoint in your config:


func main() {
	ctx := context.Background()
	goproxyrpc.New(ctx, &goproxyrpc.Config{
		EnvPrefix:    "ECHO",
		DialOptions:  []grpc.DialOption{grpc.WithInsecure()},
		RegisterFunc: RegisterFunc(),
	}).ListenServe(ctx)
}

Curl the Proxy Server (pkg/testing/echo)

#!/usr/bin/env bash

curl --header "Content-Type: application/json"   --request POST   --data '{"say":"hello"}'   http://localhost:8080/v1/echo
Response

{"say":"echoed: hello"}

Usage

Usage

type Config
type Config struct {
	EnvPrefix    string
	DialOptions  []grpc.DialOption
	RegisterFunc RegisterFunc
}

Config holds the necessary non-config file configurations needed to create a Proxy

type Proxy
type Proxy struct {
	http.Handler
}

Proxy is a REST-gRPC reverse proxy server

func NewProxy
func NewProxy(ctx context.Context, cfg *Config) *Proxy

NewProxy creates a new REST-gRPC proxy server. If a jwt_key is found in your config file, the endpoint will be reject all requests that dont provide a valid bearer token.

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

RegisterFunc registers a grpc endpoint from the generated RegisterfromEndpoint function from the grpc-gateway protoc plugin

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

NewRegisterFunc is a helper to create a RegisterFunc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	EnvPrefix    string
	DialOptions  []grpc.DialOption
	RegisterFunc RegisterFunc
}

Config holds the necessary non-config file configurations needed to create a Proxy

type Proxy

type Proxy struct {
	http.Handler
	// contains filtered or unexported fields
}

Proxy is a REST-gRPC reverse proxy server

func NewProxy

func NewProxy(ctx context.Context, cfg *Config) *Proxy

NewProxy creates a new REST-gRPC proxy server. If a jwt_key is found in your config file, the endpoint will be reject all requests that dont provide a valid bearer token.

type RegisterFunc

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

RegisterFunc registers a grpc endpoint from the generated RegisterfromEndpoint function from the grpc-gateway protoc plugin

func NewRegisterFunc

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

NewRegisterFunc is a helper to create a RegisterFunc

Directories

Path Synopsis
pkg
testing/gen/echo
Package echopb is a reverse proxy.
Package echopb is a reverse proxy.

Jump to

Keyboard shortcuts

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