Skip to content

Eldius/message-server-go

Repository files navigation

message-server-go

Go Gitpod ready-to-code

config

env vars

  • app config:
    • MESSENGER_APP_LOG_FORMAT: log format, text for normal logs and anything else for JSON logs
    • MESSENGER_APP_DATABASE_URL: app database connection URL
    • MESSENGER_APP_DATABASE_ENGINE: app database engine (sqlite3 is the only one tested until now)
    • MESSENGER_APP_DATABASE_LOG: app log database queries (true|false)?
  • authentication config:
    • MESSENGER_AUTH_USER_PATTERN: pattern for user validation
    • MESSENGER_AUTH_PASS_PATTERN: pattern for password validation
    • MESSENGER_AUTH_JWT_SECRET: secret used to sign JWT tokens
    • MESSENGER_AUTH_USER_DEFAULT_ACTIVE: default state for new users (true|false)
  • CORS interceptor config:
    • MESSENGER_CORS_ALLOW_METHODS: HTTP request methods allowed
    • MESSENGER_CORS_ALLOW_HEADERS: HTTP headers allowed
    • MESSENGER_CORS_ALLOW_ORIGIN: origin domains allowed

dev

start database using docker

docker run \
    --name test-db \
    -e MYSQL_ROOT_PASSWORD=my-secret-pw \
    -e MYSQL_DATABASE=auth_db \
    -e MYSQL_USER=auth_usr \
    -e MYSQL_PASSWORD=auth_pass \
    -p 3306:3306 \
    -d \
    --rm \
    mariadb:latest

mysql -u auth_usr -p -h 127.0.0.1

env vars

export APP_DATABASE_URL='auth_usr:auth_pass@tcp(127.0.0.1:3306)/auth_db'
export APP_DATABASE_ENGINE='mysql'

select users

mysql -u auth_usr -h 127.0.0.1 -p'auth_pass' < repository/testqueries/auth-server.sql
golangci-lint run && echo "" && go test ./... -coverprofile=coverage.out && echo "" && go tool cover -func=coverage.out

some tests

go run user add -u "eldius" -W "MyStrongAdminPass@1" -a
curl -i localhost:8000/login -d '{"user": "eldius", "pass": "MyStrongAdminPass@1"}'
# returns something like this
# {"token":"header.payload.sign"}
# the "header.payload.sign" value is acquired in the last snippet call
curl -i localhost:8000/admin -H "Authorization: Bearer header.payload.sign"
curl -i localhost:8000/admin -H "Authorization: Bearer $( curl --fail localhost:8000/login -d '{"user": "eldius", "pass": "MyStrongAdminPass@1"}' 2>/dev/null | jq -r '. | .token' )" 2>/dev/null
#send message
curl -i -XPOST localhost:8000/message -H "Authorization: Bearer $( curl --fail localhost:8000/login -d '{"user": "testUser", "pass": "MyStrongPass@1"}' 2>/dev/null | jq -r '. | .token' )" -d '{"to": "eldius","msg": "My new message 01!"}' 2>/dev/null
#fetch messages
curl -i -XGET localhost:8000/message -H "Authorization: Bearer $( curl --fail localhost:8000/login -d '{"user": "eldius", "pass": "MyStrongAdminPass@1"}' 2>/dev/null | jq -r '. | .token' )" 2>/dev/null
curl -i -XPOST http://localhost:8000/user -H "Authorization: Bearer $( curl --fail localhost:8000/login -d '{"user": "eldius", "pass": "MyStrongAdminPass@1"}' 2>/dev/null | jq -r '. | .token' )" \
-d '{
  "user": "fulanus",
  "pass": "pass",
  "name": "Fulanus",
  "active": true,
  "admin": true
}'

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published