{"id":23086135,"url":"https://github.com/umarquez/golang-examples","last_synced_at":"2025-04-03T15:32:37.845Z","repository":{"id":148138430,"uuid":"65860177","full_name":"umarquez/Golang-examples","owner":"umarquez","description":"Golang code examples ","archived":false,"fork":false,"pushed_at":"2016-12-29T00:49:47.000Z","size":68,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-09T04:25:38.175Z","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/umarquez.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":"2016-08-16T23:22:40.000Z","updated_at":"2016-08-16T23:39:00.000Z","dependencies_parsed_at":"2023-05-19T07:18:59.552Z","dependency_job_id":null,"html_url":"https://github.com/umarquez/Golang-examples","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umarquez%2FGolang-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umarquez%2FGolang-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umarquez%2FGolang-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umarquez%2FGolang-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/umarquez","download_url":"https://codeload.github.com/umarquez/Golang-examples/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247027771,"owners_count":20871586,"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-16T18:16:45.842Z","updated_at":"2025-04-03T15:32:37.826Z","avatar_url":"https://github.com/umarquez.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go (_Golang_) code examples and notes.\n\n## blank_identifier\n### http_get\nMakes a **http** get request using the _blank identifier_ to ignore exceptions.\n\n### pollution\nSimple code that declares a variable that is never used, its asign the var to a _blank identifier_ to avoid `declared and unused` error.\n\n## by_ref_and_by_val\nA program that calls two functions,   one recive arguments **_by val_** and the other recive arguments **_by ref_**. It uses **pointers** to pass **_by ref_**.\n\n## Concurrency \u0026 Parallelism\n### atomicity\nProvides the capability to access a var only one process at a time. This code uses an atomic function to modify a variable and avoiding simultaneous access to it.\n\n### Channels\nShows how to share values through channels between two processes.\n\n\u003e The optional \u003c- operator specifies the channel direction, send or receive. If no direction is given, the channel is bidirectional. A channel may be constrained only to send or only to receive by conversion or assignment.\n```\nchan T          // can be used to send and receive values of type T\nchan\u003c- float64  // can only be used to send float64s\n\u003c-chan int      // can only be used to receive ints\n```\n**Source:** *https://golang.org/ref/spec#Channel_types*\n\n#### channels_and_waitgroup\nHow to use channels and WaitGroups in the same program.\n\n#### pipeline_pattern\n\u003e\n**What is a pipeline?**\n\u003e\nThere's no formal definition of a pipeline in Go; it's just one of many kinds of concurrent programs. Informally, a pipeline is a series of stages connected by channels, where each stage is a group of goroutines running the same function. In each stage, the goroutin.\n\u003e\n- receive values from upstream via inbound channels.\n- perform some function on that data, usually producing new values.\n- send values downstream via outbound channels.\n\u003e\nEach stage has any number of inbound and outbound channels, except the - first and last stages, which have only outbound or inbound channels, respectively. The first stage is sometimes called the source or producer; the last stage, the sink or consumer.\n\u003e\n**Source:** *https://blog.golang.org/pipelines*\n\nAn example of pipeline comunication pattern.\n\n#### pure_channels\nHow to manage multiple threads using the same channel with no other library.\n\n### concurrency\n\u003e Is the composition of independently executing processes (_dealing with a lot of things at once_).\n\nAn example code that implements concurrency using the  **go** keyword for creating _goroutine_ and a `WaitGroup` just for keeping the main thread alive until all other threads ends.\n\n### parallelism\n\u003e Is the simultaneously execution of (possibly related) computations (_doing a lot of things at once_).\n\nAn example code that shows how to implements parallelism using `runtime.GOMAXPROCS()` function inside the _init()_ function.\n\n### rc_mutex\nExample of a rance condition code and mutex for preventing unwanted behavio r.\n\n## constants\nProgram that declares and use some constants, it also use the _`iota`_ value.\n\u003e **iota:** a small amount of something\n\n## control_flow\nCode example that implements the uses for the `for` statement.\n- C/Java `for` style\n- Like `while` statement sustitution\n- Like `do` for infinite loops\n- With the `continue` keyword\n\n## Convertion and Assertion\n**Convertion**: Transform a value of certain type to another (casting or parsing in other languajes).\n**Assertion**: Treats a value of one type as if it were another, without converting it.\n\n### assertion_ex\nCode that shows how to use assertion (only works with interfaces).\n\n### convertion_ex\nCode example that shows how to convert a typed value to another using ***strconv*** library.\n\n## data_structures\nBasic data structuresand how to deal with.\n\n### array_and_slice\nExample with an _**Array**_ and a _**Slice**_ and the differences between these types.\n\n### slice_example\nHow to declare a slice and append elements to it.\n\n### maps\nExample code of maps declaration and manipulation.\n\n### struct\nThis code shows how to create a custom type based on **struct** type, how to use it in a var declaration and how to change its field's values.\n\n## fmt_verbs\nUses some format verbs to display a number.\n- Deciamal\n- Binary\n- Char\n- Octal\n- Hex (_3 formats_)\n\n## for_and_format_examples\nUses a for to generate a numerical secuences and display every generated number in three formats.\n- Decimal `%d`\n- Binary `%b`\n- Hex `%#X`\n- Char `%q`\n\n## for_and_module_op\nCode example that implements a for to generate a counter and a conditional (_if_) to clasificate generated numbers in **odd** and **even** using a module operation `x % 2`.\n\n## functions\nWorking with functions.\n\n### anon_function\nA simple code that shows how to declare and execute a anonymous function.\n\n### callback\nExample of a function call that needs a callback function to do certain things.\n\n### returns\nExample of three types of function's _returns_\n- **helloWorld**: A simple (and _traditionsl_) single value return\n- **greet**: A named var return\n- **names**: A multiple values return\n\n### defer\nCode that uses the word `defer` to make a function call be executed at the end of the current function.\n\n### variadic_args\nExample of a function call that passes variadic arguments using  the variadic technique.\n\n### variadic_params\nExample of a function that can recive a unlimited number of arguments and stores in a collection, it's called variadic function.\n\n## inner_functions\nProgram with inner functions and functions that returns functions as result. Something like _functions inception_.\n\n## Interfaces\nSome interfaces examples.\n\n### empty_interface\nHow to use empty interface to create a function that could manage any type of data/object.\n\n### simple_interface\nCode that shows how to declare an interface and work with it.\n\n### sort_exercise\nRequirements:\n\n```\nUse https://godoc.org/sort to sortthe following:\n\n(1)\ntype people []string\nstudyGroup := people{\"Zeno\", \"John\", \"Al\", \"Jenny\"}\n\n(2)\ns := []string{\"Zeno\", \"John\", \"Al\", \"Jenny\"}\n\n(3)\nn := []int{7, 4, 8, 2, 9, 19, 12, 32, 3}\n```\n\n## JSON\nWorking with JSON\n\n### json_decoder\nHow to convert a streammed JSON text to an object.\n\n**Note:** Use this for reading JSON through the web.\n\n### json_encoder\nHow to convert an object to a JSON string to write it on a stream.\n\n**Note:** Use this for sending Objects JSON through the web.\n\n### json_to_struct_unmarshal\nHaving a string with JSON content, this code will assign its values to an instance of a type that has the same **exported** fields using `json.unmarshal()` method.\n\n### struct_to_json_marshal\nHaving a custom class object(_struct_), this code will convert it to a **JSON** formated string using `json.Marshal()` method.\n\n## memmory_address\nA wey to get var's memmory address, good introduction to pointers.\n\n## nested_loops\nExample of nested loops, prints values of both vars.\n\n## packages_and_imports\nHow to use the `ìmport` statement for multiple libs.\n\n## pointers\nHow to declares and use pointers in _**GO**_.\n\n## runes\nrunes generator example `rune = char`, _**rune**_ type is an alias of int32.\n\n## switch_case_default\nExample code using switch statements.\n\n## switch_on_types\nAn example of how to implement a type based switch function.\n\n## types\nA program that defines twoo custom types using **struct**, one inside the other; both of them has a method with the same name that the code calls for each type, it also contains a function that receive a pointer to a custom type.\n\n## variables\nExample about the both ways to declare a variable.\n\n## vars_scope\nHow does scopes works on _**Go**_:\n\n### main\nMain code, only imports a lib and calls a functions\n\n### outter\nHas two files in the same package, one has the var declaration and the other has the function that prints text messages.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumarquez%2Fgolang-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fumarquez%2Fgolang-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumarquez%2Fgolang-examples/lists"}