Skip to content
Snippets Groups Projects

Akamu App-Server

Backend RESTful API of the Akamu App.

The API is documented in the file appapi.yaml.
There is a staging server hosted at https://dev.akamu.de/api/v2/ as documented in https://dev.akamu.de/api/docs/ which is deployed from the development branch. A stable version of the app server can be found at https://akamu.de/api/v2/ as documented in https://akamu.de/api/docs/ which is deployed from the master branch.

Setup the Environment

Independent from your environment, you need to have the dependencies installed. Run go get ./... to receive the go packages.

Setup your MariaDB instance. Create a new database with the schema found in https://gitlab.akamu.de/akamu/data-schemas/.
First, install akamuschema.sql, containing the tables and procedures, then continue with gamesettings.sql and deploydata.sql.

Development

For development, you can additionally install sample data. Sample data can be found in this project, in /resources/data/testdata.sql. This will create the users user1 to user5 with the passwords Password1 to Password5. The passwords are hashed using the bcrypt algorithm.

Configuration

There are several ways to configure the game server. This section will cover the different ways to configure the game server.

To run the server, you need at least to provide a configuration for the database. Redundant configuration will be treated in the following order: Console Arguments > Environment Variables > Configuration File. The values read from password files or a file containing the jwt secret will overwrite the values passed directly using the mentioned ways to configure the server.

SMTP

To send emails, you need to provide SMTPS credentials to the server application. Note that emails can only be sent using SSL/TLS.

Push Notifications

For push notifications, Google Firebase Cloud Messaging is used. To enable push notifications, create a firebase project, place your private key on your server and provide the path to that private key using the GOOGLE_APPLICATION_CREDENTIALS environment variable. Additionally, provide the Firebase ProjectID using the environment variable GCLOUD_PROJECT. Make sure that your clients also support push notifications using Firebase Cloud Messaging.

For more details about how to setup Firebase, see https://firebase.google.com/docs/admin/setup#initialize-sdk.

Error Tracking

The Game Server uses Sentry's Raven for error tracking. Provide the DSN using the SENTRY_DSN environment variable to enable error tracking.

For more details about how to setup Raven, see https://docs.sentry.io/clients/go/.

Password Files

The Server allows you to provide the password for the database, the resource server, smtp and jwt secret using dedicated files. Just create a file for the password or secret you want to provide this way and provide just the password or secret in it without any other formatation. Then provide the path to the file using the jwt-file or pwfile options of the server's configuration instead of the value directly.

When you run the server without the -d flag, you cannot pass the database password and the jwt secret directly to the server, instead you must provide a file with the database password and a file with the jwt password.

Environment Variables

You can provide the path to the database password file in the environment variable PWFILE.
You can provide the path to the file containing the jwt secret in the environment variable JWTFILE.
You can provide the port, the server should be running on using the environment variable PORT.

Configuration File

You can provide the configuration using a configuration file, which must be named /config.json and must right in the root of the working directory.

Use the following as template for your config.json and remove the inapplicable fields.

{
  "jwt-secret": "SECRET",
  "jwt-file": "/path/to/file/with/secret",
  "database": {
    "name": "DATABASENAME",
    "user": "USERNAME",
    "host": "HOSTNAME",
    "password": "PASSWORD",
    "pwfile": "/path/to/file/with/database/password"
  },
  "resource-server": {
    "host": "HOSTNAME",
    "user": "USERNAME",
    "password": "PASSWORD",
    "pwfile": "/path/to/file/with/resource-server/password"
  },
  "smtp": {
    "hostname": "HOSTNAME",
    "username": "USERNAME",
    "password": "PASSWORD",
    "port": 465
  }
}

Notice that the jwt-file and the database.pwfile fields, if present, will overwrite the values set using the environment variables.

Console Arguments

You can pass most parameters, such as for the configuration of the database, smtp, the resource server and the jwt secret as console arguments. Call the executable just with the -help parameter to see the which options are available and how to use them.

Note that these arguments overwrite the values you provided using the other ways.

Run the Server

The server can be started using go run main.go or by running the executable which can be build by go build. Make sure to provide the configuration. You need to have the /assets/ directory right in the working directory.

For development purposes, start the server with -d parameter. This will set Gin to debug mode and allows the database password and the jwt secret to be provided directly using the default configuration file or console arguments.

Build the Server

To build the server run go build after you installed the server's dependencies.

Further Information

You can find further information about the server or Akamu itself in our wiki at https://confluence.akamu.de or from us in person.

Contact us at team@akamu.de and join our team.