gotemplate
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
.
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.
-
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.