https://github.com/pythoncoderunicorn/golang
a repo for my Go Language learning
https://github.com/pythoncoderunicorn/golang
Last synced: 6 months ago
JSON representation
a repo for my Go Language learning
- Host: GitHub
- URL: https://github.com/pythoncoderunicorn/golang
- Owner: PythonCoderUnicorn
- Created: 2024-02-21T22:20:17.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-21T19:30:17.000Z (over 1 year ago)
- Last Synced: 2025-01-17T20:23:57.710Z (11 months ago)
- Language: Go
- Size: 1.22 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GoLang
a repo for my Go Language learning
---
### Documentation
https://go.dev/doc/tutorial/getting-started
### Install Go
```
sudo apt install golang-go
```
### start a project
1. `mkdir folder; cd folder`
2. `go mod init folder/file` this gives a pseudo link for local Go `.mod` to reference. Name it the same as the folder your code will be in with main or hello.go
3. `touch hello.go`
4. `go run . `
5. for an executable file `go build hello.go` which compiles and makes `hello` file => `./hello`
### import external package
check out packages https://pkg.go.dev/ but all of the Go packages are from GitHub.
to import a package:
1. `go get -u github.com/` , example: `go get -u github.com/ttacon/chalk`
2. inside the main file import the github link inside the `import( )`, example: `import( "fmt"; "github.com/ttacon/chalk" )`
3. run `go mod tidy` for package maintenance
4. run program `go run .`
#### errors
Go lang does not like when you have packages imported or variables etc declared and not used, comment the things not used to avoid any errors or warnings.
----
Starter template
```Go
package main
import "fmt"
var pl = fmt.Println // declare a shortcut for fmt.Println
func main() {
pl("hello Go")
}
```