Giter VIP home page Giter VIP logo

cservice-api's Introduction

GitHub Actions status Codacy Badge Codacy Badge

Channel Services API

Warning

THIS IS A WORK IN PROGRESS. The API is not stable and may change at any time. DO NOT USE IN PRODUCTION.

Requirements

  • golang >= 1.8 (for compiling)
  • PostgreSQL >= 11.0 (for running)
  • Redis

Configuration

Copy config.yml.example to config.yml and edit it to your liking.

Generate JWT RSA key pair for access token and refresh token

openssl genrsa -out jwt.key 4096
openssl rsa -in jwt.key -pubout -out jwt.pub
openssl genrsa -out refresh_jwt.key 4096
openssl rsa -in refresh_jwt.key -pubout -out refresh_jwt.pub

Configure cservice-api with JWT RSA key

Add the following to config.yml:

jwt:
  signing_method: "RS256"
  signing_key: /path/to/jwt.key
  public_key: /path/to/jwt.pub
  refresh_signing_key: /path/to/refresh_jwt.key
  refresh_public_key: /path/to/refresh_jwt.pub

The JWKS can be downloaded from <site>/.well-known/jwks.json.

Building and running

Build

make build

Running the service:

bin/cservice-api -config </path/to/config.yml>

Development

Generate database repositories

This project uses sqlc to generate Go code from SQL queries.

The database schema is defined in db/migrations/*.sql. Do NOT modify existing migration files if a schema change is necessary. Instead, run the following command:

migrate create -ext sql -dir db/migrations <migration_name>

This will create two new migration files in db/migrations with the current timestamp for migrating up and down. Edit the files to add the necessary SQL statements.

To generate the Go code from the migrations in db/migrations and the SQL queries defined in db/query/*.sql, run:

make generate-sqlc

After this, you may have to update the service.go file in models so that it matches the interface defined in models/querier.go.

After changing the SQL queries or schema it may be necessary to update the database mocks for the unit tests by running:

make generate-mocks

Unit tests

To run the unit tests, run:

make test

Integration tests

The integration tests use dockertest. To run the integration tests, run:

make integration-test

Live reloading while developing

To run the service with live reloading, run:

make watch

cservice-api's People

Contributors

ratler avatar dependabot[bot] 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.