{"id":23209538,"url":"https://github.com/devenock/let-s-go","last_synced_at":"2025-04-05T12:13:41.356Z","repository":{"id":267522222,"uuid":"861992361","full_name":"devenock/let-s-go","owner":"devenock","description":"Let's Go Book code documentation","archived":false,"fork":false,"pushed_at":"2024-09-30T09:54:33.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-10T23:34:47.410Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/devenock.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-23T20:58:44.000Z","updated_at":"2024-09-30T09:54:37.000Z","dependencies_parsed_at":"2024-12-10T20:40:33.881Z","dependency_job_id":"cc0ce976-8b53-4c42-b6e2-0a9886aad5be","html_url":"https://github.com/devenock/let-s-go","commit_stats":null,"previous_names":["devenock/let-s-go"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devenock%2Flet-s-go","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devenock%2Flet-s-go/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devenock%2Flet-s-go/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devenock%2Flet-s-go/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devenock","download_url":"https://codeload.github.com/devenock/let-s-go/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247332601,"owners_count":20921854,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-18T18:17:54.510Z","updated_at":"2025-04-05T12:13:41.328Z","avatar_url":"https://github.com/devenock.png","language":"CSS","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Let's Go\n\n\u003c!-- TOC --\u003e\n* [Let's Go](#lets-go)\n  * [chapter 1: INTRODUCTION](#chapter-1-introduction)\n  * [chapter 2: FOUNDATIONS](#chapter-2-foundations)\n  * [chapter 3: CONFIGURATION AND ERROR HANDLING](#chapter-3-configuration-and-error-handling)\n  * [chapter 4: DATABASE-DRIVEN RESPONSES](#chapter-4-database-driven-responses)\n  * [chapter 5: DYNAMIC HTML TEMPLATES](#chapter-5-dynamic-html-templates)\n  * [chapter 6: MIDDLEWARE](#chapter-6-middleware)\n  * [chapter 7: RESTFUL ROUTING](#chapter-7-restful-routing)\n  * [chapter 8: PROCESSING FORMS](#chapter-8-processing-forms)\n  * [chapter 9: STATEFUL HTTP](#chapter-9-stateful-http)\n  * [chapter 10: SECURITY IMPROVEMENTS](#chapter-10-security-improvements)\n  * [chapter 11: USER AUTHENTICATION](#chapter-11-user-authentication)\n  * [chapter 12: USING REQUEST CONTEXT](#chapter-12-using-request-context)\n  * [chapter 13: TESTING](#chapter-13-testing)\n  * [chapter 14: CONCLUSION](#chapter-14-conclusion)\n  * [chapter 15: APPENDICES](#chapter-15-appendices)\n  * [chapter 16: GUIDED EXERCISES](#chapter-16-guided-exercises)\n    * [Path Types](#path-types)\n\u003c!-- TOC --\u003e\n\n## chapter 1: INTRODUCTION\n\n\n## chapter 2: FOUNDATIONS\nYou can check your Go version after a successful installation by running : `go version`\n\nTo create a new project in Go, create a new directory anywhere on your computer and initialize a module\nby running: `go mod init \u003cpath\u003e`\n\nThe module path is just the canonical name or identifier for your project.\n\nTo know more about your Go current installation and environment, open the terminal and run: `go env `\n\nTo create a web application in Go, we need 3 most essential components:\n1. **Handler**: If you're from the MVC background, you can think of them as controllers. They are responsible\nfor executing your application logic and for writing HTTP response headers and bodies.\n2. **Router**: It is also known as _**servemux**_ in Go.\n3. **Web server**: This is the last thing that we need and you can always establish a web server and listen to it \nnatively without importing any third-party package.\n\n`http.Handle()` and `http.HandleFunc()` allows you to create routes without declaring a servemux.\n\n\n`http.HandleFunc(\"/\", home) `\n\n`http.HandleFunc(\"/snippet\", showSnippet)`\n\nBehind the scenes, these functions register their routes with something called `DefaultServeMux` which is just a regular\nservemux which is initialized by default and stored in the `net/http` package.\n\n## chapter 3: CONFIGURATION AND ERROR HANDLING\n\n## chapter 4: DATABASE-DRIVEN RESPONSES\n\n## chapter 5: DYNAMIC HTML TEMPLATES\n\n## chapter 6: MIDDLEWARE\n\n## chapter 7: RESTFUL ROUTING\n\n## chapter 8: PROCESSING FORMS\n\n## chapter 9: STATEFUL HTTP\n\n## chapter 10: SECURITY IMPROVEMENTS\n\n## chapter 11: USER AUTHENTICATION\n\n## chapter 12: USING REQUEST CONTEXT\n\n## chapter 13: TESTING\n\n## chapter 14: CONCLUSION\n\n## chapter 15: APPENDICES\n\n## chapter 16: GUIDED EXERCISES\n\n\n\n### Path Types\n\n**Fixed path:** has no trailing slash\n\n**Subtree path:** has a trailing slash(/)\n\nTo make a check for the paths, just include a check of the URL path inside the handle function.\n\n[//]: # (checks)\nIt is possible to call `w.WriteHeader()` method just once per response and it should always be called \nbefore `w.Write()`. This is because if the later is called first, it will send a status code of 200\nto the use but if you want to send a status code different from 200, then call the `w.WriteHeader()` before.\n\n`package main\nimport (\n\"fmt\"\n\"log\"\n\"net/http\"\n\"strconv\"\n)\n//define route handlers`\n\n`// home handler\nfunc home(w http.ResponseWriter, r *http.Request) {\n//assertains the path\nif r.URL.Path != \"/\" {\nhttp.NotFound(w, r)\nreturn\n}\nw.Write([]byte(\"Let's Go!\"))\n}`\n\n`// snippet handler\nfunc showSnippet(w http.ResponseWriter, r *http.Request) {\n//to get query params from a URL string\nid, err := strconv.Atoi(r.URL.Query().Get(\"id\"))\nfmt.Println(id, err)\nif err != nil || id \u003c 1 {\nhttp.NotFound(w, r)\nreturn\n}\nw.Write([]byte(\"This is your code snippet!\"))\n}`\n\n`// create snippet\nfunc createSnippet(w http.ResponseWriter, r *http.Request) {\n        //check for the write HTTP method\n        if r.Method != http.MethodPost {\n        //set allowed method\n        w.Header().Set(\"Allow\", http.MethodPost)\n\t\t//other helper functions from w.Header method\n\t\tw.Header().Set(\"Cache-Control\", \"public, max-age=31536000\")\n\t\t//add appends the headers\n\t\tw.Header().Add(\"Content-Type\", \"text/plain\")\n\t\tw.Header().Add(\"Cache-Control\", \"public\")\n\t\tw.Header().Add(\"Cache-Control\", \"max-age=31536000\")\n\t\t//del, deletes the headers\n\t\tw.Header().Del(\"Cache-Control\")\n\t\t//set status code explicitly\n\t\t//w.WriteHeader(405)\n\t\t//w.Write([]byte(\"Method not allowed\"))\n\t\t//replaces the above method calls and calls them behind the scene\n\t\thttp.Error(w, \"Method not allowed\", 405)\n\t\treturn\n\t}\n\tw.Write([]byte(\"Create your code snippet!\"))\n}`\n\n`func main() {\n\t//initialize a server\n\tmux := http.NewServeMux()\n\tmux.HandleFunc(\"/\", home)\n\tmux.HandleFunc(\"/snippet\", showSnippet)\n\tmux.HandleFunc(\"/snippet/create\", createSnippet)\n\t//\tlisten to port\n\tlog.Println(\"Listening on port :4000\")\n\terr := http.ListenAndServe(\":4000\", mux)\n\tlog.Fatal(err)\n}\n`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevenock%2Flet-s-go","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevenock%2Flet-s-go","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevenock%2Flet-s-go/lists"}