Golang Skeleton With Fully Managed Versions For Kick Start GoLang Project Development

Golang Skeleton With Fully Managed Versions For Kick Start GoLang Project Development

License: MIT

There is no doubt that Golang’s good documentation and intelligent features could help developers in learning language efficiently and outcome might be promising still, What Golang is missing is the common structure to quick start any API Structure. While working on several Golang Projects, Golang Developers at Mindinventory confront the requirement of having an effective and well Integrated GoLang API Development Structure and as a result of which they came up with one.

  • gorm : It is the ORM library in Go which provides user friendly functions to interact with database. It supports features like ORM, Associations, Hooks, Preloading, Transaction, Auto Migration, Logger etc.
  • gin : Gin is a web framework for Go language. Here gin is used for increase performance and productivity.
  • godotenv : Basically used for load env variables from .env file.
  • mysql : It provides the mysql driver for connecting Go with MySQL.

Check out our blog to know how to use Golang API Skeleton with Fully Managed Versions to kick start Golang project. (https://www.mindinventory.com/blog/golang-project-structure/)

STRUCTURE

What it is?

It is a fully managed repository, where one can find all required components in a single package including versioning for REST APIs and you do not need to set up each time they start with any crucial work in Golang.

Prerequisite

One need to install the latest version of Go i.e 1.12 (Released in Feb 2019) from https://golang.org/dl/ and setup GOROOT and GOPATH.

Components

1. ApiHelpers

Basically contains the helper functions used in returning api responses, HTTP status codes, default messages etc.

2. Controllers

Contains handler functions for particular route to be called when an api is called.

3. Helpers

Contains helper functions used in all apis

4. Middlewares

Middleware to be used for the project

5. Models

Database tables to be used as models struct

6. Resources

Resources contains all structures other than models which can be used as responses

7. Routers

Resources define the routes for your project

8. Seeder

It is optional, but if you want to insert lots of dummy records in your database, then you can use seeder.

9. Services

All the core apis for your projects should be within services.

10. Storage

It is generally for storage purpose.

11. Templates

Contains the HTML templates used in your project

12. .env

Contains environment variables.

Steps to Follow

. For running the server you have to run following command in the terminal. go run main.go It will start your server at the port you have mentioned in the .env file.

. To run the server in a port other than the default, run following command. go run main.go <specific port>

. To create a build for your project and uploaded in the server, one need to run following command. go build

API with versioning

For using version 1 api

127.0.0.1:8099/api/v1/user-list

For using version 2 api

127.0.0.1:8099/api/v2/user-list

LICENSE!

Go Project Structure is MIT-licensed

Let us know!

We’d be really happy if you sent us links to your projects where you use our component. Just send an email to [email protected] And do let us know if you have any questions or suggestion regarding our work.

Owner
MindInventory
MindInventory works with Enterprises, Startups, and Agencies since 2011 providing web, mobile app development, enterprise mobility solutions & DevOps services.
MindInventory
Similar Resources

Go-Guardian is a golang library that provides a simple, clean, and idiomatic way to create powerful modern API and web authentication.

❗ Cache package has been moved to libcache repository Go-Guardian Go-Guardian is a golang library that provides a simple, clean, and idiomatic way to

Dec 23, 2022

A standalone, specification-compliant, OAuth2 server written in Golang.

A standalone, specification-compliant,  OAuth2 server written in Golang.

Go OAuth2 Server This service implements OAuth 2.0 specification. Excerpts from the specification are included in this README file to describe differe

Dec 28, 2022

goRBAC provides a lightweight role-based access control (RBAC) implementation in Golang.

goRBAC goRBAC provides a lightweight role-based access control implementation in Golang. For the purposes of this package: * an identity has one or mo

Dec 29, 2022

This is an implementation of JWT in golang!

jwt This is a minimal implementation of JWT designed with simplicity in mind. What is JWT? Jwt is a signed JSON object used for claims based authentic

Oct 25, 2022

This package provides json web token (jwt) middleware for goLang http servers

jwt-auth jwt auth middleware in goLang. If you're interested in using sessions, checkout my sessions library! README Contents: Quickstart Performance

Dec 5, 2022

Golang implementation of JSON Web Tokens (JWT)

jwt-go A go (or 'golang' for search engine friendliness) implementation of JSON Web Tokens NEW VERSION COMING: There have been a lot of improvements s

Jan 6, 2023

Golang OAuth2 server library

OSIN Golang OAuth2 server library OSIN is an OAuth2 server library for the Go language, as specified at http://tools.ietf.org/html/rfc6749 and http://

Dec 23, 2022

Platform-Agnostic Security Tokens implementation in GO (Golang)

Golang implementation of PASETO: Platform-Agnostic Security Tokens This is a 100% compatible pure Go (Golang) implementation of PASETO tokens. PASETO

Jan 2, 2023

Simple JWT Golang

sjwt Simple JSON Web Token - Uses HMAC SHA-256 Example // Set Claims claims := New() claims.Set("username", "billymister") claims.Set("account_id", 86

Dec 8, 2022
Comments
  • 404 on all routes

    404 on all routes

    I set up the project and installed all dependencies. Further I setup a new database and added a new sample user to the table. I am able to run

    go run main.go

    The server start on localhost:8099 if I visit the server on my browser I get a 404. If I try to call this route in postman: localhost:8099/api/v1/user-list

    I get this error

    {
        "message": "Invalid request",
        "status": 1
    }
    
  • when I run `go run main.go`, only get 'cannot find package

    when I run `go run main.go`, only get 'cannot find package "GoProject/routers"'

    [#94#root@ubuntu-dev /go/src/github.com/Mindinventory/Golang-Project-Structure]$go version
    go version go1.12.6 linux/amd64
    [#95#root@ubuntu-dev /go/src/github.com/Mindinventory/Golang-Project-Structure]$
    [#95#root@ubuntu-dev /go/src/github.com/Mindinventory/Golang-Project-Structure]$go run main.go 
    main.go:4:2: cannot find package "GoProject/routers" in any of:
            /usr/local/go/src/GoProject/routers (from $GOROOT)
            /go/src/GoProject/routers (from $GOPATH)
    [#96#root@ubuntu-dev /go/src/github.com/Mindinventory/Golang-Project-Structure]$
    
  • [Question] With this design how are you returning statuscode from service?

    [Question] With this design how are you returning statuscode from service?

    Hey Friends!

    I have recently started a project using this structure and I was wondering how you recommend returning status codes from failures within a service?

    Thanks

Goal: Develop a Go start auth starter without Gin framework

Goal: Develop a Go start auth starter without Gin framework and learn along the

Feb 1, 2022
Backend Development Rest Api Project for book management system. Used Features like redis, jwt token,validation and authorization.

Golang-restapi-project Simple Rest Api Project with Authentication, Autherization,Validation and Connection with redis File Structure ├── cache │ ├──

May 25, 2022
Gets Firebase auth tokens (for development purposes only)Gets Firebase auth tokens

Firebase Token Gets Firebase auth tokens (for development purposes only) Getting started Create Firebase project Setup Firebase authentication Setup G

Nov 17, 2021
A cli to asist developers in development and testing locally against OpenId Connect.

oidc-cli oidc-cli assists developers in automating authorization flow for local development and testing purpose. Installation Download the program fro

Feb 7, 2022
Barbar Service is a project for demo of simple distribute authentication Service.
Barbar Service is a project for demo of simple distribute authentication Service.

Barbar Service Barbar Service is a project for demo of simple distribute authentication Service. Project Structure Basicaly we reffer to Domain Driven

Aug 29, 2022
A simple user identify template with jwt token and gin, toy project

Simple Docs Register url : /api/auth/register param type value name string username password string password mailbox string mailbox response: { "sta

Dec 31, 2021
Go-auth - An authorization project using mongoDB, JWT and Go
Go-auth - An authorization project using mongoDB, JWT and Go

Ssibrahimbas Go-Auth An authorization project using mongoDB, JWT and Go. API Typ

Mar 10, 2022
Pet-project
Pet-project

Simplest-auth-with-go It's a learning project. To run it, navigate to a folder in your console. Then type to start the server: go run main.go Then go

Mar 13, 2022
Oauth2-golang - Oauth2 Golang Mysql

Oauth2-golang - Oauth2 Golang Mysql

Sep 16, 2022
An authorization library that supports access control models like ACL, RBAC, ABAC in Golang
An authorization library that supports access control models like ACL, RBAC, ABAC in Golang

Casbin News: still worry about how to write the correct Casbin policy? Casbin online editor is coming to help! Try it at: https://casbin.org/editor/ C

Jan 2, 2023