{"id":15866470,"url":"https://github.com/squidmin/go-labs","last_synced_at":"2025-04-01T21:21:01.591Z","repository":{"id":161632190,"uuid":"589766862","full_name":"squidmin/go-labs","owner":"squidmin","description":"A comprehensive repository for learning and experimenting with Go","archived":false,"fork":false,"pushed_at":"2024-06-16T21:30:06.000Z","size":3257,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-07T13:54:25.665Z","etag":null,"topics":["go","golang","learning","learning-exercises"],"latest_commit_sha":null,"homepage":"","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/squidmin.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":"2023-01-16T22:11:36.000Z","updated_at":"2024-06-16T21:30:09.000Z","dependencies_parsed_at":"2023-12-01T01:31:24.948Z","dependency_job_id":"af7e8c2f-f895-4cbf-9d8d-3b727eff7554","html_url":"https://github.com/squidmin/go-labs","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/squidmin%2Fgo-labs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squidmin%2Fgo-labs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squidmin%2Fgo-labs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/squidmin%2Fgo-labs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/squidmin","download_url":"https://codeload.github.com/squidmin/go-labs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246710005,"owners_count":20821315,"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":["go","golang","learning","learning-exercises"],"created_at":"2024-10-05T23:20:56.230Z","updated_at":"2025-04-01T21:21:01.570Z","avatar_url":"https://github.com/squidmin.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-labs\n\nA comprehensive repository for learning and experimenting with Go, set up and tested using:\n\n- **IDE**: GoLand 2022.3.2\n- **Go Version**: go1.19.5\n\n## Getting Started\n\nBelow are the initial setup steps to prepare your environment and start experimenting with Go modules.\nEnsure your terminal is pointed to the root folder of this project before proceeding.\n\n### Module initialization\n\n#### Creating a Module Directory\n\n\u003cdetails\u003e\n\u003csummary\u003eClick to expand\u003c/summary\u003e\n\n#### Use Case\n\nCreating a module directory is your first step in organizing your Go project.\nModules in Go serve as containers for packages, and having a dedicated directory for each module helps in managing dependencies, versioning, and package distribution efficiently.\nThis step is crucial when you're starting a new project or adding a new module to an existing project to ensure that your codebase remains organized and scalable.\n\n```shell\nmkdir module_name\n```\n\n\u003c/details\u003e\n\n#### Initializing a Go Module\n\n\u003cdetails\u003e\n\u003csummary\u003eClick to expand\u003c/summary\u003e\n\n#### Use Case\n\nInitializing a Go module with `go mod init` sets the foundation for managing your project's dependencies.\nThis command creates a `go.mod` file, marking the current directory as the root of a module.\nIt enables Go to track and manage the versions of external packages your project depends on, facilitating reproducible builds and simplifying dependency management.\nThis step is essential at the beginning of project development or when adding new dependencies.\n\n```shell\ngo mod init module_path\n```\n\nThe `go mod init` command creates a `go.mod` file to track your code's dependencies.\nInitially, this file will only include your module's name and the Go version your code supports.\nAs you add dependencies, `go.mod` will list the versions your code depends on, ensuring reproducible builds and direct control over module versions.\n\n\u003e**Note**: For published modules, the module path must be a downloadable path by Go tools, typically your code's repository URL, e.g., `github.com/squidmin/go-labs/example`.\n\n\u003c/details\u003e\n\n#### Cleaning Up Dependencies\n\n\u003cdetails\u003e\n\u003csummary\u003eClick to expand\u003c/summary\u003e\n\n### Use Case\n\nRunning `go mod tidy` ensures that the `go.mod` and `go.sum` files accurately reflect the dependencies actually used in your project.\nThis command adds missing dependencies, removes unused ones, and updates `go.mod` and `go.sum` to match the source code.\nIt's particularly useful after adding or removing imports in your code or when preparing to commit your code to version control, ensuring a clean, up-to-date record of dependencies.\n\n```shell\ngo mod tidy\n```\n\nUse the `go mod tidy` command to clean up your `go.mod` and `go.sum` files.\nThis step adds any missing module dependencies and removes unused ones, ensuring that your module dependencies are accurate and up-to-date.\n\nMore info: [`go mod tidy`](https://go.dev/ref/mod#go-mod-tidy)\n\n\u003c/details\u003e\n\n---\n\n## Building and Running Your Code\n\n### Building and Installing an Executable\n\n\u003cdetails\u003e\n\u003csummary\u003eClick to expand\u003c/summary\u003e\n\n#### Use Case\n\nCompiling your Go code into an executable with `go build` and then installing it with `go install` makes it easy to distribute and run your application.\nThis process is crucial for creating standalone applications that can be executed without the Go runtime.\nIt's particularly relevant when you're ready to deploy your application or share it with users who may not have Go installed.\n\n#### Steps\n\n1. **Navigate to Your Project Directory**: Ensure you're in the directory containing your `main` package.\n\n   ```shell\n   cd ./directory_name\n   ```\n   \n2. **Build Your Code (Optional)**: This step compiles your code and generates an executable in the current directory.\n   It's useful for testing the build process or when you need an executable in a specific location.\n\n   ```shell\n   go build\n   ```\n\n   \u003e **Note**: You can also build code from outside the module by specifying a path:\n   \u003e\n   \u003e ```shell\n   \u003e go build ./directory_name\n   \u003e ```\n   \n3. **Install Your Application**:\n\n   ```shell\n   cd ./directory_name # Navigate to the module\n   go install\n   ```\n\n4. **Adding the Executable to Your `PATH` (Optional)**:\n\n   After building or installing your Go application, you might want to make the executable globally accessible from the command line, regardless of your current working directory.\n   This is particularly useful for tools or applications you plan to use frequently across various projects or directories.\n\n   To add the executable to your `PATH`, you can use the `export` command in Unix-like operating systems, including Linux and macOS.\n   This command temporarily modifies the `PATH` environment variable for the current terminal session.\n   To make this change permanent, you'll need to add the export command to your shell's startup file, such as `.bashrc`, `.bash_profile`, or `.zshrc`, depending on your shell and operating system.\n\n   The following command uses `go list -f '{{.Target}}'` to dynamically find the installation path of your Go executable and adds it to your `PATH`:\n\n   ```shell\n   export PATH=$PATH:$(go list -f '{{.Target}}')\n   ```\n   \n   \u003e **Note**: This step assumes you've used `go install` to compile and install your executable.\n   \u003e `go install` places binaries in the `$GOPATH/bin` directory (or `$GOBIN` if set), which is the path resolved by `go list -f '{{.Target}}'`.\n   \u003e If you're managing your Go environment correctly, `$GOPATH/bin` should already be in your `PATH`.\n   \u003e However, if you find it's not, or if you've compiled your executable with `go build` and placed it in a custom directory, this command can be adapted to include that directory in your `PATH`.\n\n   \u003e **Important**: Remember, changes made with the `export` command to the `PATH` are temporary and only affect the current terminal session.\n   \u003e For a permanent solution, you need to add the command to your shell's startup file as mentioned earlier.\n\n\u003c/details\u003e\n\n### Running an Executable\n\n\u003cdetails\u003e\n\u003csummary\u003eClick to expand\u003c/summary\u003e\n\nTo run an installed executable with options:\n\n```shell\n./executable_name -o --option -k=val --key=value\n```\n\nOr if the executable has been added to your `PATH`:\n\n```shell\nexecutable_name -o --option -k=val --key=value\n```\n\n\u003c/details\u003e\n\n### Build or Run a Specific File\n\n\u003cdetails\u003e\n\u003csummary\u003eClick to expand\u003c/summary\u003e\n\nUse the `-tags` flag with `go build` or `go run`:\n\n```shell\ngo build -tags filename .\n```\n\ne.g.,\n\n```shell\ngo build -tags arrays ./05_arrays_and_slices/01_declaration_and_initialization/arrays\n```\n\n```shell\ngo run -tags filename .\n```\n\ne.g.,\n\n```shell\ngo run -tags arrays ./05_arrays_and_slices/01_declaration_and_initialization/arrays\n```\n\n\u003c/details\u003e\n\n### Running a Script Without Building\n\n\u003cdetails\u003e\n\u003csummary\u003eClick to expand\u003c/summary\u003e\n\n#### Use Case\n\nThe ability to run a Go script using `go run` without explicitly compiling it first is invaluable during development.\nIt allows for rapid testing and iteration, letting developers focus on writing and refining code without worrying about the build process.\nThis approach is ideal for development environments where quick feedback on code changes is crucial.\n\n```shell\ngo run script_name.go\n```\n\nUnderstanding the context and purpose behind these actions can significantly enhance your learning experience and effectiveness in Go development.\n\n\u003c/details\u003e\n\n---\n\n## Additional Resources\n\nFor a more in-depth introduction to Go, consider the official [\"Getting Started\" tutorial](https://go.dev/doc/tutorial/getting-started).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquidmin%2Fgo-labs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsquidmin%2Fgo-labs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsquidmin%2Fgo-labs/lists"}