GithubHelp home page GithubHelp logo

messenger-api's Introduction

Messenger API

Screenshots

Send image success

Success send image

Send image failed, invalid message

Send image failed, invalid message

Get messages by conversation id success 1

Get messages by conversation id success 1

Get messages by conversation id success 2

Get messages by conversation id success 2

Get messages by conversation id failed (forbidden)

Get messages by conversation id failed (forbidden)

Get messages by conversation id failed (not found)

Get messages by conversation id failed (not found)

Get conversations by user success (empty)

Get conversations by user success (empty)

Get conversations by user success (filled)

Get conversations by user success (filled)

Get conversation by ID success

Get conversation by ID success

Get conversation by ID failed (forbidden)

Get conversation by ID failed (forbidden)

Get conversation by ID failed (not found)

Get conversation by ID failed (not found)

How to init go.mod?

This project is initiated by using command:

go mod init gitlab.com/raihanlh/messenger-api

How to change between golang version?

Use gvm to change between golang version Can be installed from gvm github page

How to download packages?

go mod tidy

How to migrate database?

Install UUID extension on psql

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

Run migration

go run cmd/migration/migration.go

How to run seeder?

To run all seeder

go run cmd/seeder/seeder.go

To run specific seeder

go run cmd/seeder/seeder.go UserSeed
go run cmd/seeder/seeder.go UserSeed TestSeed

Generate test coverage

go test -v -coverprofile cover.out ./YOUR_CODE_FOLDER/...
go tool cover -html cover.out -o cover.html
open cover.html

Testing

Go has a built-in testing package for both unit and benchmark tests. While unit test is necessary, benchmark test is more of a nice-to-have and is only useful for logic-heavy codes (i.e. usecases, helper functions, etc). Learn more about golang's unit test practices here.

Generate mock

When testing, it's recommended to use an auto-generated mocks so you don't have to manually mock a function everytime you create new one. We're generally using mockgen but feel free to use other tool you're most comfortable using.

  • Install mockgen on your computer (not on this project)
go install github.com/golang/mock/[email protected]
  • Generate mock
mockgen -source={GOPATH}/example-service/example-folder/example_file.go -destination={GOPATH}/example-service/testing/mocks/example-folder/example_file.go

Example:

mockgen -source=internal/domain/user/user.go -destination=testing/mocks/user/user.go

Documentation

API Documentation can be accessed through {SERVER_URL}/swagger/index.html route.

  • Add API Operation on new handler function
  • Install swaggo on your machine (not on this project)
go install github.com/swaggo/swag/cmd/swag@latest
  • Generate docs
swag init -g cmd/server/main.go --output api/docs

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.