{"id":23065724,"url":"https://github.com/ullaskunder3/go-lang","last_synced_at":"2025-08-25T14:04:33.516Z","repository":{"id":265668389,"uuid":"896391900","full_name":"ullaskunder3/go-lang","owner":"ullaskunder3","description":null,"archived":false,"fork":false,"pushed_at":"2025-05-08T11:58:59.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-08T12:41:53.844Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","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/ullaskunder3.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,"zenodo":null}},"created_at":"2024-11-30T08:32:52.000Z","updated_at":"2025-05-08T11:59:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"1981113f-5c10-4ab2-8296-21f200c80d36","html_url":"https://github.com/ullaskunder3/go-lang","commit_stats":null,"previous_names":["ullaskunder3/go-lang"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ullaskunder3/go-lang","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ullaskunder3%2Fgo-lang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ullaskunder3%2Fgo-lang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ullaskunder3%2Fgo-lang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ullaskunder3%2Fgo-lang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ullaskunder3","download_url":"https://codeload.github.com/ullaskunder3/go-lang/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ullaskunder3%2Fgo-lang/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272077690,"owners_count":24869288,"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","status":"online","status_checked_at":"2025-08-25T02:00:12.092Z","response_time":1107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-16T05:09:51.341Z","updated_at":"2025-08-25T14:04:33.475Z","avatar_url":"https://github.com/ullaskunder3.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# **Go Language Notes**\n\nA collection of Go language concepts and examples that explore Go's core features, including variables, types, pointers, structs, arrays, slices, and maps.\n\n---\n\n## **Running Go Code with Nodemon**\n\nYou can use `nodemon` to automatically restart your Go program on file changes:\n\n```sh\nnodemon --exec go run main.go --ext go\n```\n\nTo run tests automatically on file changes:\n\n```sh\nnodemon --exec \"go test ./project\" --ext go\n```\n\nTo test\n\n```sh\nnodemon --exec \"go test -v ./test\" --ext go\n```\n\n---\n\n## **Go Basics**\n\n### **1. Statically Typed Language**\n\n- Go is **statically typed**, meaning that variable types are determined at **compile time** and cannot change at runtime.\n- Even though Go supports **type inference** (`:=`), once a type is assigned, it **cannot change**.\n\n```go\nnum := 10  // Type inferred as int\nnum = \"hello\" // ❌ Error: Cannot assign a string to an int variable\n```\n\n### **2. Why Doesn't `:=` Work Outside Functions?**\n\n- `:=` is **only for function-scoped variables**.\n- At the package level, you **must use** the `var` keyword.\n\n```go\npackage main\n\nvar globalVar = \"This works\" // ✅ Allowed\n\nfunc main() {\n    localVar := \"This also works\" // ✅ Allowed inside a function\n}\n```\n\n---\n\n## **Maps in Go**\n\n### **1. Declaring and Using Maps**\n\n```go\ncolors := map[string]string{\n    \"red\":   \"#ff0000\",\n    \"green\": \"#00ff00\",\n}\ncolors[\"white\"] = \"#ffffff\"\nfmt.Println(colors)\n```\n\n### **2. Checking if a Key Exists**\n\n```go\nvalue, exists := colors[\"blue\"]\nif exists {\n    fmt.Println(\"Found blue:\", value)\n} else {\n    fmt.Println(\"Key 'blue' does not exist\")\n}\n```\n\n### **3. Iterating Over a Map**\n\n```go\nfor key, value := range colors {\n    fmt.Println(key, value)\n}\n```\n\n### **4. Passing Maps to Functions (Reference Behavior)**\n\n```go\nfunc modifyMap(m map[string]string) {\n    m[\"purple\"] = \"#800080\"\n}\n\nmodifyMap(colors)\nfmt.Println(colors) // purple is added\n```\n\n### **5. Maps with Structs**\n\n```go\ntype Person struct {\n    Name string\n    Age  int\n}\n\npeople := map[string]Person{\n    \"user1\": {\"Alice\", 30},\n    \"user2\": {\"Bob\", 25},\n}\nfmt.Println(people)\n```\n\n### **6. Thread-Safe Maps (`sync.Map`)**\n\n```go\nimport \"sync\"\n\nvar safeMap sync.Map\nsafeMap.Store(\"red\", \"#ff0000\")\n\nval, ok := safeMap.Load(\"red\")\nif ok {\n    fmt.Println(val)\n}\n```\n\n---\n\n## **Arrays \u0026 Slices in Go**\n\n### **1. Array vs. Slice**\n\n| Feature             | Array             | Slice                          |\n| ------------------- | ----------------- | ------------------------------ |\n| **Size**            | Fixed length      | Dynamic size (can grow/shrink) |\n| **Mutability**      | Cannot resize     | Can resize using `append`      |\n| **Underlying Data** | Contiguous memory | References an array            |\n\n#### Example:\n\n```go\n// Array (Fixed size)\narr := [3]int{1, 2, 3}\n\n// Slice (Can grow)\nslice := []int{1, 2, 3}\nslice = append(slice, 4) // Returns a new slice with 4 added\n```\n\n---\n\n## **Pointers in Go**\n\n### **1. Declaring and Using Pointers**\n\n```go\nx := 58\nptr := \u0026x // ptr now stores the memory address of x\n\nfmt.Println(ptr)  // Prints the memory address\nfmt.Println(*ptr) // Dereferencing: Prints the value stored at the memory address (58)\n```\n\n### **2. Passing by Value vs Passing by Reference**\n\n```go\ntype person struct {\n    firstName string\n    lastName  string\n}\n\nfunc (p *person) updateName(newFName string) {\n    p.firstName = newFName\n}\n```\n\n---\n\n## **Functions in Go**\n\n### **1. Function Signatures**\n\n```go\nfunc functionName(parameter1 type, parameter2 type) returnType {\n    // Function body\n}\n```\n\nExample:\n\n```go\nfunc add(a int, b int) int {\n    return a + b\n}\n```\n\n### **2. Function with Pointer Receiver**\n\n```go\nfunc (p *person) updateName(newFName string) {\n    p.firstName = newFName\n}\n```\n\n---\n\n## **Common Go Data Types**\n\n### **1. Structs**\n\n```go\ntype contactInfo struct {\n    email   string\n    zipcode int\n}\n\ntype person struct {\n    firstName string\n    lastName  string\n    contact   contactInfo\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fullaskunder3%2Fgo-lang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fullaskunder3%2Fgo-lang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fullaskunder3%2Fgo-lang/lists"}