Skip to content

Instantly share code, notes, and snippets.

@tuxlinuxien
Created May 19, 2016 11:24
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 tuxlinuxien/48abdfbd4f5a1cda1c151edad07d7e78 to your computer and use it in GitHub Desktop.
Save tuxlinuxien/48abdfbd4f5a1cda1c151edad07d7e78 to your computer and use it in GitHub Desktop.
simple golang htt2 server ( go >= 1.6)
package main
/*
** generate certifictes:
** $> openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout key.pem -out cert.pem
** [...]
** Country Name (2 letter code) [AU]:CN
** State or Province Name (full name) [Some-State]:
** Locality Name (eg, city) []:
** Organization Name (eg, company) [Internet Widgits Pty Ltd]:
** Organizational Unit Name (eg, section) []:
** Common Name (e.g. server FQDN or YOUR name) []:localhost:8080 <---- IMPORTANT!
** Email Address []:
**
*/
import (
"fmt"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there!")
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServeTLS(":8080", "cert.pem", "key.pem", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment