joho / prohttphandler

A (not very) pro http handler for go (does simple asset serving and exact match paths -> handler funcs)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ProHttpHandler

A teeny tiny http handler for Go that I wanted to reuse across a couple of projects.

It gives you two things: static asset handling (in a path of your choice) and exact matching of paths to http handler funcs

Example

An example that serves all files in "public" at / and serves up a super boring homepage on port 8080.

package main

import (
  "fmt"
  "github.com/joho/prohttphandler"
  "log"
  "net/http"
)

func main() {
  handler := prohttphandler.New("public")

  handler.ExactMatchFunc("/", func(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintf(w, "This is the homepage at /")
  })

  log.Fatal(http.ListenAndServe(":8080", handler))
}

There are some very poor docs here


Copyright 2013 John Barton (but under MIT Licence)

About

A (not very) pro http handler for go (does simple asset serving and exact match paths -> handler funcs)

License:MIT License


Languages

Language:Go 100.0%