index work
This commit is contained in:
parent
6c1742a4e5
commit
1f7065e387
@ -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()
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,3 +0,0 @@
|
|||||||
$ go run tcp-client.go
|
|
||||||
Sending: hello world
|
|
||||||
Received: hello world
|
|
@ -1,4 +1,4 @@
|
|||||||
// ## HTTP Server
|
// ## Hello Web
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
@ -6,7 +6,7 @@ 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")
|
||||||
res.Write([]byte("Hello From HTTP\n"))
|
res.Write([]byte("Hello web\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
@ -1,4 +1,4 @@
|
|||||||
// ## HTTP Server Status Code
|
// ## Responses
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
$ go get github.com/bmizerany/pat
|
$ 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
|
$ curl -i http://127.0.0.1:5000/hello/gopher
|
@ -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
|
|
@ -1,4 +1,4 @@
|
|||||||
// ## HTTP Server Logging
|
// ## Request Logging
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
@ -37,4 +37,4 @@ func main() {
|
|||||||
http.ListenAndServe(":5000", nil)
|
http.ListenAndServe(":5000", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: status code?
|
// todo: logging status code?
|
@ -1,4 +1,4 @@
|
|||||||
// ## HTTP Server Static
|
// ## Static Content
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
@ -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/
|
||||||
$ curl http://127.0.0.1:5000/http-server-static.go
|
$ curl http://127.0.0.1:5000/http-server-static.go
|
@ -1,4 +1,4 @@
|
|||||||
// ## HTTP Server Basic
|
// ## Basic Authentication
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
// ## HTTP Server Canonical Host
|
// ## Canonical Hosts
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
@ -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
|
||||||
$ curl -i -L http://127.0.0.1:5000/go
|
$ curl -i -L http://127.0.0.1:5000/go
|
@ -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
|
|
@ -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
|
|
@ -1,4 +1,4 @@
|
|||||||
// ## HTTP Server Middleware
|
// ## Middleware
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
// ## HTTP Serve Graceful Shutdown
|
// ## Graceful Shutdown
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
6
080-graceful-shutdown/graceful-shutdown.sh
Normal file
6
080-graceful-shutdown/graceful-shutdown.sh
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
$ go build graceful-shutdown.go
|
||||||
|
$ ./graceful-shutdown
|
||||||
|
|
||||||
|
$ curl -i http://127.0.0.1:5000/
|
||||||
|
|
||||||
|
^C
|
@ -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)
|
|
||||||
}
|
|
@ -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
|
|
@ -1,4 +1,4 @@
|
|||||||
// ## HTTPS Server
|
// ## HTTPS Servers
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
@ -5,7 +5,7 @@ $ openssl rsa -in server.orig.key -out server.key
|
|||||||
$ openssl req -new -key server.key -out server.csr
|
$ openssl req -new -key server.key -out server.csr
|
||||||
$ openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
|
$ 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 https://127.0.0.1:5000/
|
||||||
$ curl --insecure https://127.0.0.1:5000/
|
$ curl --insecure https://127.0.0.1:5000/
|
@ -93,21 +93,19 @@ mongodb ~
|
|||||||
sending-email
|
sending-email
|
||||||
|
|
||||||
## web apps
|
## web apps
|
||||||
http-server-basic
|
hello-web
|
||||||
http-server-canonical-host
|
requests ~
|
||||||
http-server-graceful-shutdown
|
responses
|
||||||
http-server-log
|
request-routing
|
||||||
http-server-middleware
|
request-logging
|
||||||
http-server-routing
|
static-content
|
||||||
http-server-static-dynamic
|
basic-authentication
|
||||||
http-server-static-select
|
canonical-hosts
|
||||||
http-server-static
|
|
||||||
http-server-status-code
|
|
||||||
http-server
|
|
||||||
https-server
|
|
||||||
headers-and-query-params ~
|
|
||||||
post-bodies ~
|
post-bodies ~
|
||||||
|
middleware
|
||||||
streaming-out-http-responses ~
|
streaming-out-http-responses ~
|
||||||
|
graceful-shutdown
|
||||||
|
https-servers
|
||||||
|
|
||||||
## shipping go
|
## shipping go
|
||||||
using-gofmt ~
|
using-gofmt ~
|
||||||
|
Loading…
x
Reference in New Issue
Block a user