You can install and run the project with these steps.
Go into your go work directory
cd GO-WORK-DIRECTORY/
and git clone the project
git clone https://github.com/huzairuje/go-echo-example.git
install the dependencies from go mod with
go mod install
add existing config.yml with cp from example :
cp config.yml.example config.yml
and then fill the necessary data, example
ServerPort: ":3000"
DatabaseHost: "localhost"
DatabasePort: "5432"
DatabaseUser: "postgres"
DatabasePassword: "postgres"
DatabaseName: "products"
firstly you need this package to run the migration https://github.com/golang-migrate/migrate to install the package you need to run this
$ brew install golang-migrate
Using scoop
$ scoop install migrate
$ curl -L https://packagecloud.io/golang-migrate/migrate/gpgkey | apt-key add -
$ echo "deb https://packagecloud.io/golang-migrate/migrate/ubuntu/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/migrate.list
$ apt-get update
$ apt-get install -y migrate
$ migrate -help
and use this command to do the migration
$ migrate -database postgresql://postgres:postgres@localhost:5432/products -path product/migration/ up
$ go get -u -d github.com/golang-migrate/migrate/cmd/migrate
$ cd $GOPATH/src/github.com/golang-migrate/migrate/cmd/migrate
$ git checkout $TAG # e.g. v4.1.0
$ # Go 1.15 and below
$ go build -tags 'postgres' -ldflags="-X main.Version=$(git describe --tags)" -o $GOPATH/bin/migrate $GOPATH/src/github.com/golang-migrate/migrate/cmd/migrate
$ # Go 1.16+
$ go install -tags 'postgres' -o $GOPATH/bin/migrate github.com/golang-migrate/migrate/v4/cmd/migrate@$TAG
go to this project root folder
cd ROOT-FOLDER-PROJECT/
and then
go run main.go
- Open API (swagger), you can access it on (http://localhost:3000/swagger/index.html)
- DB Migration using golang-migrate (https://github.com/golang-migrate/migrate)
- validation by struct
- using config with viper (https://github.com/spf13/viper)
- using echo HTTP framework (https://echo.labstack.com/)
- using grom (https://gorm.io/) as ORM
This package is open-sourced software licensed under the MIT license.