Ejemplo n.º 1
0
func main() {
	mux := possum.NewServerMux()

	mux.PreRequest = func(ctx *possum.Context) error {
		host, _, err := net.SplitHostPort(ctx.Request.RemoteAddr)
		if err != nil {
			return err
		}
		if host != "127.0.0.1" {
			return possum.NewError(http.StatusForbidden, "Localhost only")
		}
		return nil
	}

	mux.PostResponse = func(ctx *possum.Context) error {
		fmt.Printf("[%d] %s:%s \"%s\"", ctx.Response.Status,
			ctx.Request.RemoteAddr, ctx.Request.Method,
			ctx.Request.URL.String())
		return nil
	}
	mux.HandleFunc(router.Simple("/rbac"), rbacHandler, view.Json(view.CharSetUTF8))
	mux.HandleFunc(router.Simple("/isgranted"), isGrantedHandler, view.Json(view.CharSetUTF8))
	fmt.Printf("[%s] %s\n", time.Now(), addr)
	if err := http.ListenAndServe(addr, mux); err != nil {
		fmt.Println(err)
		return
	}
}
Ejemplo n.º 2
0
func startPossum() {
	mux := possum.NewServerMux()
	mux.HandleFunc(possumrouter.Simple("/hello"), possumHandler, possumview.Simple("text/html", "utf-8"))
	http.ListenAndServe(":"+strconv.Itoa(port), mux)
}