This commit is contained in:
Mark McGranaghan 2012-09-23 12:22:32 -07:00
parent 360105bc64
commit 36c7bf4bef
6 changed files with 45 additions and 26 deletions

View File

@ -1,6 +1,10 @@
// ## HTTP Server Canonical Host
package main
import ("net/http"; "fmt"; "strings")
import "net/http"
import "strings"
import "fmt"
func hello(res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Type", "text/plain")
@ -28,8 +32,4 @@ func main() {
http.ListenAndServe(":5000", nil)
}
// == running
// $ go run xx-http-server-canonical-host.go
//
// $ curl -i -L http://127.0.0.1:5000/go
// $ curl -i -L http://127.0.0.1:5000/go
// todo: comment about https canonicalization

View File

@ -0,0 +1,4 @@
$ go run xx-http-server-canonical-host.go
$ curl -i -L http://127.0.0.1:5000/go
$ curl -i -L http://127.0.0.1:5000/go

View File

@ -1,6 +1,17 @@
// ## HTTP Serve Graceful Shutdown
package main
import ("net"; "net/http"; "time"; "os"; "os/signal"; "syscall"; "fmt"; "sync/atomic")
import (
"net"
"net/http"
"time"
"os"
"os/signal"
"syscall"
"fmt"
"sync/atomic"
)
func slow(res http.ResponseWriter, req *http.Request) {
fmt.Println("respond at=start")
@ -76,20 +87,8 @@ func main() {
}
}
// == todo
// clean up logging
// limit shutdown time
// wait -> drain
// factor out to cut-and-pastable against normal app
// == running
// $ cd src
// $ go build xx-http-server-graceful-shutdown.go
// $ ./xx-http-server-graceful-shutdown
//
// $ curl -i http://127.0.0.1:5000/
//
// ^C
// == credits
// http://blog.nella.org/?p=879
// todo: clean up logging
// todo: limit shutdown time
// todo: factor out to cut-and-pastable against normal app
// todo: credit http://blog.nella.org/?p=879
// todo: comment about tcp servers

View File

@ -0,0 +1,7 @@
$ cd src
$ go build xx-http-server-graceful-shutdown.go
$ ./xx-http-server-graceful-shutdown
$ curl -i http://127.0.0.1:5000/
^C

View File

@ -1,6 +1,10 @@
// ## HTTP Server Logging
package main
import ("net/http"; "fmt"; "time")
import "net/http"
import "time"
import "fmt"
func runLogging(logs chan string) {
for log := range logs {
@ -32,3 +36,5 @@ func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":5000", nil)
}
// todo: status code?

View File

@ -1,6 +1,9 @@
// ## HTTP Server Middleware
package main
import ("net/http"; "fmt")
import "net/http"
import "fmt"
func hello(res http.ResponseWriter, req *http.Request) {
res.Header().Set("Content-Type", "text/plain")