/go-crud

A Go tutorial to create a blog using MySQL http://www.golangprograms.com/advance-programs/example-of-golang-crud-using-mysql-from-scratch.html

Primary LanguageGoGNU General Public License v3.0GPL-3.0

Go CRUD


Database set up

This project is using MySql as the persistent layer for storing employee info. The following user, database and table need to exist before running the backend service:

  • Create user gocrud
    CREATE USER gocrud@'localhost' IDENTIFIED BY 'password';
    • Grant privilage:
      GRANT ALL PRIVILEGES ON *. * TO gocrud@'localhost';
  • Create database gocrud_db
    CREATE DATABASE gocrud_db;
  • Create employee table
    CREATE TABLE `employee` (`id` int(6) unsigned NOT NULL AUTO_INCREMENT,`name` varchar(30) NOT NULL,`city` varchar(30) NOT NULL,PRIMARY KEY (`id`)) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;

Create Environmental Variables

export DB_USER="<database username>"
export DB_NAME="<database name>"
export DB_PASSWORD="<database password>"

Start service

go build main.go
go run main.go