server

command module
v0.0.0-...-cf413bb Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2023 License: AGPL-3.0 Imports: 15 Imported by: 0

README

Thinking of You API server

Build Status

The goal of the api server is to provide basic device state delivery for client apps and a simple message interface for publishing and retreiving media to one or more target inboxes.

API Documentation

For now, refer to the OpenAPI spec file in the api directory for endpoint and response documentation.

Database

An embedded sqlite3 database is used for persistent storage in this project. SQLite is a reliable and comprehensive embedded database used in many industries and applications. For this project, it gives a well understood and reliable basis for data persistence that should allow for minimal maintainance to keep the server running once deployed. Use the database/init_dev.sqlite.sql file for initalizing a testing instance of the database.

Create Test Database
# install sqlite3 cli tool
sudo apt install sqlite3
# pipe in database file
sqlite3 ./tofu.db < ./database/init_dev.sqlite.sql
Compiling with sqlite3

One caviate of using the sqlite3 database engine is that the C stdlib must be present on the target deployment platform and the compiling environment must have a C compiler toolchain to build the binary. See the library docs for more info.

For windows, see build.ps1

Run the Application

After creating the database file, use go run to compile and run the server.

go run ./cmd/server/
Run in Docker

If you don't want to compile and run from source, or you want to quickly switch between tagged releases, you can run the app in docker using the published container images.

docker run --rm \
	-p "8080:8080" \
	-v $(pwd):/data \
	-e TOFU_DATA=/data \
	-e GIN_MODE=debug \
	dkr-reg.sysreturn.net/auxreturn/thinking-of-you:latest

Configuration

The server accepts the following configuration via environment variables

# http listen address and port
TOFU_ADDR=
TOFU_PORT="8080"

# filepath and name of main database file 
TOFU_DB_FILE=tofu.db

# s3 style storage endpoint id and secret
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=

# s3 bucket to store uploaded files
# both AWS_ACCESS_KEY_ID and TOFU_STORAGE_BUCKET must be defined for 
# s3 external storage to become active. Otherwise, local filesystem is used.
TOFU_STORAGE_BUCKET=

# region and endpoint settings for s3 api
AWS_REGION=
TOFU_STORAGE_ENDPOINT=

# file prefix for files uploaded to message storage
TOFU_STORAGE_PREFIX=uploads

# use the digitaloceans cdn download url instead of the regular spaces download url
TOFU_STORAGE_DO_CDN=FALSE

Testing the Application

Start with the main client entrypoint

curl --user alice:alice http://localhost:8080/manifest

you should get the following response

{
	"id": "alice",
	"name": "Alice",
	"icon": "https://randomuser.me/api/portraits/women/67.jpg",
	"targets": [{
		"id": "bob",
		"name": "Bob",
		"icon": "https://randomuser.me/api/portraits/men/32.jpg"
	}, {
		"id": "carol",
		"name": "Carol",
		"icon": "https://randomuser.me/api/portraits/women/16.jpg"
	}, {
		"id": "dave",
		"name": "Dave",
		"icon": "https://randomuser.me/api/portraits/men/61.jpg"
	}, {
		"id": "erin",
		"name": "Erin",
		"icon": "https://randomuser.me/api/portraits/women/15.jpg"
	}, {
		"id": "testgroup",
		"name": "Test Group"
	}]
}
Test User credentials

All test users have a user name and password set. The password is the same as their id, so in curl use

curl --user alice:alice http://...
curl --user bob:bob http://...
...etc

Documentation

Overview

Copyright (C) 2021 Sysreturn Community Contributors SPDX-License-Identifier: AGPL-3.0-or-later

Directories

Path Synopsis
internal
jobs
scheduled and async jobs.
scheduled and async jobs.
pkg

Jump to

Keyboard shortcuts

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