Web service CRUD using Golang with gorilla-MUX for create REST api, MySQL as database, Viper as environment variable and sqlmock assert for Testing.
Prerequisites
Getting Started
- Firstly, we need to get MUX, MySQL, Viper, sqlmock, assert library dependencies and install it
go get github.com/gorilla/mux
go get github.com/go-sql-driver/mysql
go get github.com/spf13/viper
go get github.com/DATA-DOG/go-sqlmock
go get github.com/stretchr/testify/assert
-
Import dump.sql to your MySQL and configure your credential in folder resource
-
Open cmd in your project directory and type
go test -v
, you should get a response similar to the following: -
To run application,open cmd in your project directory and type
go run main.go
Sample Payload