Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Ha ĐANG hadv

🎯
Focusing
Block or report user

Report or block hadv

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View installing-get-on-centos.md
$ sudo yum -y update
$ sudo yum -y install golang
$ sudo yum -y install gmp-devel
$ sudo yum -y install git
$ git clone https://github.com/ethereum/go-ethereum
$ cd go-ethereum/
$ make geth
$ ls -al build/bin/geth
@hadv
hadv / main.go
Created Apr 25, 2019 — forked from wayneashleyberry/main.go
Go http server with graceful shutdown
View main.go
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"syscall"
)
View keybase.md

Keybase proof

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:

View main.go
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]
View multiWeatherProvider.go
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) {
View apixu.go
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
}
View openWeatherMap.go
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
}
View weatherProvider.go
type weatherProvider interface {
temperature(city string) (float64, error)
}
View service.swagger.json
{
"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"
View main.go
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”
)
You can’t perform that action at this time.