kuroyamii / golang-webapi

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

All Contributors

Overview

Prerequisites

  • Have installed MySQL
  • Have installed Go
  • Have installed Database Migrations https://github.com/golang-migrate/migrate
  • Have learned the basics of Go

Get Started

  • First of all, you must make an empty database in your MySQL
  • Create a .env file like below (change if it's needed):
    SERVER_ADDRESS=127.0.0.1:8080
    DB_ADDRESS=localhost:3309
    DB_USERNAME=root
    DB_PASSWORD=
    DB_NAME=inugami_db
    WHITELISTED_URLS=http://localhost:3000
  • Run database migration. Example:

    To run a migration
migrate -source file://directory-to-migration-folder -database "database-connection-query" up <number>

//example
migrate -source file://./db/migration -database "mysql://root:@tcp(localhost:3307)/inugami_db" up

To rollback a migration

migrate -source file://directory-to-migration-folder -database "database-connection-query" down <number>

//example
migrate -source file://./db/migration -database "mysql://root:@tcp(localhost:3307)/inugami_db" down 1

To create a new migration file

migrate create -ext sql -dir migrations <migration-name>

//example
migrate create -ext sql -dir migrations create_tables
  • Run main.go in cmd/main

Contributors ✨


Gede Gery Sastrawan

πŸ’» πŸ“– πŸš‡ πŸ‘€

This project follows the all-contributors specification. Contributions of any kind welcome!

About


Languages

Language:Go 99.7%Language:Dockerfile 0.2%Language:Shell 0.1%