message-server-go

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

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

Go to latest
Published: Oct 23, 2020 License: Apache-2.0 Imports: 1 Imported by: 0

README

message-server-go

Go Gitpod ready-to-code

config

env vars
  • app config:
    • APP_LOG_FORMAT: log format, text for normal logs and anything else for JSON logs
    • APP_DATABASE_URL: app database connection URL
    • APP_DATABASE_ENGINE: app database engine (sqlite3 is the only one tested until now)
    • APP_DATABASE_LOG: app log database queries (true|false)?
  • authentication config:
    • AUTH_DATABASE_URL: authentication database connection URL
    • AUTH_DATABASE_ENGINE:authentication database engine (sqlite3 is the only one tested until now)
    • AUTH_DATABASE_LOG: authentication log database queries (true|false)?
    • AUTH_USER_PATTERN: pattern for user validation
    • AUTH_PASS_PATTERN: pattern for password validation
    • AUTH_JWT_SECRET: secret used to sign JWT tokens
    • AUTH_USER_DEFAULT_ACTIVE: default state for new users (true|false)
  • CORS interceptor config:
    • CORS_ALLOW_METHODS: HTTP request methods allowed
    • CORS_ALLOW_HEADERS: HTTP headers allowed
    • 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 "MyStrongPass@1" -a
curl -i localhost:8000/login -d '{"user": "eldius", "pass": "MyStrongPass@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": "pass@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": "user", "pass": "pass"}' 2>/dev/null | jq -r '. | .token' )" -d '{"to": "user1","msg": "My new message 01!"}' 2>/dev/null

Documentation

Overview

Copyright © 2020 NAME HERE <EMAIL ADDRESS>

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Directories

Path Synopsis
Package cmd have all command line commands
Package cmd have all command line commands

Jump to

Keyboard shortcuts

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