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/gorilla/mux" | |
func main() { | |
r := mux.NewRouter() | |
r.HandleFunc("/reservations/{key}", func1).Methods("POST") | |
r.HandleFunc("/values/{key}/{lock_id}", func2).Queries("release", "").Methods("POST") | |
r.HandleFunc("/values/{key}", func3).Methods("PUT") |
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
var ( | |
ErrInvalidCommand = errors.New("invalid command") | |
ErrInvalidNumArgs = errors.New("wrong num args") | |
ErrInvalidInt = errors.New("invalid int") | |
) | |
const ( | |
create = "CREATE" | |
modify = "MODIFY" | |
set = "SET" |
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
import ( | |
"bufio" | |
"os" | |
) | |
func main() { | |
f := os.Open("somefile") | |
defer f.Close | |
rdr := bufio.NewReader(f) | |
for { |
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
func myHandlerFunc(i int) http.HanderFunc { | |
return func(w http.ResponseWriter, r *http.Request) { | |
str := fmt.Sprintf("hello %d", i) | |
w.Write([]byte(str)) | |
} | |
} |
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 tmplbench | |
import ( | |
"testing" | |
"html/template" | |
) | |
func BenchmarkTemplate(b *testing.B) { | |
tmpl := template.New("test") | |
b.ResetTimer() |
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
import akka.actor.{Props, Actor, ActorSystem} | |
class A extends Actor { | |
override def receive = { | |
case other => println(other) | |
} | |
} | |
object Main extends App { | |
val system = ActorSystem("main") |
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 goactor | |
import "container/list" | |
import "sync" | |
//public types | |
type Message struct { | |
Sender Pid | |
Payload interface{} | |
} |
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
import scala.concurrent._ | |
import scala.concurrent.duration._ | |
import scala.concurrent.ExecutionContext.Implicits.global | |
import scala.util.Random | |
import java.util.{Timer, TimerTask} | |
object Util { | |
sealed trait BaseResponse | |
case class Response1(res: Int) extends BaseResponse | |
case class Response2(res: String) extends BaseResponse |
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
//Newman has a DSL for building up HttpRequests. | |
//the DSL uses the familiar builder pattern from Java. | |
//it copies the state of the request on each call, instead of modifying any internal state. | |
val url = new URL("http://siliconvalley-codecamp.com") | |
//the familiar GET function returns an instance of a Builder | |
//you can convert any Builder to a Newman HttpRequest | |
val builder1 = GET(url) |
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
val httpClient: HttpClient = ??? | |
val httpResponse: HttpResponse = Await.result(httpClient.get(someUrl, someHeaders).apply(), 1.second) | |
//bodyAsIfResponseCode will return a Success if: | |
//- the HttpResponse returned with HttpResponseCode.OK | |
//- the function in the second argument returned a Success | |
val bodyValidation1: Validation[Throwable, String] = httpResponse.bodyAsIfResponseCode(HttpResponseCode.OK, | |
{ httpResponse: HttpResponse => | |
Success(httpResponse.bodyString) | |
} |