Created
April 23, 2018 03:35
-
-
Save jsfaint/ad2fbd690b94da2ed42102d9db8d255f to your computer and use it in GitHub Desktop.
https 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 provides ... | |
package main | |
import ( | |
"fmt" | |
"log" | |
"net/http" | |
) | |
func HelloServer(w http.ResponseWriter, req *http.Request) { | |
fmt.Println("Method:", req.Method) | |
fmt.Println("Host:", req.URL.Hostname(), req.URL.Port()) | |
fmt.Println("URL:", req.URL.RequestURI()) | |
fmt.Println("Form:") | |
for k, v := range req.PostForm { | |
fmt.Printf("%s: %s\n", k, v) | |
} | |
fmt.Println("Header:") | |
for k, v := range req.Header { | |
fmt.Printf("%s: %s\n", k, v) | |
} | |
fmt.Println("") | |
} | |
func main() { | |
http.HandleFunc("/", HelloServer) | |
log.Panic(http.ListenAndServeTLS(":443", "server.crt", "server.key", nil)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment