All Projects → hojabri → backend

hojabri / backend

Licence: GPL-3.0 license
A REST web-service sample project written in Golang using go-fiber, GORM and PostgreSQL

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to backend

go-pangu
rest api web server based on go(High availability, high security, high performance)
Stars: ✭ 45 (+66.67%)
Mutual labels:  gorm
go-graphql-api-boilerplate
A Boilerplate of GraphQL API built in Go + graphql-go + gorm
Stars: ✭ 75 (+177.78%)
Mutual labels:  gorm
iris-gorm-demo
iris+gorm+mysql的restful api项目起手式
Stars: ✭ 92 (+240.74%)
Mutual labels:  gorm
simple-mpesa
A simple example of how MPESA works. Works with all 3 types of customers i.e. Agents, Merchants and Subscribers. Allows you to configure a tariff and apply it to transactions. The project follows DDD principles.
Stars: ✭ 31 (+14.81%)
Mutual labels:  gorm
simple-wallet
This is a simple wallet REST api that is capable of acount deposits and withdrawals, checking for account balance and providing a ministatement. It follows domain driven design practices. The project uses the DDD architecture approach.
Stars: ✭ 32 (+18.52%)
Mutual labels:  gorm
ginadmin
基于Gin开发的后台管理系统,集成了、数据库操作、日志管理、权限分配管理、多模板页面、自动分页器、数据库迁移和填充、Docker集成部署等功能、静态资源打包
Stars: ✭ 149 (+451.85%)
Mutual labels:  gorm
BEW-2.5-Strongly-Typed-Languages
💪 Learn and implement the design patterns and best practices that make Go a top choice at high-velocity startups like Lyft, Heroku, Docker, Medium, and more!
Stars: ✭ 14 (-48.15%)
Mutual labels:  gorm
sqlext
extend gorm and gocql
Stars: ✭ 16 (-40.74%)
Mutual labels:  gorm
prometheus
Collect DB Status or user-defined metrics with Prometheus
Stars: ✭ 94 (+248.15%)
Mutual labels:  gorm
gorm-neo4j
GORM for Neo4j
Stars: ✭ 16 (-40.74%)
Mutual labels:  gorm
go-orm-code-helper
🔥🔥🔥go-orm-code-helper is a goland plugin, it aims to make gorm code getting more simple
Stars: ✭ 22 (-18.52%)
Mutual labels:  gorm
gorm-paginator
gorm pagination extension
Stars: ✭ 154 (+470.37%)
Mutual labels:  gorm
mysql
GORM mysql driver
Stars: ✭ 126 (+366.67%)
Mutual labels:  gorm
gorm-mongodb
GORM for MongoDB
Stars: ✭ 58 (+114.81%)
Mutual labels:  gorm
pink-lady
a template project of gin app.
Stars: ✭ 44 (+62.96%)
Mutual labels:  gorm
opentracing-gorm
OpenTracing instrumentation for GORM.
Stars: ✭ 46 (+70.37%)
Mutual labels:  gorm
go api boilerplate
🐶Go (Golang)🚀REST / GraphQL API + Postgres boilerplate
Stars: ✭ 127 (+370.37%)
Mutual labels:  gorm
laya-template
服务基本框架,template
Stars: ✭ 13 (-51.85%)
Mutual labels:  gorm
gothic
🦇 Gothic is a user registration and authentication SWT/JWT microservice. It supports REST, gRPC, and gRPC Web API, reCAPTCHA & a variety of DBs with Gorm.
Stars: ✭ 65 (+140.74%)
Mutual labels:  gorm
go-webapp-sample
golang, echo, gorm
Stars: ✭ 194 (+618.52%)
Mutual labels:  gorm

backend

A REST web-service sample project written in Golang using go-fiber, GORM and PostgreSQL

How to run

  • Make sure you have Go installed (download).
  • Make sure you have installed docker and docker-compose tools (for running PostgreSQL database) (instruction).
  • Pull and setup project DB with docker-compose tools and docker-compose.yml file
> make db-up

Output:

Starting postgresql ... done

  • Run the project:
> make run

Output:

 ┌───────────────────────────────────────────────────┐ 
 │                    Fiber v2.7.1                   │ 
 │               http://127.0.0.1:3000               │ 
 │       (bound on host 0.0.0.0 and port 3000)       │ 
 │                                                   │ 
 │ Handlers ............ 24  Processes ........... 1 │ 
 │ Prefork ....... Disabled  PID .............. 5699 │ 
 └───────────────────────────────────────────────────┘ 

List of endpoints:

Note: replace :user_id with user's ID

show <hello> message:                       GET         http://127.0.0.1:3000

Get all users:                              GET         http://127.0.0.1:3000/user
Get single user information:                GET         http://127.0.0.1:3000/user/:user_id
Create new user:                            POST        http://127.0.0.1:3000/user
Update user:                                PUT         http://127.0.0.1:3000/user/:user_id
Delete user:                                DELETE      http://127.0.0.1:3000/user/:user_id

Get all companies:                          GET         http://127.0.0.1:3000/company
Get single company information:             GET         http://127.0.0.1:3000/company/:company_id
Create new company:                         POST        http://127.0.0.1:3000/company
Update company:                             PUT         http://127.0.0.1:3000/company/:company_id
Delete company:                             DELETE      http://127.0.0.1:3000/company/:company_id

