[Golang] Ecosystem

Tags
Golang
Engineering
Created
Nov 7, 2023 04:43 AM
Edited
Nov 6, 2023
Description
go run/build/mod/get…

Golang file

There must be a package
// main.go
package main
You can import outside lib
import (
	"fmt"
)

Run

go run main.go
But if you are using other files and they are all under the same package. Main function is an entry point.
go run .

Build

Build programs into binaries.
go build file.go
./file

Initiate go module as a package manager

go mod init <project_name>

Install package from Github

go get 

Formatting

Run go fmt.
It briefly does the followings:
  1. Indentation: Go uses tab 😊
  1. Line length: no limit
go <command> [arguments]

Use go help <command>

bug         start a bug report
build       compile packages and dependencies
clean       remove object files and cached files
doc         show documentation for package or symbol
env         print Go environment information
fix         update packages to use new APIs
fmt         gofmt (reformat) package sources
generate    generate Go files by processing source
get         add dependencies to current module and install them
install     compile and install packages and dependencies
list        list packages or modules
mod         module maintenance
run         compile and run Go program
test        test packages
tool        run specified go tool
version     print Go version
vet         report likely mistakes in packages

Reference