So unlike modern PHP, Go handles the way we interact with types in our applications in a different way, through the use of structs. In fact it tailors itself to be more primitive, like it’s grandfather C.
Go does however have similar concepts implemented, which to an outsiders point of…
For all you beginner, intermediate or expert PHP developers, here’s an article which should provide you with a little guidance on how to get started writing your applications in Golang and how it compares to a similar workflow with PHP.
But first, let’s grab the things we need to start…
Have you ever wondered how you can interact with a database in Go using the Model pattern? Well here’s a quick example of how you can get started with GORM, an ORM for Go.
In this example we connect to an SQLite database called database.db and migrate a new table for users. We then add a new user row with the name “Craig” and fetch all users. We finish by printing out the JSON representation of this list of users.
GORM makes interacting with databases in Go dead simple and is just one of the many tools you can use to encapsulate your data layer in the Model architecture.
Recently I’ve been implementing a small side project in Go with Gin. I know how easy it is to setup tests with Go, but I was very surprised not many people had covered examples of how to test the JSON responses for your APIs. With Gin specifically.