Giter Site home page Giter Site logo

gin-rest-api's Introduction

gin-rest-api-sample

Golang REST API sample with MariaDB integration using Gin and GORM. (This project IS NOT a starter kit, it is just an example project.)

This project is a sample project that contains following features:

Project Setup

$ dep ensure
$ go get github.com/jinzhu/gorm
$ go get github.com/codegangsta/gin

GORM should be installed via go get since installation via dep is imperfect (it does not download dialects directory).

codegangsta/gin is an optional package to install if you want to make usage of live reloading feature of server (just like nodemon in Node.js environment).

MariaDB Configuration

This project uses MariaDB to store data. Install MariaDB and create a sample database and a user account.

Install MariaDB

Create Database / Account

CREATE DATABASE sample;
GRANT ALL PRIVILEGES ON sample.* to sample@'%' IDENTIFIED BY 'samplepass';
GRANT ALL PRIVILEGES ON sample.* to sample@'localhost' IDENTIFIED BY 'samplepass';

Configure Environment Variables

Open .env file and edit the values if you need to. This project uses godotenv to read and use .env file.

Database config string is formatted in go-sql-driver format.

Start Project

$ go run main.go

To explicitly compile the code before you run the server:

$ go build main.go
$ ./main

To use live-reloading in development environment,

$ ./scripts/start-dev

gin-rest-api's People

Contributors

tqmvt avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.