Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rakibrahman/go
loading Go(golang) to my brain
https://github.com/rakibrahman/go
Last synced: 1 day ago
JSON representation
loading Go(golang) to my brain
- Host: GitHub
- URL: https://github.com/rakibrahman/go
- Owner: RakibRahman
- Created: 2025-01-18T05:44:39.000Z (24 days ago)
- Default Branch: main
- Last Pushed: 2025-02-07T10:18:54.000Z (4 days ago)
- Last Synced: 2025-02-07T11:21:39.373Z (4 days ago)
- Language: Go
- Size: 1.24 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Go
# Commands
### GO Module
- Command : `go mod init hello_world`
- A Go project is called a module. A module is not just source code. It is also an exact specification of the dependencies of the code within the module. Every
module has a `go.mod` file in its root directory. Running go mod init creates this file.
- The `go.mod` file declares the name of the module, the minimum supported version of Go for the module, and any other modules that your module depends on### GO Build
- Command : `go build` / `go build -o hello`
- Creates an executable file (hello) in the current directory.### GO FMT
- Command: `go fmt ./...`
- Automatically fixes the whitespace in your code to match the standard format.
- `./...` tells a Go tool to apply the command to all the files in the current directory and all subdirectories.
### GO VET
- Command : ` go vet ./...`
- To catches several common programming errors.
- Scan for possible bugs in valid code.# Variables
Variables are used to store values. It can be declared using the var keyword, or the shorthand := syntax.
```
var name string
name = "John Doe"age := 30
```
# Variadic Functions
Variadic functions accept a variable number of arguments. Use an ellipsis (...) before the type to indicate that a function takes a variable number of parameters:
```
func sum(numbers ...int) int {
total := 0
for _, number := range numbers {
total += number
}
return total
}func main() {
fmt.Println(sum(1, 2, 3, 4, 5)) // Outputs: 15
}```
# Defer Statement
The `defer` statement delays the execution of a function until the surrounding function returns. It’s often used for clean-up tasks:
```
func main() {
defer fmt.Println("Goodbye!")
fmt.Println("Hello")
}``