diff --git a/067-http-client/http-client.go b/066-http-client/http-client.go similarity index 100% rename from 067-http-client/http-client.go rename to 066-http-client/http-client.go diff --git a/066-tcp-client/tcp-client.go b/066-tcp-client/tcp-client.go deleted file mode 100644 index 7cd4cdb..0000000 --- a/066-tcp-client/tcp-client.go +++ /dev/null @@ -1,29 +0,0 @@ -// ## TCP Client - -package main - -import "net" -import "fmt" - -func main() { - c, err := net.Dial("tcp", "127.0.0.1:5000") - if err != nil { - panic(err) - } - - msg := "hello world" - fmt.Println("Sending: ", msg) - _, err = c.Write([]byte(msg)) - if err != nil { - panic(err) - } - - buf := make([]byte, 1024) - _, err = c.Read(buf) - if err != nil { - panic(err) - } else { - fmt.Println("Received:", string(buf)) - c.Close() - } -} diff --git a/066-tcp-client/tcp-client.sh b/066-tcp-client/tcp-client.sh deleted file mode 100644 index b722f08..0000000 --- a/066-tcp-client/tcp-client.sh +++ /dev/null @@ -1,3 +0,0 @@ -$ go run tcp-client.go -Sending: hello world -Received: hello world diff --git a/068-http-client-basic/http-client-basic.go b/067-http-client-basic/http-client-basic.go similarity index 100% rename from 068-http-client-basic/http-client-basic.go rename to 067-http-client-basic/http-client-basic.go diff --git a/069-https-client/https-client.go b/068-https-client/https-client.go similarity index 100% rename from 069-https-client/https-client.go rename to 068-https-client/https-client.go diff --git a/070-redis/redis.go b/069-redis/redis.go similarity index 100% rename from 070-redis/redis.go rename to 069-redis/redis.go diff --git a/070-redis/redis.sh b/069-redis/redis.sh similarity index 100% rename from 070-redis/redis.sh rename to 069-redis/redis.sh diff --git a/071-postgres/postgres.go b/070-postgres/postgres.go similarity index 100% rename from 071-postgres/postgres.go rename to 070-postgres/postgres.go diff --git a/071-postgres/postgres.sh b/070-postgres/postgres.sh similarity index 100% rename from 071-postgres/postgres.sh rename to 070-postgres/postgres.sh diff --git a/072-sending-email/sending-email.go b/071-sending-email/sending-email.go similarity index 100% rename from 072-sending-email/sending-email.go rename to 071-sending-email/sending-email.go diff --git a/083-http-server/http-server.go b/072-hello-web/hello-web.go similarity index 79% rename from 083-http-server/http-server.go rename to 072-hello-web/hello-web.go index 8f61694..d5a65d7 100644 --- a/083-http-server/http-server.go +++ b/072-hello-web/hello-web.go @@ -1,4 +1,4 @@ -// ## HTTP Server +// ## Hello Web package main @@ -6,7 +6,7 @@ import "net/http" func hello(res http.ResponseWriter, req *http.Request) { res.Header().Set("Content-Type", "text/plain") - res.Write([]byte("Hello From HTTP\n")) + res.Write([]byte("Hello web\n")) } func main() { diff --git a/082-http-server-status-code/http-server-status-code.go b/073-responses/responses.go similarity index 92% rename from 082-http-server-status-code/http-server-status-code.go rename to 073-responses/responses.go index b51748e..bb9671e 100644 --- a/082-http-server-status-code/http-server-status-code.go +++ b/073-responses/responses.go @@ -1,4 +1,4 @@ -// ## HTTP Server Status Code +// ## Responses package main diff --git a/082-http-server-status-code/http-server-status-code.sh b/073-responses/responses.sh similarity index 100% rename from 082-http-server-status-code/http-server-status-code.sh rename to 073-responses/responses.sh diff --git a/078-http-server-routing/http-server-routing.go b/074-request-routing/request-routing.go similarity index 100% rename from 078-http-server-routing/http-server-routing.go rename to 074-request-routing/request-routing.go diff --git a/078-http-server-routing/http-server-routing.sh b/074-request-routing/request-routing.sh similarity index 69% rename from 078-http-server-routing/http-server-routing.sh rename to 074-request-routing/request-routing.sh index f61b62a..c358da8 100644 --- a/078-http-server-routing/http-server-routing.sh +++ b/074-request-routing/request-routing.sh @@ -1,4 +1,4 @@ $ go get github.com/bmizerany/pat -$ go run xx-http-server-routing.go +$ go run request-routing.go $ curl -i http://127.0.0.1:5000/hello/gopher diff --git a/075-http-server-graceful-shutdown/http-server-graceful-shutdown.sh b/075-http-server-graceful-shutdown/http-server-graceful-shutdown.sh deleted file mode 100644 index 5b0e94f..0000000 --- a/075-http-server-graceful-shutdown/http-server-graceful-shutdown.sh +++ /dev/null @@ -1,7 +0,0 @@ -$ cd src -$ go build xx-http-server-graceful-shutdown.go -$ ./xx-http-server-graceful-shutdown - -$ curl -i http://127.0.0.1:5000/ - -^C diff --git a/076-http-server-log/http-server-log.go b/075-request-logging/request-logging.go similarity index 94% rename from 076-http-server-log/http-server-log.go rename to 075-request-logging/request-logging.go index 5841bdd..7af01dc 100644 --- a/076-http-server-log/http-server-log.go +++ b/075-request-logging/request-logging.go @@ -1,4 +1,4 @@ -// ## HTTP Server Logging +// ## Request Logging package main @@ -37,4 +37,4 @@ func main() { http.ListenAndServe(":5000", nil) } -// todo: status code? +// todo: logging status code? diff --git a/081-http-server-static/http-server-static.go b/076-static-content/static-content.go similarity index 89% rename from 081-http-server-static/http-server-static.go rename to 076-static-content/static-content.go index 0f0acbf..52c3672 100644 --- a/081-http-server-static/http-server-static.go +++ b/076-static-content/static-content.go @@ -1,4 +1,4 @@ -// ## HTTP Server Static +// ## Static Content package main diff --git a/081-http-server-static/http-server-static.sh b/076-static-content/static-content.sh similarity index 79% rename from 081-http-server-static/http-server-static.sh rename to 076-static-content/static-content.sh index bd95207..135fcc3 100644 --- a/081-http-server-static/http-server-static.sh +++ b/076-static-content/static-content.sh @@ -1,4 +1,4 @@ -$ go run http-server-static.go +$ go run static-content.go $ curl http://127.0.0.1:5000/ $ curl http://127.0.0.1:5000/http-server-static.go diff --git a/073-http-server-basic/http-server-basic.go b/077-basic-authentication/basic-authentication.go similarity index 97% rename from 073-http-server-basic/http-server-basic.go rename to 077-basic-authentication/basic-authentication.go index 8b6d811..cecb132 100644 --- a/073-http-server-basic/http-server-basic.go +++ b/077-basic-authentication/basic-authentication.go @@ -1,4 +1,4 @@ -// ## HTTP Server Basic +// ## Basic Authentication package main diff --git a/074-http-server-canonical-host/http-server-canonical-host.go b/078-canonical-hosts/canonical-hosts.go similarity index 96% rename from 074-http-server-canonical-host/http-server-canonical-host.go rename to 078-canonical-hosts/canonical-hosts.go index 4116b27..b53ab01 100644 --- a/074-http-server-canonical-host/http-server-canonical-host.go +++ b/078-canonical-hosts/canonical-hosts.go @@ -1,4 +1,4 @@ -// ## HTTP Server Canonical Host +// ## Canonical Hosts package main diff --git a/074-http-server-canonical-host/http-server-canonical-host.sh b/078-canonical-hosts/canonical-hosts.sh similarity index 64% rename from 074-http-server-canonical-host/http-server-canonical-host.sh rename to 078-canonical-hosts/canonical-hosts.sh index 62a3f7e..f2582cc 100644 --- a/074-http-server-canonical-host/http-server-canonical-host.sh +++ b/078-canonical-hosts/canonical-hosts.sh @@ -1,4 +1,4 @@ -$ go run xx-http-server-canonical-host.go +$ go run canonical-hosts.go $ curl -i -L http://127.0.0.1:5000/go $ curl -i -L http://127.0.0.1:5000/go diff --git a/079-http-server-static-dynamic/http-server-static-dynamic.go b/079-http-server-static-dynamic/http-server-static-dynamic.go deleted file mode 100644 index 0329b34..0000000 --- a/079-http-server-static-dynamic/http-server-static-dynamic.go +++ /dev/null @@ -1,22 +0,0 @@ -// ## HTTP Server Static Dynamic - -package main - -import "net/http" - -func hello(res http.ResponseWriter, req *http.Request) { - res.Header().Set("Content-Type", "text/plain") - res.Write([]byte("Hello From HTTP\n")) -} - -func main() { - helloHandler := http.HandlerFunc(hello) - staticHandler := http.StripPrefix("/static/", http.FileServer(http.Dir("./"))) - http.Handle("/hello", helloHandler) - http.Handle("/static/", staticHandler) - http.ListenAndServe(":5000", nil) -} - -// todo: try to get dynamic at root -// todo: try to get static at root -// todo: favicon diff --git a/079-http-server-static-dynamic/http-server-static-dynamic.sh b/079-http-server-static-dynamic/http-server-static-dynamic.sh deleted file mode 100644 index cf1d030..0000000 --- a/079-http-server-static-dynamic/http-server-static-dynamic.sh +++ /dev/null @@ -1,6 +0,0 @@ -$ cd src -$ go run xx-http-server-static-dynamic.go - -$ curl http://127.0.0.1:5000/hello -$ curl http://127.0.0.1:5000/static -$ curl http://127.0.0.1:5000/static/01-hello.go diff --git a/077-http-server-middleware/http-server-middleware.go b/079-middleware/middleware.go similarity index 94% rename from 077-http-server-middleware/http-server-middleware.go rename to 079-middleware/middleware.go index b0be22f..6f85166 100644 --- a/077-http-server-middleware/http-server-middleware.go +++ b/079-middleware/middleware.go @@ -1,4 +1,4 @@ -// ## HTTP Server Middleware +// ## Middleware package main diff --git a/075-http-server-graceful-shutdown/http-server-graceful-shutdown.go b/080-graceful-shutdown/graceful-shutdown.go similarity index 98% rename from 075-http-server-graceful-shutdown/http-server-graceful-shutdown.go rename to 080-graceful-shutdown/graceful-shutdown.go index a0e9635..27ec0e5 100644 --- a/075-http-server-graceful-shutdown/http-server-graceful-shutdown.go +++ b/080-graceful-shutdown/graceful-shutdown.go @@ -1,4 +1,4 @@ -// ## HTTP Serve Graceful Shutdown +// ## Graceful Shutdown package main diff --git a/080-graceful-shutdown/graceful-shutdown.sh b/080-graceful-shutdown/graceful-shutdown.sh new file mode 100644 index 0000000..824b09b --- /dev/null +++ b/080-graceful-shutdown/graceful-shutdown.sh @@ -0,0 +1,6 @@ +$ go build graceful-shutdown.go +$ ./graceful-shutdown + +$ curl -i http://127.0.0.1:5000/ + +^C diff --git a/080-http-server-static-select/http-server-static-select.go b/080-http-server-static-select/http-server-static-select.go deleted file mode 100644 index 78e9483..0000000 --- a/080-http-server-static-select/http-server-static-select.go +++ /dev/null @@ -1,30 +0,0 @@ -// ## HTTP Server Static Select - -package main - -import "code.google.com/p/gorilla/mux" -import "net/http" -import "fmt" - -func hello(res http.ResponseWriter, req *http.Request) { - res.Header().Set("Content-Type", "text/plain") - fmt.Fprintln(res, "Hello") -} - -func static(res http.ResponseWriter, req *http.Request) { - http.ServeFile(res, req, "./01-hello.go") -} - -func notFound(res http.ResponseWriter, req *http.Request) { - res.Header().Set("Content-Type", "text/plain") - res.WriteHeader(404) - fmt.Fprintln(res, "Not found: /" + mux.Vars(req)["path"]) -} - -func main() { - r := mux.NewRouter() - r.HandleFunc("/", hello) - r.HandleFunc("/01-hello.go", static) - r.HandleFunc("/{path:.*}", notFound) - http.ListenAndServe(":5000", r) -} diff --git a/080-http-server-static-select/http-server-static-select.sh b/080-http-server-static-select/http-server-static-select.sh deleted file mode 100644 index 5742eff..0000000 --- a/080-http-server-static-select/http-server-static-select.sh +++ /dev/null @@ -1,7 +0,0 @@ -$ go get code.google.com/p/gorilla/mux -$ go run xx-http-server-static-select.go - -$ curl -i http://127.0.0.1:5000/ -$ curl -i http://127.0.0.1:5000/favicon.ico -$ curl -i http://127.0.0.1:5000/wat -$ curl -i http://127.0.0.1:5000/wat/wat diff --git a/084-https-server/https-server.go b/084-https-server/https-servers.go similarity index 94% rename from 084-https-server/https-server.go rename to 084-https-server/https-servers.go index ecbdc17..11a69e3 100644 --- a/084-https-server/https-server.go +++ b/084-https-server/https-servers.go @@ -1,4 +1,4 @@ -// ## HTTPS Server +// ## HTTPS Servers package main diff --git a/084-https-server/https-server.sh b/084-https-server/https-servers.sh similarity index 91% rename from 084-https-server/https-server.sh rename to 084-https-server/https-servers.sh index 8e03639..7b63787 100644 --- a/084-https-server/https-server.sh +++ b/084-https-server/https-servers.sh @@ -5,7 +5,7 @@ $ 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 +$ go run https-servers.go $ curl https://127.0.0.1:5000/ $ curl --insecure https://127.0.0.1:5000/ diff --git a/tool/index.txt b/tool/index.txt index eea2003..6be221e 100644 --- a/tool/index.txt +++ b/tool/index.txt @@ -93,21 +93,19 @@ mongodb ~ sending-email ## web apps -http-server-basic -http-server-canonical-host -http-server-graceful-shutdown -http-server-log -http-server-middleware -http-server-routing -http-server-static-dynamic -http-server-static-select -http-server-static -http-server-status-code -http-server -https-server -headers-and-query-params ~ +hello-web +requests ~ +responses +request-routing +request-logging +static-content +basic-authentication +canonical-hosts post-bodies ~ +middleware streaming-out-http-responses ~ +graceful-shutdown +https-servers ## shipping go using-gofmt ~