updates
This commit is contained in:
parent
360105bc64
commit
36c7bf4bef
@ -1,6 +1,10 @@
|
|||||||
|
// ## HTTP Server Canonical Host
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import ("net/http"; "fmt"; "strings")
|
import "net/http"
|
||||||
|
import "strings"
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
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")
|
||||||
@ -28,8 +32,4 @@ func main() {
|
|||||||
http.ListenAndServe(":5000", nil)
|
http.ListenAndServe(":5000", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// == running
|
// todo: comment about https canonicalization
|
||||||
// $ 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
|
|
@ -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
|
@ -1,6 +1,17 @@
|
|||||||
|
// ## HTTP Serve Graceful Shutdown
|
||||||
|
|
||||||
package main
|
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) {
|
func slow(res http.ResponseWriter, req *http.Request) {
|
||||||
fmt.Println("respond at=start")
|
fmt.Println("respond at=start")
|
||||||
@ -76,20 +87,8 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// == todo
|
// todo: clean up logging
|
||||||
// clean up logging
|
// todo: limit shutdown time
|
||||||
// limit shutdown time
|
// todo: factor out to cut-and-pastable against normal app
|
||||||
// wait -> drain
|
// todo: credit http://blog.nella.org/?p=879
|
||||||
// factor out to cut-and-pastable against normal app
|
// todo: comment about tcp servers
|
||||||
|
|
||||||
// == 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
|
|
@ -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
|
@ -1,6 +1,10 @@
|
|||||||
|
// ## HTTP Server Logging
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import ("net/http"; "fmt"; "time")
|
import "net/http"
|
||||||
|
import "time"
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
func runLogging(logs chan string) {
|
func runLogging(logs chan string) {
|
||||||
for log := range logs {
|
for log := range logs {
|
||||||
@ -32,3 +36,5 @@ func main() {
|
|||||||
http.HandleFunc("/", handler)
|
http.HandleFunc("/", handler)
|
||||||
http.ListenAndServe(":5000", nil)
|
http.ListenAndServe(":5000", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: status code?
|
@ -1,6 +1,9 @@
|
|||||||
|
// ## HTTP Server Middleware
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import ("net/http"; "fmt")
|
import "net/http"
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
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")
|
Loading…
x
Reference in New Issue
Block a user