Skip to content

Instantly share code, notes, and snippets.

package main
import (
"fmt"
"io/ioutil"
"net/http"
)
// Stitcher calls the Hello and World APIs to create a very useful string
func Stitcher(helloURL string, worldURL string) string {
func Benchmark_the_stitcher(b *testing.B) {
slowHelloAPI := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(500 * time.Millisecond)
fmt.Fprint(w, "Hello")
}))
slowWorldAPI := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(500 * time.Millisecond)
fmt.Fprint(w, "world")
}))
// Stitcher calls the Hello and World APIs to create a very useful string
func Stitcher(helloURL string, worldURL string) string {
helloChannel := make(chan []byte, 1)
worldChannel := make(chan []byte, 1)
go func() {
helloResponse, _ := http.Get(helloURL)
defer helloResponse.Body.Close()
helloContent, _ := ioutil.ReadAll(helloResponse.Body)
const wordSeparator = ", "
// Stitcher calls the Hello and World APIs to create a very useful string
func Stitcher(helloURL string, worldURL string) string {
helloChannel := make(chan []byte, 1)
worldChannel := make(chan []byte, 1)
go getStringFromAPI(helloChannel, helloURL)
go getStringFromAPI(worldChannel, worldURL)
func Test_it_handles_non_ok_from_hello_api(t *testing.T) {
helloAPI := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "oops", http.StatusInternalServerError)
}))
worldAPI := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "world")
}))
const wordSeparator = ", "
const errorMsg = "ALL OTHER SOFTWARE TEAMS ARE USELESS, OUTSOURCING IS A SHAM"
type apiResult struct {
content string
err error
}
// Stitcher calls the Hello and World APIs to create a very useful string
func Stitcher(helloURL string, worldURL string) string {
@quii
quii / channel.go
Created April 7, 2015 16:20
Simple golang channel example
package main
import (
"fmt"
)
type Baz struct {
Y string
}
package main
import (
"fmt"
"net/http"
)
type CoPublisher struct {
id string
link string
@quii
quii / composition.clj
Created July 24, 2015 13:14
Function composition in Clojure
foo=> (defn x [a] (+ a 1))
#'foo/x
foo=> (defn y [a] (+ a 2))
#'foo/y
foo=> (-> 5 x y)
8
foo=> (defn z [a] (-> a x y))
#'foo/z
foo=> (z 10)
13
@quii
quii / clojure.clj
Last active August 29, 2015 14:26
My notes on learning some clojure
(comment
Clojure notes. Gathered from links below and "Programming Clojure"
- Uniform syntax.
- Code is data
- Immutablility encouraged
- [http://learnxinyminutes.com/docs/clojure/]
- [http://www.4clojure.com/problem/8#prob-title]
- [http://www.braveclojure.com/]
- Revenge of the nerds http://www.paulgraham.com/icad.html