From fee3a928f82ed34b66e04ff84bc521f0c7faaf25 Mon Sep 17 00:00:00 2001 From: Christian Hercules Date: Fri, 15 Mar 2019 23:03:09 -0700 Subject: [PATCH 1/9] Updates to README and solution --- 022_hands-on/02/11_hands-on/README.md | 4 ++-- 024_hands-on/12_solution/main.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/022_hands-on/02/11_hands-on/README.md b/022_hands-on/02/11_hands-on/README.md index 64aaf71c..044f91eb 100644 --- a/022_hands-on/02/11_hands-on/README.md +++ b/022_hands-on/02/11_hands-on/README.md @@ -1,6 +1,6 @@ # Building upon the code from the previous problem: -Before we WRITE our RESPONSE , let's WRITE to our RESPONSE the STATUS LINE and some REPONSE HEADERS. Remember the request line and status line: +Before we WRITE our RESPONSE, let's WRITE to our RESPONSE the STATUS LINE and some RESPONSE HEADERS. Remember the request line and status line: REQUEST LINE GET / HTTP/1.1 @@ -22,4 +22,4 @@ fmt.Fprint(c, "Content-Type: text/plain\r\n") "\r\n" -Look in your browser "developer tools" under the network tab. Compare the RESPONSE HEADERS from the previous file with the RESPONSE HEADERS in your new solution. \ No newline at end of file +Look in your browser "developer tools" under the network tab. Compare the RESPONSE HEADERS from the previous file with the RESPONSE HEADERS in your new solution. diff --git a/024_hands-on/12_solution/main.go b/024_hands-on/12_solution/main.go index 8f8bf128..7e59a3e7 100644 --- a/024_hands-on/12_solution/main.go +++ b/024_hands-on/12_solution/main.go @@ -14,8 +14,8 @@ func init() { func main() { http.HandleFunc("/", index) - http.HandleFunc("/about", about) - http.HandleFunc("/contact", contact) + http.HandleFunc("/about/", about) + http.HandleFunc("/contact/", contact) http.HandleFunc("/apply", apply) http.ListenAndServe(":8080", nil) } From d24a149a115f972a9e5c701306fc114133ab5689 Mon Sep 17 00:00:00 2001 From: Dennis Slavinsky Date: Sun, 26 May 2019 17:11:50 -0600 Subject: [PATCH 2/9] Redundant conn.Close() --- 022_hands-on/02/04_solution/main.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/022_hands-on/02/04_solution/main.go b/022_hands-on/02/04_solution/main.go index 7740f10b..2fdb743c 100644 --- a/022_hands-on/02/04_solution/main.go +++ b/022_hands-on/02/04_solution/main.go @@ -34,7 +34,5 @@ func main() { // how does the above reader know when it's done? fmt.Println("Code got here.") io.WriteString(conn, "I see you connected.") - - conn.Close() } } From 7bba7985ef0c1354a9811760433745c0735e90e8 Mon Sep 17 00:00:00 2001 From: Sklep Date: Sat, 15 Jun 2019 22:01:37 +0200 Subject: [PATCH 3/9] cleaned getUser function and fixed issue with generating new uuid --- 030_sessions/03_signup/main.go | 7 ++++--- 030_sessions/03_signup/session.go | 16 ++++------------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/030_sessions/03_signup/main.go b/030_sessions/03_signup/main.go index a1da2c8d..48f0d58c 100644 --- a/030_sessions/03_signup/main.go +++ b/030_sessions/03_signup/main.go @@ -1,9 +1,10 @@ package main import ( - "github.com/satori/go.uuid" "html/template" "net/http" + + uuid "github.com/satori/go.uuid" ) type user struct { @@ -30,12 +31,12 @@ func main() { } func index(w http.ResponseWriter, req *http.Request) { - u := getUser(w, req) + u := getUser(req) tpl.ExecuteTemplate(w, "index.gohtml", u) } func bar(w http.ResponseWriter, req *http.Request) { - u := getUser(w, req) + u := getUser(req) if !alreadyLoggedIn(req) { http.Redirect(w, req, "/", http.StatusSeeOther) return diff --git a/030_sessions/03_signup/session.go b/030_sessions/03_signup/session.go index 17a72572..bda111e9 100644 --- a/030_sessions/03_signup/session.go +++ b/030_sessions/03_signup/session.go @@ -2,26 +2,18 @@ package main import ( "net/http" - - "github.com/satori/go.uuid" ) -func getUser(w http.ResponseWriter, req *http.Request) user { +func getUser(req *http.Request) user { + var u user + // get cookie c, err := req.Cookie("session") if err != nil { - sID, _ := uuid.NewV4() - c = &http.Cookie{ - Name: "session", - Value: sID.String(), - } - + return u } - //Next line may not be required, commenting it - // http.SetCookie(w, c) // if the user exists already, get user - var u user if un, ok := dbSessions[c.Value]; ok { u = dbUsers[un] } From c85a4b78515d84e46db06513f31de11ef35397d0 Mon Sep 17 00:00:00 2001 From: Dave Clement Date: Fri, 15 Nov 2019 19:19:05 -0800 Subject: [PATCH 4/9] fix numeric identifier in readme --- 015_understanding-TCP-servers/06_dial-write/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/015_understanding-TCP-servers/06_dial-write/README.md b/015_understanding-TCP-servers/06_dial-write/README.md index 3d836a76..5e9cdb6f 100644 --- a/015_understanding-TCP-servers/06_dial-write/README.md +++ b/015_understanding-TCP-servers/06_dial-write/README.md @@ -1,3 +1,3 @@ run "02_read-scanner" -run "07_dial-write" \ No newline at end of file +run "06_dial-write" \ No newline at end of file From 479d7e03cbc2d32dbaff7308280cc31d2a3d58c2 Mon Sep 17 00:00:00 2001 From: di-reu Date: Wed, 27 Nov 2019 11:57:05 +0100 Subject: [PATCH 5/9] update appengine deployment for v1.13 --- 026_appengine-deploy/01/app.yaml | 8 +++----- 026_appengine-deploy/02/app.yaml | 8 +++----- 026_appengine-deploy/README.md | 14 ++++++-------- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/026_appengine-deploy/01/app.yaml b/026_appengine-deploy/01/app.yaml index 1dd8f1c6..fb82ec67 100644 --- a/026_appengine-deploy/01/app.yaml +++ b/026_appengine-deploy/01/app.yaml @@ -1,8 +1,6 @@ -application: temp-145415 -version: 1 -runtime: go -api_version: go1 +runtime: go113 handlers: - url: /.* - script: _go_app \ No newline at end of file + script: auto + secure: always \ No newline at end of file diff --git a/026_appengine-deploy/02/app.yaml b/026_appengine-deploy/02/app.yaml index 1dd8f1c6..fb82ec67 100644 --- a/026_appengine-deploy/02/app.yaml +++ b/026_appengine-deploy/02/app.yaml @@ -1,8 +1,6 @@ -application: temp-145415 -version: 1 -runtime: go -api_version: go1 +runtime: go113 handlers: - url: /.* - script: _go_app \ No newline at end of file + script: auto + secure: always \ No newline at end of file diff --git a/026_appengine-deploy/README.md b/026_appengine-deploy/README.md index 247ba1be..1ef5179c 100644 --- a/026_appengine-deploy/README.md +++ b/026_appengine-deploy/README.md @@ -1,4 +1,4 @@ -# buying a domain + # buying a domain https://domains.google/#/ @@ -13,18 +13,16 @@ https://domains.google/#/ - update the app.yaml file with your project ID ``` -application: temp-137512 -version: 1 -runtime: go -api_version: go1 +runtime: go113 handlers: - url: /.* - script: _go_app + script: auto + secure: always ``` -- deploy to that project +- deploy to that project. update --project with your project-id ``` -appcfg.py -A -V v1 update . +gcloud app deploy --project temp-137512 ``` - view your project - http://YOUR_PROJECT_ID.appspot.com/ From 388c20d1b93c37c7a8922cc15f3143ed0d3d2750 Mon Sep 17 00:00:00 2001 From: Mark Rosemaker <48681726+MarkRosemaker@users.noreply.github.com> Date: Thu, 12 Dec 2019 19:17:54 +0100 Subject: [PATCH 6/9] make localhost:8080/dog/ work --- 023_serving-files/02_serving/04_FileServer/01/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/023_serving-files/02_serving/04_FileServer/01/main.go b/023_serving-files/02_serving/04_FileServer/01/main.go index 5ff93afd..34a0df2a 100644 --- a/023_serving-files/02_serving/04_FileServer/01/main.go +++ b/023_serving-files/02_serving/04_FileServer/01/main.go @@ -7,11 +7,11 @@ import ( func main() { http.Handle("/", http.FileServer(http.Dir("."))) - http.HandleFunc("/dog", dog) + http.HandleFunc("/dog/", dog) http.ListenAndServe(":8080", nil) } func dog(w http.ResponseWriter, req *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf-8") - io.WriteString(w, ``) + io.WriteString(w, ``) } From 84dcfc26bb901a9051f8d5add58a1a04b0ebad59 Mon Sep 17 00:00:00 2001 From: Mark Rosemaker <48681726+MarkRosemaker@users.noreply.github.com> Date: Fri, 13 Dec 2019 20:16:34 +0100 Subject: [PATCH 7/9] make new version work I've spend some time trying to figure out why it didn't work for me. The reason is that Google updated the system. Google's changes: - use main() instead of init() - specify go version in app.yaml - most other declarations in app.yaml now invalid - pass project name and version as flags in the gcloud command - python install not needed anymore Plus, you need ListenAndServe of course! ;) I can confirm that it now works with the changes I made to the files. --- 026_appengine-deploy/README.md | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/026_appengine-deploy/README.md b/026_appengine-deploy/README.md index 247ba1be..da3c87d6 100644 --- a/026_appengine-deploy/README.md +++ b/026_appengine-deploy/README.md @@ -4,27 +4,18 @@ https://domains.google/#/ # deploying to [Google Cloud](https://cloud.google.com/) - [install google appengine](https://cloud.google.com/appengine/docs/go/download) -- [make sure python is installed VERSION 2.7.x](https://www.python.org/downloads/release/python-2712/) - - python -V - configure environment PATH variables - google cloud developer console - create a project - get the project ID -- update the app.yaml file with your project ID +- set your go version in the app.yaml file ``` -application: temp-137512 -version: 1 -runtime: go -api_version: go1 - -handlers: -- url: /.* - script: _go_app +runtime: go113 ``` - deploy to that project ``` -appcfg.py -A -V v1 update . +gcloud app deploy app.yaml --project= -v 1 ``` - view your project - http://YOUR_PROJECT_ID.appspot.com/ From 304c653fbc7c6625f2a88a55bbea40987afe06a8 Mon Sep 17 00:00:00 2001 From: Mark Rosemaker <48681726+MarkRosemaker@users.noreply.github.com> Date: Fri, 13 Dec 2019 20:22:14 +0100 Subject: [PATCH 8/9] make new version work - Google now wants you to use main instead of init - don't forget to ListenAndServe --- 026_appengine-deploy/01/main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/026_appengine-deploy/01/main.go b/026_appengine-deploy/01/main.go index 68523458..671d6b1d 100644 --- a/026_appengine-deploy/01/main.go +++ b/026_appengine-deploy/01/main.go @@ -4,6 +4,7 @@ import ( "net/http" ) -func init() { +func main() { http.Handle("/", http.FileServer(http.Dir("."))) + http.ListenAndServe(":8080", nil) } From f862b2b7bba75300c8c47eacab15b8933ae110a3 Mon Sep 17 00:00:00 2001 From: Mark Rosemaker <48681726+MarkRosemaker@users.noreply.github.com> Date: Fri, 13 Dec 2019 20:22:22 +0100 Subject: [PATCH 9/9] make new version work - Google now wants you to use main instead of init - don't forget to ListenAndServe --- 026_appengine-deploy/02/main.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/026_appengine-deploy/02/main.go b/026_appengine-deploy/02/main.go index 68523458..671d6b1d 100644 --- a/026_appengine-deploy/02/main.go +++ b/026_appengine-deploy/02/main.go @@ -4,6 +4,7 @@ import ( "net/http" ) -func init() { +func main() { http.Handle("/", http.FileServer(http.Dir("."))) + http.ListenAndServe(":8080", nil) }