發表文章

目前顯示的是 6月, 2017的文章

gRPC-Gateway

圖片
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. 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 ...

How to use gRPC

圖片
About gRPC gRPC is a modern open source high performance RPC framework that can run in any environment. It can efficiently connect services in and across data centers with pluggable support for load balancing, tracing, health checking and authentication. It is also applicable in last mile of distributed computing to connect devices, mobile applications and browsers to backend services. Overview In gRPC a client application can directly call methods on a server application on a different machine as if it was a local object, making it easier for you to create distributed applications and services. As in many RPC systems, gRPC is based around the idea of defining a service, specifying the methods that can be called remotely with their parameters and return types. On the server side, the server implements this interface and runs a gRPC server to handle client calls. On the client side, the client has a stub (referred to as just a client in some languages) that provides the same me...
圖片
Build RESTful API service in golang using gin-gonic framework Today I’m going to build a simple API for  todo  application with the golang programming language. I’m going to use golang simplest/fastest framework  gin-gonic  and a beautiful ORM  gorm  for our database work . To install these packages go to your workspace $GOPATH/src and run these command below: $ go get gopkg.in/gin-gonic/gin.v1 $ go get -u github.com/jinzhu/gorm $ go get github.com/go-sql-driver/mysql In generic crud application we need the API’s as follows: POST todos/ GET todos/ GET todos/{id} PUT todos/{id} DELETE todos/{id} Let’s start coding, go to your $GOPATH/src and make a directory  todo.  Inside the todo directory create a file  main.go.  Import the “gin framework” to our project and create the routes like below inside  main  function. I like to add a prefix of the apis like “api/v1/”, that’s why we’ll use the router Group meth...