cservice-api

module
v0.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2023 License: MIT

README

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

Directories

Path Synopsis
cmd
Package controllers provides the controllers for the API
Package controllers provides the controllers for the API
admin
Package admin defines the admin controllers.
Package admin defines the admin controllers.
db
Package db defines the database types and functions.
Package db defines the database types and functions.
types/flags
Package flags contains all the bitmask based flags used in the database.
Package flags contains all the bitmask based flags used in the database.
internal
auth/password
Package password provides password hashing and validation.
Package password provides password hashing and validation.
checks
Package checks contains functions intended for Is, Has, etc.
Package checks contains functions intended for Is, Has, etc.
config
Package config provides configuration management
Package config provides configuration management
docs
Package docs Code generated by swaggo/swag.
Package docs Code generated by swaggo/swag.
globals
Package globals contains global variables and functions
Package globals contains global variables and functions
helper
Package helper contains helper functions
Package helper contains helper functions
jwks
Package jwks provides functions for generating a JWKS
Package jwks provides functions for generating a JWKS
testutils
Package testutils provides shared unit test functions
Package testutils provides shared unit test functions
Package models contains the database models
Package models contains the database models
Package routes defines the routes for the echo server.
Package routes defines the routes for the echo server.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL