Move to the project’s folder cd $GOPATH//demouser/myAppĬreate package archives for non-executable packages in myApp and store them in $GOPATH/pkgĬreate binary for executable packages ( package main) in myApp and store them in $GOPATH/binĪssuming that $GOPATH/bin is added to $PATH (for Unix systems) the project can be executed from anywhere on the system with the following command myApp (This also assumes that myApp has a single executable package main and not multiple commands) Go workspace - Folder structure and responsibilities Initialize Git repository for the project - cd myApp git init Creating the unique namespace would help to share the package in the futureĬreate a folder for the project myApp - mkdir myApp The earlier step where we create a namespace using / can be skipped and the project folder can be directly created inside $GOPATH/src/. Move to the folder /demouser - cd /demouser ![]() ![]() Suppose the new project we create is going to be hosted on under account demouser. Inside src folder there are multiple folders each corresponding to domains hosting Go code (eg. Suppose for a username demo this is /home/demo/go) Identify the Go workspace from GOPATH environment variable go env GOPATH (The default value of GOPATH is $HOME/go. Initialize Git repository cd myApp git init Initialize package.json to track dependencies - npm init -y Go programmers typically keep all their Go code in a single workspace The greatest shift for me as a developer coming from Node.js was the following statement from Go Docs It took me a while to get a hang of the notion of workspace in Go and the resulting differences in initializing a project in Go compared to Node.js.
0 Comments
Leave a Reply. |