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 ( | |
"bytes" | |
"log" | |
"github.com/linkedin/goavro" | |
) | |
var ( |
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 ( | |
"bytes" | |
"log" | |
"github.com/linkedin/goavro" | |
) | |
var ( |
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 exist | |
import ( | |
"sync" | |
"sync/atomic" | |
) | |
type ExistCache struct { | |
growLock sync.RWMutex | |
indexMask uint64 |
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
// ErrorLogHandler returns a new http.Handler that logs HTTP requests that result in response | |
// errors. The handler will output lines in common log format to the specified io.Writer. | |
func ErrorLogHandler(next http.Handler, out io.Writer) http.Handler { | |
const apacheLogFormat = "%s [%s] \"%s\" %d %d %f\n" | |
const timeFormat = "02/Jan/2006:15:04:05 MST" | |
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
lrw := &loggedResponseWriter{ | |
ResponseWriter: w, | |
status: http.StatusOK, |
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
// PanicHandler returns a new http.Handler that catches a panic caused by the specified | |
// http.Handler, and responds with an appropriate http status code and message. | |
func PanicHandler(next http.Handler) http.Handler { | |
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
defer func() { | |
if r := recover(); r != nil { | |
var text string | |
switch t := r.(type) { | |
case error: | |
text = t.Error() |
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
// GzipHandler returns a new http.Handler that optionally compresses the response text using the | |
// gzip compression algorithm when the HTTP request's Accept-Encoding header includes the string | |
// "gzip". | |
func GzipHandler(next http.Handler) http.Handler { | |
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
if !strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { | |
next.ServeHTTP(w, r) | |
return | |
} | |
w.Header().Set("Content-Encoding", "gzip") |
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 sortAndMaybeInsertString | |
func sortAndMaybeInsertString(s string, a []string) []string { | |
if len(a) == 0 { | |
return append(a, s) | |
} | |
sort.Strings(a) | |
i := sort.SearchStrings(a, s) |
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 ( | |
"bufio" | |
"fmt" | |
"io" | |
"os" | |
"time" | |
"github.com/karrick/gorill" |
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 ( | |
"fmt" | |
"os" | |
"github.com/karrick/godirwalk" | |
"github.com/pkg/errors" | |
) |
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 "time" | |
func backoff(retries int, callback func() error) error { | |
var err error | |
delay := time.Millisecond | |
for { | |
err = callback() | |
if err == nil { |
OlderNewer