I hereby claim:
- I am hadv on github.
- I am dvietha (https://keybase.io/dvietha) on keybase.
- I have a public key ASApRXY1Pj2ToSDec4ZOPXIcHWyp8qlQ8GE_obqoMU1OjAo
To claim this, I am signing this object:
| syntax = “proto3”; | |
| option go_package = “echo”; | |
| // Echo Service | |
| // | |
| // Echo Service API consists of a single service which returns a message. | |
| package hadv.grpc.echo; | |
| import “google/api/annotations.proto”; | |
| // Message represents a simple message sent to the Echo service. | |
| message Message { | |
| // Id represents the message identifier. |
| package main | |
| import ( | |
| “github.com/golang/glog” | |
| examples “github.com/hadv/grpc” | |
| “golang.org/x/net/context” | |
| “google.golang.org/grpc” | |
| “google.golang.org/grpc/metadata” | |
| ) | |
| // Implements of EchoServiceServer | |
| type echoServer struct{} |
| package main | |
| import ( | |
| “flag” | |
| “net/http” | |
| “github.com/gengo/grpc-gateway/runtime” | |
| “github.com/golang/glog” | |
| echo “github.com/hadv/grpc/echo” | |
| “golang.org/x/net/context” | |
| “google.golang.org/grpc” | |
| ) |
| { | |
| "swagger": "2.0", | |
| "info": { | |
| "title": "Echo Service", | |
| "description": "Echo Service API consists of a single service which returns a message.", | |
| "version": "version not set" | |
| }, | |
| "schemes": [ | |
| "http", | |
| "https" |
| type weatherProvider interface { | |
| temperature(city string) (float64, error) | |
| } |
| type openWeatherMap struct { | |
| apiKey string | |
| } | |
| func (w openWeatherMap) temperature(city string) (float64, error) { | |
| resp, err := http.Get("http://api.openweathermap.org/data/2.5/weather?APPID=" + w.apiKey + "&q=" + city) | |
| if err != nil { | |
| return 0, err | |
| } |
| type apixu struct { | |
| apiKey string | |
| } | |
| func (w apixu) temperature(city string) (float64, error) { | |
| resp, err := http.Get("http://api.apixu.com/v1/current.json?key=" + w.apiKey + "&q=" + city) | |
| if err != nil { | |
| return 0, err | |
| } |
| func (w multiWeatherProvider) temperature(city string) (float64, error) { | |
| // Make a channel for temperatures, and a channel for errors. | |
| // Each provider will push a value into only one. | |
| temps := make(chan float64, len(w)) | |
| errs := make(chan error, len(w)) | |
| // For each provider, spawn a goroutine with an anonymous function. | |
| // That function will invoke the temperature method, and forward the response. | |
| for _, provider := range w { | |
| go func(p weatherProvider) { |
| func main() { | |
| mw := multiWeatherProvider{ | |
| openWeatherMap{apiKey: "5bd6d7d469feee97788f51744f8c2910"}, | |
| apixu{apiKey: "ff8b321075a54e7288794851162712"}, | |
| } | |
| http.HandleFunc("/weather/", func(w http.ResponseWriter, r *http.Request) { | |
| begin := time.Now() | |
| city := strings.SplitN(r.URL.Path, "/", 3)[2] |
I hereby claim:
To claim this, I am signing this object: