Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/autom8ter/goproxyrpc
GoProxyRPC- a highly configurable rest-to-grpc gateway/authentication server
https://github.com/autom8ter/goproxyrpc
api autom8ter colemanword gateway golang grpc proxy
Last synced: 9 days ago
JSON representation
GoProxyRPC- a highly configurable rest-to-grpc gateway/authentication server
- Host: GitHub
- URL: https://github.com/autom8ter/goproxyrpc
- Owner: autom8ter
- License: apache-2.0
- Created: 2019-03-07T04:35:29.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-21T03:14:24.000Z (over 5 years ago)
- Last Synced: 2024-12-12T19:04:40.650Z (25 days ago)
- Topics: api, autom8ter, colemanword, gateway, golang, grpc, proxy
- Language: Go
- Homepage:
- Size: 2.12 MB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GoProxyRPC
# Overview
## Config (./config.yaml)
### Example:
```yaml
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)`
```go
//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:```go
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)
```text
#!/usr/bin/env bashcurl --header "Content-Type: application/json" --request POST --data '{"say":"hello"}' http://localhost:8080/v1/echo
```
### Response`{"say":"echoed: hello"}`
## Usage
## Usage
#### type Config
```go
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
```go
type Proxy struct {
http.Handler
}
```Proxy is a REST-gRPC reverse proxy server
#### func NewProxy
```go
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
```go
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
```go
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