Skip to content

Instantly share code, notes, and snippets.

@jsfaint
Created April 23, 2018 03:35
Show Gist options
  • Save jsfaint/ad2fbd690b94da2ed42102d9db8d255f to your computer and use it in GitHub Desktop.
Save jsfaint/ad2fbd690b94da2ed42102d9db8d255f to your computer and use it in GitHub Desktop.
https server in go
// 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