Skip to content

Instantly share code, notes, and snippets.

@ki4jnq
Last active November 9, 2018 20:19
Show Gist options
  • Save ki4jnq/1b3096f1bf0626267a5bf0c29c519f5c to your computer and use it in GitHub Desktop.
Save ki4jnq/1b3096f1bf0626267a5bf0c29c519f5c to your computer and use it in GitHub Desktop.
package web
import (
"net/http"
"encoding/json"
)
func ServerStart() {
http.HandleFunc("/", func(res http.ResponseWriter, req *http.Request) {
buf, err := json.Marshal(map[string]string{"message": "Hello World!"})
if err != nil {
res.Write([]byte("Boom!"))
panic(err)
}
res.Header().Set("Content-Type", "application/json")
res.Write(buf)
})
http.ListenAndServe(
":8081",
nil,
)
}
package main
import (
"fmt"
"github.com/yourname/web"
)
func main() {
fmt.Println("Starting Server...")
web.ServerStart()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment