Exemple #1
0
// Hello is an example endpoint
func Hello(w http.ResponseWriter, r *http.Request) {
	ctx := &myContext{}
	flannel.Context(r, &ctx)
	flannel.LogInfo(r, "Hello was called by %s", ctx.Name)

	flannel.Write(w, http.StatusOK, fmt.Sprintf("Hello, %s. I've been called %d times.", ctx.Name, ctx.Counter))
}
Exemple #2
0
// NameMiddleware is an example of a middleware method.
func NameMiddleware(next http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		ctx := &myContext{}
		flannel.Context(r, &ctx)
		ctx.Name = "World"

		next(w, r)
	}
}
Exemple #3
0
// CounterMiddleware is another example of a middleware method.
func CounterMiddleware(next http.HandlerFunc) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		ctx := &myContext{}
		flannel.Context(r, &ctx)
		counter++
		ctx.Counter = counter

		next(w, r)
	}
}