https server

This commit is contained in:
Mark McGranaghan 2012-09-19 06:08:50 -07:00
parent cdcb3e1c00
commit 277a226423
3 changed files with 29 additions and 3 deletions

2
README
View File

@ -54,7 +54,6 @@ gobyexample.com signups
* listing files
* tls server
* tls client
* https server
* https client
* buffered io
* tcp proxy
@ -80,6 +79,7 @@ gobyexample.com signups
* blackfriday
= program ideas
self-signed cert generator
command line client for public json api
redis server
github webook receiver

View File

@ -1,10 +1,10 @@
package main
import ("net/http"; "io")
import "net/http"
func hello(res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Type", "text/plain")
io.WriteString(res, "Hello From HTTP\n")
res.Write([]byte("Hello From HTTP\n"))
}
func main() {

26
src/xx-https-server.go Normal file
View File

@ -0,0 +1,26 @@
package main
import "net/http"
func handler(res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Type", "text/plain")
res.Write([]byte("Hello from HTTPS\n"))
}
func main() {
http.HandleFunc("/", handler)
err := http.ListenAndServeTLS(":5000", "/tmp/server.crt", "/tmp/server.key", nil)
if err != nil { panic(err) }
}
// $ cd /tmp
// $ rm -f server.*
// $ openssl genrsa -des3 -out server.orig.key 2048
// $ openssl rsa -in server.orig.key -out server.key
// $ openssl req -new -key server.key -out server.csr
// $ openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
// $ go run src/xx-https-server.go
// $ curl https://127.0.0.1:5000/
// $ curl --insecure https://127.0.0.1:5000/