loading...

Build Web App with Go for Beginners Part I

iamhabbeboy profile image Azeez Abiodun Solomon ・2 min read

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

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.❀️

Posted on May 29 by:

iamhabbeboy profile

Azeez Abiodun Solomon

@iamhabbeboy

A software developer that derive joy in creating stuffs and helping others

Discussion

markdown guide
 

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

 

Thanks for reading, here is the continuation Part II 😊