Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple HTTP & Static rendering in Go
package main
import (
var INDEX_HTML []byte
func main() {
fmt.Println("starting server on http://localhost:8888/\nvalue is %s", "asdf")
http.HandleFunc("/", IndexHandler)
http.HandleFunc("/post", PostHandler)
serveSingle("/js/getData.js", "./js/getData.js")
// http.Handle("/js/", http.StripPrefix("/js/", http.FileServer(http.Dir("js/getData.js"))))
http.ListenAndServe(":8888", nil)
func serveSingle(pattern string, filename string) {
http.HandleFunc(pattern, func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, filename)
func IndexHandler(w http.ResponseWriter, r *http.Request) {
log.Println("GET /")
func PostHandler(w http.ResponseWriter, r *http.Request) {
log.Println("in posthandler", r.Form)
var value = r.FormValue("textfield")
func init() {
INDEX_HTML, _ = ioutil.ReadFile("./html/index.html")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment