DEV Community

Azeez Abiodun Solomon
Azeez Abiodun Solomon

Posted on

Build Web App with Go for Beginners Part I

Cover Image

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode
  • Mux: It's handles our routes and requests.
go get -u github.com/gorilla/mux

Enter fullscreen mode Exit fullscreen mode
  • Godotenv: Would be used to access our .env variables
go get github.com/joho/godotenv

Enter fullscreen mode Exit fullscreen mode
  • MySQL driver: Allow connection to MySQL DB
 go get github.com/go-sql-driver/mysql

Enter fullscreen mode Exit fullscreen mode

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)

Collapse
 
morshud profile image
Gbadamosi Moshood

Wow! What a great tut...........

Collapse
 
iamhabbeboy profile image
Azeez Abiodun Solomon

Thanks for reading, here is the continuation Part II 😊