Coder Social home page Coder Social logo

hellojebus / go-mux-jwt-boilerplate Goto Github PK

View Code? Open in Web Editor NEW
46.0 4.0 7.0 3.38 MB

Golang REST API using MUX, GORM, and JWT for authentication

License: MIT License

Go 100.00%
golang golang-application jwt gorm-orm mux gorilla-mux rest-api mysql boilerplate crud

go-mux-jwt-boilerplate's Introduction

GoLang Mux, Gorm, JWT REST API Boilerplate

The purpose of this web app is for me to learn Go REST API Development using Mux (router), Gorm (ORM), JSON Web Tokens (JWT), and Golang development in general. The application is optimized for Heroku deployment using the Go Build Kit and Godep for dependency management.

This is for educational purposes only and probably unsuitable for production

What's included

Basic CRUD routes for user management

  • Show Users GET /users
  • Show User GET /users/{userId}
  • Create User POST /users
  • User Login POST /users/login
  • Delete User DELETE /users/{userId}
  • Update User PUT /users/{userId} * Note only the user can update their own name

Several routes are protected and require JWT tokens, which can be generated using the login route. You will need to create a user by sending a post request to the createUser route.

Configuration

Make sure to copy .env.sample to .env and update all fields (DB fields are important!)

Please note that this is using the MySQL driver, if you prefer to use another driver, update db.go accordingly

Gorm is setup to automigrate the Users table, so it should be plug and play.

Installation

Make sure to have all required external deps. Look at Godeps config file to view them all.

Preferred Method, Live Reloading (optional):

Install Gin go get github.com/codegangsta/gin

Then run: gin run main.go

Otherwise:

To run using Go: go run *.go

To view application in browser: localhost:3000 (gin run) or locahost:YOUR_PORT_ENV (go run)

Todos

[] Detach userHandlers DB functions from http for testing purposes
[] Add User Role to illustrate how relationships work with Gorm

go-mux-jwt-boilerplate's People

Contributors

hellojebus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  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.