36 lines
No EOL
860 B
Markdown
36 lines
No EOL
860 B
Markdown
Initial
|
|
|
|
Install go compiler.
|
|
|
|
Sample program
|
|
```go
|
|
|
|
// file name : main.go
|
|
package main
|
|
import ("fmt")
|
|
|
|
func main() {
|
|
fmt.Println("Hello World!")
|
|
}
|
|
```
|
|
then run `go run main.go` or `go build -o main main.go && ./main`.
|
|
for partilcular platform
|
|
`GOOS=linux GOARCH=arm64 go build -o myapp-linux-arm64 . `
|
|
and equivalent of `npm i`
|
|
to install all packages
|
|
`go get .` or `go mod tidy`
|
|
to install specific package
|
|
`go get github.com/spf13/cobra@latest`
|
|
to remove go package
|
|
simply remove import statements and then run `go mod tidy`
|
|
|
|
for initiating like `npm init -y`
|
|
use `go mod init <module_name>`
|
|
|
|
|
|
Program explanation
|
|
1. in go every program is part of package that's why here is ths package main
|
|
2. fmt package is imported
|
|
3. main function
|
|
4. fmt.Println is used to print text
|
|
5. Comments are like in C ie `//` for single line and `/* */` for multi line |