Skip to content

Instantly share code, notes, and snippets.

@hoenirvili
Created September 25, 2015 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoenirvili/dcaf74edfab1adecb5bb to your computer and use it in GitHub Desktop.
Save hoenirvili/dcaf74edfab1adecb5bb to your computer and use it in GitHub Desktop.
Basic minimal web server in Go
package main
import (
"fmt"
"log"
"net/http"
"strings"
)
func sayHelloName(w http.ResponseWriter, r *http.Request) {
// parse arguments you have to call this by yourself
r.ParseForm()
fmt.Println(r.Form)
fmt.Println("path", r.URL.Path)
fmt.Println("scheme", r.URL.Scheme)
fmt.Println(r.Form["url_long"])
for k, v := range r.Form {
fmt.Println("key:", k)
fmt.Println("val:", strings.Join(v, ""))
}
}
func main() {
http.HandleFunc("/", sayHelloName) // set router
err := http.ListenAndServe(":9090", nil)
if err != nil {
log.Fatal("ListenAndServer: ", err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment