Git Product home page Git Product logo

go-playground's Introduction

go-playground

Go Report Card

go-playground is a collection of Go's programs and notes for learning Go, which I mostly use for reference.

Topic

  • Basic: scope, callback, function expression, defer, slice, pointer
  • Concurrency
  • Networking: http, tcp, mux, session, cookie
  • Error Handling

Note

How to setup GOPATH

There are 2 essential environment variables to setup before running any Go program:

  • GOPATH
  • GOROOT

GOPATH is the path to our workspace. It is required and has no default. I'm setting it up at $HOME/go because it works for me.

GOROOT is that path to where Go standard library is located on our local filesystem. Is set automatically setup when we install Go.

Additionally, GOBIN is the path to where our Go binaries are installed from running go install.

All of the environment variables configurations can be set in .bashrc or .zshrc. For example:

export GOPATH=$HOME/go
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin

Execute the command go env to see all the environment variable.

How to structure project

Exported/unexported, aka visible/not visible

In go we don't say public or or private, we say exported or unexported. Depend on capialization:

  • capitalize: exported, visible outside the package
  • lowercase: unxported, not visible outside the package

go commands

Assume that our folder directory looks like this:

package
├── main
│  └── main.go
├── utils
│  └── utilOne.go
│  └── utilTwo.go

If we run these commands in our executable, main:

  • go run main.go will run the file the file
  • go build will make an executable file and put that inside
  • go clean will clean that executable file
  • go install will make an executable file inside the workspace bin folder and archive file in pkg

If we run these commands in our packages, utils:

  • they cannot be run because they are non-main packages
  • they cannot be built because there are no executable

go fmt

go fmt ./...: Go fmt all the files in this directory and anything below it.

go-playground's People

Contributors

hoanhan101 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.