add configs from file, continue develpoment on hubs
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
)
|
||||
|
||||
// Array-size constants — must be compile-time values; cannot be overridden via config file.
|
||||
const (
|
||||
MaxDirectMsgCache uint32 = 32
|
||||
MaxHubMsgCache uint32 = 32
|
||||
)
|
||||
|
||||
var (
|
||||
Port uint32 = 8080
|
||||
FileStorageBucketName string = "communicator"
|
||||
MaxRequestBytes uint32 = 4 << 10
|
||||
MaxRequestWithFileBytes uint32 = 1 << 30
|
||||
MaxRequestWithAvatarBytes uint = 1 << 20
|
||||
MaxRequestWithProfileBgBytes uint = 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"`
|
||||
MaxHubMsgCache uint32 `toml:"max_hub_msg_cache"`
|
||||
FileStorageBucketName string `toml:"file_storage_bucket_name"`
|
||||
MaxRequestBytes uint32 `toml:"max_request_bytes"`
|
||||
MaxRequestWithFileBytes uint32 `toml:"max_request_with_file_bytes"`
|
||||
MaxRequestWithAvatarBytes uint `toml:"max_request_with_avatar_bytes"`
|
||||
MaxRequestWithProfileBgBytes uint `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
|
||||
FileStorageBucketName = cfg.FileStorageBucketName
|
||||
MaxRequestBytes = cfg.MaxRequestBytes
|
||||
MaxRequestWithFileBytes = cfg.MaxRequestWithFileBytes
|
||||
MaxRequestWithAvatarBytes = cfg.MaxRequestWithAvatarBytes
|
||||
MaxRequestWithProfileBgBytes = cfg.MaxRequestWithProfileBgBytes
|
||||
FileProcessingPartBytes = cfg.FileProcessingPartBytes
|
||||
FileProcessingThreads = cfg.FileProcessingThreads
|
||||
FileDownloadLinkTtl = cfg.FileDownloadLinkTtl
|
||||
}
|
||||
Reference in New Issue
Block a user