Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/edloidas/gohacks

Demonstration of various Go syntax capabilities.
https://github.com/edloidas/gohacks

Last synced: 25 days ago
JSON representation

Demonstration of various Go syntax capabilities.

Awesome Lists containing this project

README

        

# Go Hacks

A project to demonstrate the capabilities of the Go syntax, from basics to more complex things.

#### Sections
* [variables](./sections/variables/variables.go)
* [functions](./sections/functions/functions.go)
* [flow](./sections/flow/flow.go)
* [moretypes](./sections/moretypes/moretypes.go)

### Commands

The list of most commonly used commands are the following:

1. `go mod init`

Initializes a new module in your current directory, creating a `go.mod` file.

__Usage:__ `go mod init `

2. `go mod tidy`

Adds missing and removes unused modules.
Ensures that the `go.mod` file matches the source code in the module.

__Usage:__ `go mod tidy`

3. `go build`

Compiles your Go program.
By default, it does not produce an output file. Instead, it saves the compiled binary in a temporary location.
To save the compiled binary, you can specify a name: `go build -o `.

__Usage:__ `go build` or `go build -o myapp`

4. `go run`

Compiles and runs your Go program.
Useful for quick testing and development.

Usage: `go run `

Example: `go run .` or `go run main.go`

5. `go test`

Runs tests in the current package.
Go identifies any file ending in `_test.go` as a test.

__Usage:__ `go test`

_To run tests in all subdirectories, use_ `go test ./...`.

6. `go get`

Adds a dependency to your module and installs it.

__Usage:__ `go get `

__Example:__ `go get github.com/gin-gonic/gin`

7. `go install`

Compiles and installs a Go program (typically used for installing Go tools).
The binary is saved to the bin directory in your `GOPATH`.

__Usage:__ `go install `

8. `go fmt`

Formats your Go source code according to the Go standards.

__Usage:__ `go fmt `

_To run format in the current directory and its subdirectories, use_ `go fmt ./..`.

9. `go vet`

Analyzes your source code and reports potential errors like unreachable code, unnecessary assignments, etc.

__Usage:__ `go vet `

_To run format for all files in the current directory and its subdirectories, use_ `go vet ./..`.

10. `go env`

Prints Go environment information.
Useful for debugging and understanding your Go setup.

__Usage:__ `go env`