Go was designed at Google in 2007 to improve programming productivity in an era of multicore, networked machines and large code bases.The designers wanted to address criticism of other languages in use at Google, but keep their useful characteristics.
During past couple of days I have been learning Golang and I noticed some of the challenges I faced was the lack of constraints or standards, choosing external packages and much moreπ. I would like to share some findings that have worked for me and also walk you through the steps by building a simple todo app.
Prerequisites
- A Golang compiler installed on your Machine
- An IDE or text editor
- Basic understanding of Go
- Basic understanding of HTML and CSS
- Basic understanding of SQL (Only required to create Database π)
Project Layout
We would start by creating a module for our project so as to better track our packages in a file called go.mod
which would makes it easier for distribution or deployment. it's more like package.json
or composer.json
.
go mod init github.com/iamhabbeboy/todoapp
Next, we need to create the following folders.
You don't have to follow this structure.π
todoapp
βββmodels
| βββ Todo.go
βββ controllers
| βββ TodoController.go
βββ database
| βββ connect.go
βββ views
| βββ index.html
| βββ create.html
|ββ main.go
|ββ .env
Packages
The following packages would be used to better develop our project.
- Gorm: Go ORM that support mysql and other databases.
go get -u github.com/jinzhu/gorm
- Mux: It's handles our routes and requests.
go get -u github.com/gorilla/mux
- Godotenv: Would be used to access our
.env
variables
go get github.com/joho/godotenv
- MySQL driver: Allow connection to MySQL DB
go get github.com/go-sql-driver/mysql
I wouldn't want you to be bored with this post so I decided to split it into two. The other part would be posted in the comment section soon.
Please do leave a comment in case you have any contributions, I would really appreciate that.π
Thanks for reading.β€οΈ
Top comments (2)
Wow! What a great tut...........
Thanks for reading, here is the continuation Part II π