Skip to content

Instantly share code, notes, and snippets.

@tedsuo
tedsuo / trace_lager.go
Last active August 18, 2016 18:02
Adding OpenTracing to Lager
func FromContext(context.Context) Logger {}
func FromSpan(opentracing.Span) Logger {}
func FromHTTPHeaders(http.Header) Logger {}
func ToHTTPHeaders(Logger, http.Header) {}
type Logger interface {
// Lifecycle
@tedsuo
tedsuo / main_v1.go
Last active August 7, 2018 20:00
ifrit v2: Cleanup and simplification of boilerplate in main
// Old clunky way of setting up ifrit
package main
import ...
func main() {
logger := newLogger("example-service")
members := grouper.Members{
{"http_server", httpServer},
@tedsuo
tedsuo / 1-bank.go
Last active March 7, 2016 08:22
Why golang favors code generation for protocols
// When writing an application, we want to stick to the details that are specific
// to our application domain. We don't want to write generic code that deals with
// contemporary issues, such as "what type of client would like to connect to us today?"
package bank
// The Account interface represents our application's protocol.
// We'd like to never have to write the generic transport protocol code.
type Account interface{
HowFarInTheHoleAmI() Farthings
}
@tedsuo
tedsuo / exec.go
Created March 5, 2016 01:03
ifrit.Exec
package ifrit
import (
"os"
"os/signal"
)
const SIGNAL_BUFFER_SIZE = 1024
func Exec(logger Logger, runner Runner, signalTypes ...os.Signal) {
@tedsuo
tedsuo / volman_feedback.md
Last active February 2, 2016 18:57
Volman Feedback

volman/cmd/volman/main.go

Don't dot import.

parse flags in init instead of main - not a big deal but a better practice.

passing loggers - logger argument always comes first in every function that takes a logger

exitOnFailure() - use log.Fatal to trigger a log and panic instead

@tedsuo
tedsuo / log_jammer.go
Created July 17, 2015 17:25
Log Jammer App
package main
import (
"fmt"
"log"
"net/http"
"os"
"strconv"
"time"
)
type Range interface {
Add(low, high int)
Remove(low, high int)
Contains(int) bool
Lowest() int
Highest() int
Each(func(int, int) bool)
Union(Range) Range
@tedsuo
tedsuo / main.go
Created December 9, 2014 21:51
CancellableCopy wants to stop an in-progress io.Copy, but suffers from a race
package main
import (
"bytes"
"errors"
"io"
"io/ioutil"
"os"
)

This is a minimal-ish set of instruction to set up a freshly imaged OS X workstation for working on Diego. If you've already used the Pivotal sprout recipes to provision your machine, you might have a bad time.

Pivotal Workstation Conveniences

These are nice for the core developer team, feel free to skip this section:

  • Download Chrome using Safari, and install it.
  • Download Wraparound from the web.
  • Download ShiftIt.zip from github.com/onsi/shiftit.
  • Get Flycut from the App Store.