Code Monkey home page Code Monkey logo

go-restful-api's Introduction

Golang RESTful Apis

Project struct build in monolithic architecture but open for microservices architecture. The main functions:

  • Open Api for authentication (login/register user)
  • Open Api for User (Get/update user info)

Technical and libraries

  • Golang 1.19
  • Go-Gin framework
  • Gorm & Postgresql database
  • Docker, docker-compose and integrated Github CI
  • Some popular libraries (viper config, go-migrate, jwt-go, govalidator, logrus, samber-lodash, ...).

How to use

Clone this repository to your local machine.

  1. Ensure that you have Go environment
  2. Postgresql database running (update the information config file app.yml)

For creating docker Postgresql, from root project run script:

docker-compose -f docker/docker-compose.local.yml up -d

For init tables, from root project run migration script:

ENV=local make migrate-up

Run from source code

Go to root project and run:

cd services/question/ && go run main.go

Run by docker

From root project run the script:

docker build -t sample-restful-api:lastest --build-arg APPCONFIG=app.yml -f ./services/question/Dockerfile .
docker run -d -p 3000:3000 sample-restful-api:lastest

Sample request

Login/register api request:

curl --location 'http://localhost:3000/v1/auth/login' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "[email protected]",
    "password": "12345678"
}'

Response:

{
    "data": {
        "id": "2d31eff9-b9c1-4422-b1b0-003acd2f58cb",
        "name": "",
        "email": "[email protected]",
        "avatar": "",
        "access_token": {
            "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiMmQzMWVmZjktYjljMS00NDIyLWIxYjAtMDAzYWNkMmY1OGNiIiwiZW1haWwiOiJuZ3V5ZW5jb25ncGh1b25nQGdtYWlsLmNvbSIsImV4cCI6MTY5MzQ2MTAyMSwiaXNzIjoiU21hcnRLaWQtRWR1Y2F0aW9uIn0.YRDUxV5eapw-WqMuce9Vbp7EnOy_5N2faycV02n1Mac",
            "expired_at": "2023-08-31T12:50:21.978723+07:00"
        }
    },
    "error": null,
    "message": "Success",
    "success": true
}

Questions / Feedbacks / Bugs

Feel free to reach out to me if you have any questions or feedback on how my code can be improved. My email: [email protected]

TODO

  • REST APIs
  • Docker build
  • Unit test
  • Swagger documentation

go-restful-api's People

Contributors

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