Files
go-socket/packages/config/config.go
T
2026-04-25 16:04:53 +02:00

66 lines
2.5 KiB
Go

package config
import (
"log/slog"
"os"
"path/filepath"
"time"
"github.com/BurntSushi/toml"
)
var (
Port uint32 = 8080
MaxDirectMsgCache uint32 = 32
MaxHubChannelMsgCache uint32 = 16
MaxUserHubRoles uint8 = 64
FileStorageBucketName string = "communicator"
MaxRequestBytes uint32 = 4 << 10
MaxRequestWithFileBytes uint32 = 1 << 30
MaxRequestWithAvatarBytes uint32 = 1 << 20
MaxRequestWithProfileBgBytes uint32 = 4 << 20
FileProcessingPartBytes uint64 = 12 << 20
FileProcessingThreads uint32 = 3
FileDownloadLinkTtl time.Duration = 24 * time.Hour
)
type configFile struct {
Port uint32 `toml:"port"`
MaxDirectMsgCache uint32 `toml:"max_direct_messages_cache"`
MaxHubChannelMsgCache uint32 `toml:"max_hub_channel_msg_cache"`
MaxUserHubRoles uint8 `toml:"max_hub_roles"`
FileStorageBucketName string `toml:"file_storage_bucket_name"`
MaxRequestBytes uint32 `toml:"max_request_bytes"`
MaxRequestWithFileBytes uint32 `toml:"max_request_with_file_bytes"`
MaxRequestWithAvatarBytes uint32 `toml:"max_request_with_avatar_bytes"`
MaxRequestWithProfileBgBytes uint32 `toml:"max_request_with_profile_bg_bytes"`
FileProcessingPartBytes uint64 `toml:"file_processing_part_bytes"`
FileProcessingThreads uint32 `toml:"file_processing_threads"`
FileDownloadLinkTtl time.Duration `toml:"file_download_link_ttl"`
}
func LoadConfFile() {
path, err := os.Executable()
if err != nil {
panic(err)
}
var cfg configFile
if _, err := toml.DecodeFile("config.toml", &cfg); err != nil {
slog.Warn("Failed to load config.toml. Default values will be used", "path", filepath.Dir(path)+"/config.toml")
return
}
Port = cfg.Port
MaxDirectMsgCache = cfg.MaxDirectMsgCache
MaxHubChannelMsgCache = cfg.MaxHubChannelMsgCache
FileStorageBucketName = cfg.FileStorageBucketName
MaxRequestBytes = cfg.MaxRequestBytes
MaxRequestWithFileBytes = cfg.MaxRequestWithFileBytes
MaxRequestWithAvatarBytes = cfg.MaxRequestWithAvatarBytes
MaxRequestWithProfileBgBytes = cfg.MaxRequestWithProfileBgBytes
FileProcessingPartBytes = cfg.FileProcessingPartBytes
FileProcessingThreads = cfg.FileProcessingThreads
FileDownloadLinkTtl = cfg.FileDownloadLinkTtl
}