Javad Rajabzadeh
Posted on June 7, 2021
Project Creator
create project and management with go modules
Create your project
- go to GOPATH in local
cd $GOPATH
- If there is no src,bin,pkg folder, create them
mkdir -p {src,bin,pkg}
- go to src folder
cd src
- create your github repository
- create folder
mkdir -p github.com/username
- change username to your username
- go to folder github.com/username via
cd github.com/username
- clone project from github
git clone https://github.com/username/project.git
- go to project folder
cd project
- create the first Go module in the project
go mod init github.com/username/project
- You can now add modules to your project using go get ...
Project structure type
- Flat Structures - Basic
├── file1.go
├── file2.go
├── file3.go
├── main.go
├── LICENSE
└── README.md
- Standard Structures - Good
├── _example // this is dir for your examples
│ ├── sample1
│ ├── sample1.go
│ └── sample1_test.go
│ └── sample2
│ ├── sample2.go
│ └── sample2_test.go
├── dir1
│ ├── file1.go
│ └── file1_test.go
├── dir2
│ ├── file2.go
│ └── file2_test.go
├── dir3
│ ├── file3.go
│ ├── file3_test.go
│ ├── file4.go
│ ├── file4_test.go
│ └── file5.go
├── dir4
│ ├── samplefolder
│ ├── file6.go
│ └── file6_test.go
├── LICENSE
├── go.mod
├── go.sum
├── main.go or project.go // project.go for pkg project
└── README.md
- MVC Pattern Structures - Excellent
├── _example // this is dir for your examples
│ ├── sample1
│ ├── sample1.go
│ └── sample1_test.go
│ └── sample2
│ ├── sample2.go
│ └── sample2_test.go
├── module
│ ├── file1.go
│ ├── file1_test.go
│ └── samplefolder
│ ├── file6.go
│ └── file6_test.go
├── view
│ ├── file2.go
│ └── file2_test.go
├── controller
│ ├── file3.go
│ ├── file3_test.go
│ ├── file4.go
│ ├── file4_test.go
│ └── file5.go
├── LICENSE
├── go.mod
├── go.sum
├── main.go
└── README.md
Project Contributor
- Create a fork of the target project in your repository
- Go to your $GOPATH via
cd $GOPATH
- Create the bin,pkg,src folders if you don't already have them using
mkdir -p {src,bin,pkg}
. - Create the target module's original path using
mkdir -p src/github.com/target
- Change the username of the target module to the creator of the project or the organization
- Go to target path
cd src/github.com/target
- Clone the forked project in the current directory by cloning
git clone https://github.com/your_username/project.git
- Go to project folder
cd project
- By using go get ./..., obtaining the necessary packages
- You should add git remote upstream
https://github.com/target/project.git
to update your fork. - Working on your project and sending your PR
- Every time before you start coding, you should:
-
git fetch upstream
git merge upstream/main
-
git merge upstream/branch1
-
git merge upstream/branch2
- Push any changes to your forked branch via
git push origin main
orgit push origin branch1
-
💖 💪 🙅 🚩
Javad Rajabzadeh
Posted on June 7, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.