Karolis' playground unit_golang / master modhello / main.go
master

Tree @master (Download .tar.gz)

main.go @masterraw · history · blame

package main

import (
	"context"
	"fmt"
	"io"
	"net/http"
)

type noClose struct{}

func (*noClose) Close() error { return nil }

func InitModule(ctx context.Context) (io.Closer, http.Handler) {
	return &noClose{}, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		name := "stranger"
		if i := r.URL.Query()["name"]; len(i) > 0 {
			name = i[0]
		}
		w.Header().Set("Content-Type", "text/plain")
		fmt.Fprintf(w, "Hello %s", name)
	})
}