Skip to content

Instantly share code, notes, and snippets.

@erhangundogan
Created July 17, 2014 08:10
Show Gist options
  • Select an option

  • Save erhangundogan/0696d85dd0bae3e7ceab to your computer and use it in GitHub Desktop.

Select an option

Save erhangundogan/0696d85dd0bae3e7ceab to your computer and use it in GitHub Desktop.
simple go http server
package main
import (
"fmt"
"net/http"
"strings"
)
var chttp = http.NewServeMux()
func main() {
chttp.Handle("/", http.FileServer(http.Dir("./")))
http.HandleFunc("/erhan", HomeHandler)
http.ListenAndServe(":8080", nil)
}
func HomeHandler(w http.ResponseWriter, r *http.Request) {
if (strings.Contains(r.URL.Path, ".")) {
chttp.ServeHTTP(w, r)
} else {
fmt.Fprintf(w, "HomeHandler")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment