Giter Club home page Giter Club logo

message-server-go's Introduction

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
}'

message-server-go's People

Contributors

eldius avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.