https server
This commit is contained in:
parent
cdcb3e1c00
commit
277a226423
2
README
2
README
@ -54,7 +54,6 @@ gobyexample.com signups
|
|||||||
* listing files
|
* listing files
|
||||||
* tls server
|
* tls server
|
||||||
* tls client
|
* tls client
|
||||||
* https server
|
|
||||||
* https client
|
* https client
|
||||||
* buffered io
|
* buffered io
|
||||||
* tcp proxy
|
* tcp proxy
|
||||||
@ -80,6 +79,7 @@ gobyexample.com signups
|
|||||||
* blackfriday
|
* blackfriday
|
||||||
|
|
||||||
= program ideas
|
= program ideas
|
||||||
|
self-signed cert generator
|
||||||
command line client for public json api
|
command line client for public json api
|
||||||
redis server
|
redis server
|
||||||
github webook receiver
|
github webook receiver
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import ("net/http"; "io")
|
import "net/http"
|
||||||
|
|
||||||
func hello(res http.ResponseWriter, req *http.Request) {
|
func hello(res http.ResponseWriter, req *http.Request) {
|
||||||
res.Header().Set("Content-Type", "text/plain")
|
res.Header().Set("Content-Type", "text/plain")
|
||||||
io.WriteString(res, "Hello From HTTP\n")
|
res.Write([]byte("Hello From HTTP\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
26
src/xx-https-server.go
Normal file
26
src/xx-https-server.go
Normal 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/
|
Loading…
x
Reference in New Issue
Block a user