Major rewrite

* use dep for vendoring
* lets encrypt
* moved web to transfer.sh-web repo
* single command install
* added first tests
This commit is contained in:
Remco
2017-03-22 18:09:21 +01:00
parent 6d68ad982f
commit cb6e5cb0c7
1917 changed files with 424197 additions and 260688 deletions

59
vendor/github.com/golang/gddo/log/http_handler.go generated vendored Normal file
View File

@@ -0,0 +1,59 @@
package log
import (
"encoding/hex"
"math/rand"
"net/http"
"time"
"github.com/inconshreveable/log15"
)
const (
gaeRequestIDHeader = "X-AppEngine-Request-Log-Id"
)
var random = rand.New(rand.NewSource(time.Now().UnixNano()))
type httpContextHandler struct {
log log15.Logger
next http.Handler
onAppEngine bool
}
// NewHTTPContextHandler adds a context logger based on the given logger to
// each request. After a request passes through this handler,
// Error(req.Context(), "foo") will log to that logger and add useful context
// to each log entry.
func NewHTTPContextHandler(h http.Handler, l log15.Logger, onAppEngine bool) http.Handler {
if l == nil {
l = log15.Root()
}
return &httpContextHandler{
log: l,
next: h,
onAppEngine: onAppEngine,
}
}
func (h *httpContextHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
// We will accept an App Engine Request Header. If there isn't one, we will
// fallback to 16 random bytes (hex encoded).
reqID := r.Header.Get(gaeRequestIDHeader)
if !h.onAppEngine || reqID == "" {
buf := make([]byte, 16)
random.Read(buf)
reqID = hex.EncodeToString(buf)
}
requestLogger := h.log.New(log15.Ctx{
"request_id": reqID,
})
r = r.WithContext(NewContext(ctx, requestLogger))
h.next.ServeHTTP(w, r)
}

64
vendor/github.com/golang/gddo/log/log.go generated vendored Normal file
View File

@@ -0,0 +1,64 @@
package log
import (
"context"
"os"
"github.com/inconshreveable/log15"
)
// Type key is used as a key for context.Context values
type key int
const (
_ key = iota
loggerKey
)
// FromContext always returns a logger. If there is no logger in the context, it
// returns the root logger. It is not recommended for use and may be removed in
// the future.
func FromContext(ctx context.Context) log15.Logger {
if logger, ok := ctx.Value(loggerKey).(log15.Logger); ok {
return logger
}
return log15.Root()
}
// NewContext creates a new context containing the given logger. It is not
// recommended for use and may be removed in the future.
func NewContext(ctx context.Context, l log15.Logger) context.Context {
return context.WithValue(ctx, loggerKey, l)
}
// Debug is a convenient alias for FromContext(ctx).Debug
func Debug(ctx context.Context, msg string, logCtx ...interface{}) {
FromContext(ctx).Debug(msg, logCtx...)
}
// Info is a convenient alias for FromContext(ctx).Info
func Info(ctx context.Context, msg string, logCtx ...interface{}) {
FromContext(ctx).Info(msg, logCtx...)
}
// Warn is a convenient alias for FromContext(ctx).Warn
func Warn(ctx context.Context, msg string, logCtx ...interface{}) {
FromContext(ctx).Warn(msg, logCtx...)
}
// Error is a convenient alias for FromContext(ctx).Error
func Error(ctx context.Context, msg string, logCtx ...interface{}) {
FromContext(ctx).Error(msg, logCtx...)
}
// Crit is a convenient alias for FromContext(ctx).Crit
func Crit(ctx context.Context, msg string, logCtx ...interface{}) {
FromContext(ctx).Crit(msg, logCtx...)
}
// Fatal is equivalent to Crit() followed by a call to os.Exit(1).
func Fatal(ctx context.Context, msg string, logCtx ...interface{}) {
FromContext(ctx).Crit(msg, logCtx...)
os.Exit(1)
}