Created
December 8, 2019 17:55
-
-
Save fourswordsio/cc7571af1090285d8064c7a403b7c228 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/linkpoolio/bridges" | |
"net/http" | |
) | |
type GasStation struct{} | |
// Run implements Bridge Run for querying the ETH Gas Station | |
func (gs *GasStation) Run(h *bridges.Helper) (interface{}, error) { | |
obj := make(map[string]interface{}) | |
err := h.HTTPCall( | |
http.MethodGet, | |
"https://ethgasstation.info/json/ethgasAPI.json", | |
&obj, | |
) | |
return obj["average"], err | |
} | |
// Opts is the bridge.Bridge implementation | |
func (gs *GasStation) Opts() *bridges.Opts { | |
return &bridges.Opts{ | |
Name: "GasStation", | |
Lambda: true, | |
} | |
} | |
func Handler(w http.ResponseWriter, r *http.Request) { | |
bridges.NewServer(&GasStation{}).Handler(w, r) | |
} | |
func main() { | |
bridges.NewServer(&GasStation{}).Start(8080) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment