- Hands-On Full Stack Development with Go
- Mina Andrawos
- 359字
- 2021-07-02 12:33:29
Setting up Go's workspace
For you to write Go code on your computer, you need to set up a Go workspace. A Go workspace is a folder where you will write your Go code. Setting up a Go workspace is relatively simple. Here is what you will need to do:
- First, make sure that you have Go installed. As we mentioned earlier, you can download and install Go by going to https://golang.org/dl/.
- After installing Go, create a new folder in your computer for Go's workspace. Mine is called GoProjects.
- Inside your Go workspace folder, you will have to create three main folders: src, pkg, and bin. It is very important to create folders with these exact names inside your Go workspace folder. Here is why these three folders are important:
- The src folder will host all of your code files. Whenever you decide to start a new program, you will simply go to the src folder and create a new folder with your new program name.
- The pkg folder typically hosts the compiled package files of your code.
- The bin folder typically hosts the binary files that are produced by your Go programs.
- You will need to set two environmental variables:
- The first environmental variable is called GoRoot, and will include the path to your Go install. GoRoot should typically be taken care of by the Go installer. However, if it's missing, or you would like to move your Go installation to a different place, then you need to set GoRoot.
- The second environmental variable is called GoPath. GoPath includes the path to your Go workspace folder. By default, if not set, GoPath is assumed to either to be at $HOME/go on Unix systems or %USERPROFILE%\go on Windows. There is an entire GitHub page which covers setting up GoPath in different operating systems, which can be found at https://github.com/golang/go/wiki/SettingGOPATH.
Once your Go environment is set up, you can use the Go tool, which is installed alongside the Go language so that you can compile and run your Go programs.
We'll take a look at some of the basic building blocks of the Go language in the next section.
推薦閱讀
- 自然語言處理實戰(zhàn):預訓練模型應用及其產(chǎn)品化
- Kubernetes實戰(zhàn)
- HBase從入門到實戰(zhàn)
- 數(shù)據(jù)結(jié)構簡明教程(第2版)微課版
- R的極客理想:工具篇
- C程序設計案例教程
- 數(shù)據(jù)結(jié)構案例教程(C/C++版)
- Node.js Design Patterns
- C++寶典
- 計算機應用基礎項目化教程
- Unity 2017 Game AI Programming(Third Edition)
- Python+Office:輕松實現(xiàn)Python辦公自動化
- 大學計算機基礎實訓教程
- Clojure High Performance Programming(Second Edition)
- 零基礎學SQL(升級版)