Added: timezone support

This commit is contained in:
Aleksandr Soloshenko 2023-11-03 00:16:43 +07:00
parent 2b132b67f2
commit ce15a6ce53
7 changed files with 23 additions and 13 deletions

View File

@ -16,16 +16,16 @@ Authorization: Basic IUGFXE:v4ejpbeydvjo1h
{
"message": "Test",
"ttl": {{$randomInt 0 86400}},
"ttl": 60,
"phoneNumbers": [
"79990001234"
]
}
###
GET {{baseUrl}}/api/3rdparty/v1/message/pRl1wf_yez5TikJb_xemU HTTP/1.1
GET {{baseUrl}}/api/3rdparty/v1/message/iZo6T9hw7wTuKLQUIP29I HTTP/1.1
Authorization: Basic IUGFXE:v4ejpbeydvjo1h
###
GET {{baseUrl}}/api/mobile/v1/message HTTP/1.1
Authorization: Bearer KuvE4LBXzvy8QO2ZXDDMP
Authorization: Bearer KuvE4LBXzvy8QO2ZXDDMP

View File

@ -1,7 +1,7 @@
-- +goose Up
-- +goose StatementBegin
ALTER TABLE `messages`
ADD `valid_until` datetime;
ADD `valid_until` datetime(3) DEFAULT NULL;
-- +goose StatementEnd
---
-- +goose Down

View File

@ -9,10 +9,15 @@ services:
container_name: sms-gateway
environment:
- DEBUG=1
- HTTP__LISTEN=:3000
env_file:
- .env
ports:
- "4000:3000"
- "3000:3000"
- "3456:2345"
volumes:
- "../..:/app"
- "/tmp/sms-gateway/go-cache:/go/pkg"
extra_hosts:
- "host.docker.internal:host-gateway"
restart: 'no'

View File

@ -16,15 +16,16 @@ type Config struct {
}
type HTTP struct {
Listen string `yaml:"listen"`
Listen string `yaml:"listen" envconfig:"HTTP__LISTEN"`
}
type Database struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
User string `yaml:"user"`
Password string `yaml:"password"`
Database string `yaml:"database"`
Host string `yaml:"host" envconfig:"DATABASE__HOST"`
Port int `yaml:"port" envconfig:"DATABASE__PORT"`
User string `yaml:"user" envconfig:"DATABASE__USER"`
Password string `yaml:"password" envconfig:"DATABASE__PASSWORD"`
Database string `yaml:"database" envconfig:"DATABASE__DATABASE"`
Timezone string `yaml:"timezone" envconfig:"DATABASE__TIMEZONE"`
}
type FCMConfig struct {
@ -41,6 +42,7 @@ var defaultConfig = Config{
User: "sms",
Password: "sms",
Database: "sms",
Timezone: "UTC",
},
FCM: FCMConfig{
CredentialsJSON: "",

View File

@ -32,6 +32,7 @@ var Module = fx.Module(
User: cfg.Database.User,
Password: cfg.Database.Password,
Database: cfg.Database.Database,
Timezone: cfg.Database.Timezone,
}
}),
fx.Provide(func(cfg Config) services.PushServiceConfig {

View File

@ -14,6 +14,7 @@ type Config struct {
User string
Password string
Database string
Timezone string
}
// Helper function to set default values

View File

@ -3,6 +3,7 @@ package db
import (
"fmt"
"log"
"net/url"
sql "github.com/go-sql-driver/mysql"
"gorm.io/driver/mysql"
@ -33,7 +34,7 @@ func makeConfig(params Params) *gorm.Config {
func makeDSN(cfg Config) string {
cfg = configDefault(cfg)
return fmt.Sprintf(
"%s:%s@tcp(%s:%d)/%s?charset=utf8mb4,utf8&parseTime=true&tls=preferred",
cfg.User, cfg.Password, cfg.Host, cfg.Port, cfg.Database,
"%s:%s@tcp(%s:%d)/%s?charset=utf8mb4,utf8&parseTime=true&loc=%s&tls=preferred",
cfg.User, cfg.Password, cfg.Host, cfg.Port, cfg.Database, url.QueryEscape(cfg.Timezone),
)
}