func handleExit(res http.ResponseWriter, req *http.Request) {
	code := 0
	var err error
	if c := req.URL.Query().Get("code"); c != "" {
		if code, err = strconv.Atoi(c); err != nil {
			code = 1
		}
	}
	log.Printf("exit code=%d", code)
	os.Exit(code)
}
Special path for forcing the server to exit with a given code
package main
import (
	"encoding/json"
	"fmt"
	"html"
	"io"
	"io/ioutil"
	"log"
	"net/http"
	"os"
	"os/exec"
	p "path"
	"path/filepath"
	"strconv"
	"strings"
	"time"
	"golang.org/x/net/websocket"
	"github.com/heroku/shaas/pkg"
)
var (
	authUser, authPassword string
	requireBasicAuth       bool
	readonly               bool
)
const (
	defaultResponseStatusCode = 200
	defaultResponseDelay      = 0
)
func main() {
	if basicAuth := os.Getenv("BASIC_AUTH"); basicAuth != "" {
		requireBasicAuth = true
		bits := strings.SplitN(basicAuth, ":", 2)
		authUser = bits[0]
		if len(bits) == 2 {
			authPassword = bits[1]
		}
		log.Println("at=basic-auth.enabled")
	} else {
		log.Println("at=basic-auth.disabled")
	}
	if _, readonly = os.LookupEnv("READ_ONLY"); readonly {
		log.Println("at=readonly.enabled")
	} else {
		log.Println("at=readonly.disabled")
	}
	http.HandleFunc("/health", handleHealth)
	http.HandleFunc("/>/exit", authorize(handleExit))
	http.HandleFunc("/", authorize(handleAny))
	for _, p := range httpPorts() {
		go func(addr string) {
			log.Fatal(http.ListenAndServe(addr, nil))
		}(":" + p)
	}
	select {}
}
func authorize(handler func(http.ResponseWriter, *http.Request)) func(res http.ResponseWriter, req *http.Request) {
	return func(res http.ResponseWriter, req *http.Request) {
		if requireBasicAuth {
			if user, pass, ok := req.BasicAuth(); !ok {
				handleError(res, req, fmt.Errorf("Authorization Required"), http.StatusUnauthorized, "Not Authorized")
				return
			} else if user != authUser || pass != authPassword {
				handleError(res, req, fmt.Errorf("Not Authorized"), http.StatusUnauthorized, "Not Authorized")
				return
			}
		}
		handler(res, req)
	}
}