Get all company categories:                 GET         http://127.0.0.1:3000/companyCategory
Get single company category information:    GET         http://127.0.0.1:3000/companyCategory/:companyCategory_id
Create new company category:                POST        http://127.0.0.1:3000/companyCategory
Update company category:                    PUT         http://127.0.0.1:3000/companyCategory/:companyCategory_id
Delete company category:                    DELETE      http://127.0.0.1:3000/companyCategory/:companyCategory_id

Call endpoints with curl command:

curl:

command line tool and library for transferring data with URLs

Samples:

Get all users:

curl --location --request GET 'http://127.0.0.1:3000/user'

Output:

{
  "code": 200,
  "body": [
    {
      "ID": 2,
      "CreatedAt": "0001-01-01T01:55:52+01:55",
      "UpdatedAt": "2021-04-16T15:03:45.89629+03:00",
      "DeletedAt": null,
      "first_name": "Omid",
      "last_name": "Hojabri",
      "email": "[email protected]",
      "phone": "+90123456790"
    },
    {
      "ID": 4,
      "CreatedAt": "0001-01-01T01:55:52+01:55",
      "UpdatedAt": "2021-04-16T15:17:35.699638+03:00",
      "DeletedAt": null,
      "first_name": "Bill",
      "last_name": "Gates",
      "email": "[email protected]",
      "company_id": 2,
      "company": {
        "ID": 2,
        "CreatedAt": "2021-04-16T15:17:05.418797+03:00",
        "UpdatedAt": "2021-04-16T15:17:05.418797+03:00",
        "DeletedAt": null,
        "name": "Microsoft",
        "category_id": 2,
        "category": null,
        "website": "http://microsoft.com"
      }
    }
  ],
  "title": "GetAllUsers",
  "message": "All users"
}

Create user:

curl --location --request POST 'http://127.0.0.1:3000/user' \
--header 'Content-Type: application/json' \
--data-raw '{
    "first_name" : "Bill",
    "last_name" : "Gates",
    "email" : "[email protected]",
    "company_id" : 2
}'

Output:

{
    "code": 200,
    "body": {
        "ID": 4,
        "CreatedAt": "2021-04-16T15:16:08.114701+03:00",
        "UpdatedAt": "2021-04-16T15:16:08.114701+03:00",
        "DeletedAt": null,
        "first_name": "Bill",
        "last_name": "Gates",
        "email": "[email protected]",
        "company_id": 2,
        "company": {
          "ID": 2,
          "CreatedAt": "2021-04-16T15:17:05.418797+03:00",
          "UpdatedAt": "2021-04-16T15:17:05.418797+03:00",
          "DeletedAt": null,
          "name": "Microsoft",
          "category_id": 2,
          "category": null,
          "website": "http://microsoft.com"
        }      
    },
    "title": "OK",
    "message": "new user added successfully"
}

Data models

User:

type User struct {
	gorm.Model
	FirstName string  `json:"first_name"`
	LastName  string  `json:"last_name"`
	Email     string  `json:"email,omitempty" gorm:"uniqueIndex"`
	Phone     string  `json:"phone,omitempty"`
	CompanyID *uint    `json:"company_id,omitempty"`
	Company   *Company `json:"company,omitempty"`
}

Company:

type Company struct {
	gorm.Model
	Name         string          `json:"name" gorm:"uniqueIndex"`
	Description  string          `json:"description,omitempty"`
	CategoryID   *uint            `json:"category_id,omitempty"`
	Category     *CompanyCategory `json:"category"`
	Website      string          `json:"website,omitempty"`
}

Company Category:

type CompanyCategory struct {
	gorm.Model
	Name string `json:"name" gorm:"uniqueIndex"`
}

GORM

The fantastic ORM library for Golang aims to be developer friendly.

  • More information (https://gorm.io/)
  • Full-Featured ORM
  • Associations (has one, has many, belongs to, many to many, polymorphism, single-table inheritance)
  • Hooks (before/after create/save/update/delete/find)
  • Eager loading with Preload, Joins
  • Transactions, Nested Transactions, Save Point, RollbackTo to Saved Point
  • Context, Prepared Statement Mode, DryRun Mode
  • Batch Insert, FindInBatches, Find/Create with Map, CRUD with SQL Expr and Context Valuer
  • SQL Builder, Upsert, Locking, Optimizer/Index/Comment Hints, Named Argument, SubQuery
  • Composite Primary Key, Indexes, Constraints
  • Auto Migrations
  • Logger
  • Extendable, flexible plugin API: Database Resolver (multiple databases, read/write splitting) / Prometheus…
  • Every feature comes with tests
  • Developer Friendly

Go-Fiber

Fiber is a Go web framework built on top of Fasthttp, the fastest HTTP engine for Go. It's designed to ease things up for fast development with zero memory allocation and performance in mind. More information (https://gofiber.io/)

PostgerSQL

PostgreSQL is a powerful, open source object-relational database system with over 30 years of active development that has earned it a strong reputation for reliability, feature robustness, and performance. More information (https://www.postgresql.org/)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].