Created
September 25, 2015 12:18
-
-
Save hoenirvili/dcaf74edfab1adecb5bb to your computer and use it in GitHub Desktop.
Basic minimal web server in Go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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