package config import ( "log/slog" "os" "path/filepath" "time" "github.com/BurntSushi/toml" ) var ( Port uint32 = 8080 MaxDirectMsgCache uint32 = 32 MaxHubChannelMsgCache uint32 = 16 FileStorageBucketName string = "communicator" MaxRequestBytes uint32 = 4 << 10 MaxRequestWithFileBytes uint32 = 1 << 30 MaxRequestWithAvatarBytes uint32 = 1 << 20 MaxRequestWithProfileBgBytes uint32 = 4 << 20 FileProcessingPartBytes uint64 = 12 << 20 FileProcessingThreads uint = 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"` 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 uint `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 }