Skip to content

open-collaboration/server

Repository files navigation

Go Report Card

Development environment setup

This section assumes your terminal's current working directory is the project's directory.

Required tools:

  1. Install golangci-lint
  2. Install pre-commit
pip install pre-commit && pre-commit install
  1. Install docker
  2. Install docker-compose

Tip: Install the Go Linter plugin for GoLand/VSCode

Running the project

To start the database:

docker-compose up -d

To stop the database:

docker-compose down

To run the server:

go run .

Contribution guidelines

Modifying the database's schema

To modify the database's schema, you should create a migration in the migrations package. Do not delete or modify existing migrations in migrations.go, only add more migrations to it with an increasing id.

Creating routes

Don't create gin routes with "pure" gin route handlers (functions with the signature func(*gin.Context)), instead use the createRouteHandler method, which will be able to provide your handler with a database connection and automatic error handling.

Globals

Don't use globals. Ever. They make it harder to test the code. Instead, use depencency injection.

In a nutshell, dependency injection basically means receiving all of a method's dependencies (e.g. database connections like *gorm.DB) as parameters. This way the caller of the function has to provide it with its dependencies and testing the function later on is easier, we just have to pass it mocked or real dependencies as parameters, no need to fiddle around with singletons and globals and whatnot.

DTOs

Use DTOs (Data Transfer Objects) to send and receive data on routes. DTOs are basically just plain structs with fields and field tags for validation (take a look at NewUserDto).

About

Source code for the backend of the OpenCollab website

Resources

Stars

Watchers

Forks

Contributors