Skip to content

sunny7899/go-basic

Repository files navigation

Golang for Beginners

This repository is designed to help beginners get started with Golang. Below is a quick guide to installing, setting up, and using Go effectively.

Prerequisites

Ensure that you have Go installed. To check the installed version of Go, run:

go version

Setting Up the Environment

Configure your Go environment:

go env -w GO111MODULE=off

Run your Go application:

  • To run a Go application from the current directory:
go run .
  • To run a specific Go file:
go run filename.go

For help with Go commands:

go help

Package Management

Go code is grouped into packages, and packages are grouped into modules. To explore packages, visit pkg.go.dev.

Initialize your Go module using:

go env -w GO111MODULE=on    ##  need to set, so as to init or install modules..

go mod init [module-path]
go mod init hello

Adding Packages

To add external packages to your Go module:

go get -v rsc.io/quote

Managing Dependencies

The go mod tidy command will ensure that your dependencies are in order:

  • It adds missing dependencies.
  • It removes unused ones.

Run it with:

go mod tidy

Building Go Projects

Compile and build your Go project:

go build
  • To build a specific Go file:
go build filename.go

Listing Go Modules

To list the modules and their dependencies:

go list

Additional Resources

About

No description or website provided.

Topics

Resources

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published