test

package module
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2018 License: BSD-3-Clause Imports: 0 Imported by: 0

README

Requirements

Go 1.6 or higher

You can download the binary release from releases or compile the source release.

Make sure that your $GOPATH/bin is in your $PATH.

(Optional)ProtocolBuffers 3.0.0-beta-3 or later

In project, we have provided gRPC stub and reverse-proxy so that this step is optional.

If you want to generate gRPC stub and reverse-proxy by yourself, you need to install ProtocolBuffers 3.0.0-beta-3 or later.

You can download the binary release from releases or compile the source release.

cd /tmp
wget https://github.com/google/protobuf/releases/download/v3.5.1/protobuf-all-3.5.1.tar.gz
tar -xzvf protobuf-all-3.5.1.tar.gz
cd protobuf-3.5.1 && ./configure --prefix=$HOME/protobuf && make && make install
export PATH=$PATH:./protobuf/bin

note: you can choose to download other os realeases on https://github.com/google/protobuf/releases instead of linux realease

Update code

go get -u github.com/tronprotocol/grpc-gateway

Usage

  1. Make sure your Tron grpc serivice has been started on localhost:50051 , you can visit How to build for starting Tron service.
  2. Get the source code and change word dir (Strongly suggest update your code before you start the service on your server)
# download project
go get -u github.com/tronprotocol/grpc-gateway

# change to project dir
cd $GOPATH/src/github.com/tronprotocol/grpc-gateway
  1. (Optional) Generate gRPC stub and reverse-proxy. Make sure you have installed protoc
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go get -u github.com/golang/protobuf/protoc-gen-go
./gen-proto.sh
  1. run proxy-server. Make sure your code is lastest version.
go run tron_http/main.go
or
go run tron_http/main.go -port 50051 -host localhost

# listen is your http port
go run tron_http/main.go -port 50051 -host 10.0.8.214 -listen 8080
  1. Test API of tron http
curl -X POST -k http://localhost:8086/wallet/listwitnesses

If you get witness-list json data, congratulations

Note: json to protobuf, bytes should be passed via base64 formate

grpc-gateway

Build Status

grpc-gateway is a plugin of protoc. It reads gRPC service definition, and generates a reverse-proxy server which translates a RESTful JSON API into gRPC. This server is generated according to custom options in your gRPC definition.

It helps you to provide your APIs in both gRPC and RESTful style at the same time.

architecture introduction diagram

Background

gRPC is great -- it generates API clients and server stubs in many programming languages. It is fast, easy-to-use, bandwidth-efficient and its design is combat-proven by Google. However, you might still want to provide a traditional RESTful API as well. Reasons can range from maintaining backwards-compatibility, supporting languages or clients not well supported by gRPC to simply maintaining the aesthetics and tooling involved with a RESTful architecture.

This project aims to provide that HTTP+JSON interface to your gRPC service. A small amount of configuration in your service to attach HTTP semantics is all that's needed to generate a reverse-proxy with this library.

Parameters and flags

protoc-gen-grpc-gateway supports custom mapping from Protobuf import to Golang import path. They are compatible to the parameters with same names in protoc-gen-go.

In addition, we also support the request_context parameter in order to use the http.Request's Context (only for Go 1.7 and above). This parameter can be useful to pass request scoped context between the gateway and the gRPC service.

protoc-gen-grpc-gateway also supports some more command line flags to control logging. You can give these flags together with parameters above. Run protoc-gen-grpc-gateway --help for more details about the flags.

Features

Supported
  • Generating JSON API handlers
  • Method parameters in request body
  • Method parameters in request path
  • Method parameters in query string
  • Enum fields in path parameter (including repeated enum fields).
  • Mapping streaming APIs to newline-delimited JSON streams
  • Mapping HTTP headers with Grpc-Metadata- prefix to gRPC metadata (prefixed with grpcgateway-)
  • Optionally emitting API definition for Swagger.
  • Setting gRPC timeouts through inbound HTTP Grpc-Timeout header.

Mapping gRPC to HTTP

  • How gRPC error codes map to HTTP status codes in the response
  • HTTP request source IP is added as X-Forwarded-For gRPC request header
  • HTTP request host is added as X-Forwarded-Host gRPC request header
  • HTTP Authorization header is added as authorization gRPC request header
  • Remaining Permanent HTTP header keys (as specified by the IANA here are prefixed with grpcgateway- and added with their values to gRPC request header
  • HTTP headers that start with 'Grpc-Metadata-' are mapped to gRPC metadata (prefixed with grpcgateway-)
  • While configurable, the default {un,}marshaling uses jsonpb with OrigName: true.

Contribution

See CONTRIBUTING.md.

License

grpc-gateway is licensed under the BSD 3-Clause License. See LICENSE.txt for more details.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Package api is a reverse proxy.
Package api is a reverse proxy.
examplepb
Package examplepb is a reverse proxy.
Package examplepb is a reverse proxy.
sub
Package sub is a generated protocol buffer package.
Package sub is a generated protocol buffer package.
sub2
Package sub2 is a generated protocol buffer package.
Package sub2 is a generated protocol buffer package.
Command protoc-gen-grpc-gateway is a plugin for Google protocol buffer compiler to generate a reverse-proxy, which converts incoming RESTful HTTP/1 requests gRPC invocation.
Command protoc-gen-grpc-gateway is a plugin for Google protocol buffer compiler to generate a reverse-proxy, which converts incoming RESTful HTTP/1 requests gRPC invocation.
generator
Package generator provides an abstract interface to code generators.
Package generator provides an abstract interface to code generators.
gengateway
Package gengateway provides a code generator for grpc gateway files.
Package gengateway provides a code generator for grpc gateway files.
genswagger
Package genswagger provides a code generator for swagger.
Package genswagger provides a code generator for swagger.
options
Package options is a generated protocol buffer package.
Package options is a generated protocol buffer package.
Package runtime contains runtime helper functions used by servers which protoc-gen-grpc-gateway generates.
Package runtime contains runtime helper functions used by servers which protoc-gen-grpc-gateway generates.
internal
Package internal is a generated protocol buffer package.
Package internal is a generated protocol buffer package.
Package utilities provides members for internal use in grpc-gateway.
Package utilities provides members for internal use in grpc-gateway.

Jump to

Keyboard shortcuts

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