gotemplate

module
v0.0.0-...-19f3120 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2020 License: MIT

README

gotemplate Go codecov

Build and Deploy

Environment variables

The application awaits next environment variables provided in .env file in the project folder:

Environment Default Description Example
DEBUG false Turn on debug mode true
SERVICE_URL URL to the backend service http://0.0.0.0:8080/
SERVICE_PORT 8080 Port of the backend servuce 8080
EMAIL Default admin email e.duskaliev@innopolis.university
PASSWORD Default admin password verystrongpassword
SECRET Secret key for signing JWT tokens verystrongsecret
DB_CONN_STR Connection string to database engine postgres://attc:attcpwd@db:5432/attc?sslmode=disable
bolt:///Users/semior/go/src/github.com/Semior001/gotemplate/db
DB_TEST Connection string to database engine for tests (optional, needed only if you want to run tests) postgres://attc:attcpwd@localhost:5432/attc?sslmode=disable

Next environment variables depends on the kind of database that you're using:

Remark!. If you decided to do not use the Postgres as a database engine, remove the migration part from the Dockerfile and entrypoint script.

Run the application
docker-compose up -d
Env file example
DEBUG=true

#DB_CONN_STR=postgres://attc:attcpwd@db:5432/attc?sslmode=disable
DB_CONN_STR=bolt:///Users/semior/go/src/github.com/Semior001/gotemplate/db

SERVICE_URL=http://0.0.0.0:8080/
SERVICE_PORT=8080
EMAIL=e.duskaliev@innopolis.university
PASSWORD=test

SECRET=hO]rqN2cQ|r/oOWTS~*Q3=@w-zd<c"
DB_TEST=postgres://attc:attcpwd@localhost:5432/attc?sslmode=disable

# for postgres service
PG_USER=attc
PG_PWD=attcpwd
PG_DB=attc

Backend REST API

Several notes:

  • All timestamps in RFC3339 format, like 2020-06-30T22:01:53+06:00.
  • All durations in RFC3339 format, like 1h30m5s.
  • Clocks should be represented in ISO 8601 format, like 15:04:05.
Errors format
Unauthorized

In case if the user requested a route without proper auth, the 401 status code will be returned with the Unauthorized body content.

General

Example:

{
	"code"     : 0,
	"details"  : "failed to update event",
	"error"    : "event not found"
}

In case of bad client request error might have null value.

Supported error codes for client mapping:

const (
	ErrInternal   ErrCode = 0 // any internal error
	ErrDecode     ErrCode = 1 // failed to unmarshal incoming request
	ErrBadRequest ErrCode = 2 // request contains incorrect data or doesn't contain data
)
Client methods
Auth methods
  • GET /auth/local/login - authenticate and get JWT token. The token will be saved in secure cookies.

    • Body:
      {
          "user": "e.duskaliev@innopolis.university",
          "passwd": "verystrongpassword"
      }
      
    • Response (example, shrinked for the sake of simplicity; next examples will be also shrinked):
      • Headers:
        Set-Cookie: JWT=json.web.token; Path=/; Max-Age=720000; HttpOnly
        
      • Body (avatar is not used in the application, it is provided by the auth library):
        {
          "name": "e.duskaliev@innopolis.university",
          "id": "local_7f48448389aa065af161c3215237acef139e4ecf",
          "picture": "http://0.0.0.0:8080/avatar/", 
          "email": "e.duskaliev@innopolis.university",
          "attrs": {
            "privileges": [
              "read_users",
              "edit_users",
              "list_users",
              "add_users"
            ]
          }
        }
        
  • GET /auth/local/user - get information about the logged in user. Requires authed user.

    • Body: empty
    • Response:
      {
        "name": "e.duskaliev@innopolis.university",
        "id": "local_7f48448389aa065af161c3215237acef139e4ecf",
        "picture": "http://0.0.0.0:8080/avatar/", 
        "email": "e.duskaliev@innopolis.university",
        "attrs": {
          "privileges": [
            "read_users",
            "edit_users",
            "list_users",
            "add_users"
          ]
        }
      }
      
  • GET /auth/local/logout - logout from the app, this will remove the JWT token from cookies.

    • Body: empty
    • Response:
      • Headers:
        Set-Cookie: JWT=; Path=/; Expires=Thu, 01 Jan 1970 00:00:00 GMT; Max-Age=0
        
      • Body: empty

Directories

Path Synopsis
app
cmd
Package cmd contains all cli commands, their arguments and tests to them
Package cmd contains all cli commands, their arguments and tests to them
store
Package store defines models and global methods to operate these models
Package store defines models and global methods to operate these models
store/service
Package service wraps user interfaces with common logic unrelated to any particular user implementation.
Package service wraps user interfaces with common logic unrelated to any particular user implementation.
store/user
Package user provides implementations for Interface for the database user repository.
Package user provides implementations for Interface for the database user repository.

Jump to

Keyboard shortcuts

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