Initial commit

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2025-08-21 16:22:03 +02:00
commit ef9aca1f3b
Signed by: jriou
GPG key ID: 9A099EDA51316854
26 changed files with 1668 additions and 0 deletions

65
src/server/config.go Normal file
View file

@ -0,0 +1,65 @@
package server
import (
"fmt"
"git.riou.xyz/jriou/coller/internal"
)
type Config struct {
Title string `json:"title"`
DatabaseType string `json:"database_type"`
DatabaseDsn string `json:"database_dsn"`
IDLength int `json:"id_length"`
PasswordLength int `json:"password_length"`
ExpirationInterval int `json:"expiration_interval"`
ListenAddress string `json:"listen_address"`
ListenPort int `json:"listen_port"`
Expirations []int `json:"expirations"`
Expiration int `json:"expiration"`
MaxUploadSize int64 `json:"max_upload_size"`
ShowVersion bool `json:"show_version"`
}
func NewConfig() *Config {
return &Config{
Title: "Coller",
DatabaseType: "sqlite",
DatabaseDsn: "collerd.db",
IDLength: 5,
PasswordLength: 16,
ExpirationInterval: 60, // 1 minute
ListenAddress: "127.0.0.1",
ListenPort: 8080,
Expirations: []int{
300, // 5 minutes
3600, // 1 hour
86400, // 1 day
604800, // 7 days
18144000, // 30 days
},
Expiration: 604800, // 7 days
MaxUploadSize: 10485760, // 10MiB (encoded)
ShowVersion: false,
}
}
func (c *Config) Check() error {
if len(c.Expirations) == 0 {
return fmt.Errorf("expirations are required")
}
for _, e := range c.Expirations {
if e <= 0 {
return fmt.Errorf("invalid expiration %d: must be greater than zero", e)
}
}
if c.IDLength <= 0 {
return fmt.Errorf("identifiers length must be greater than zero")
}
if c.PasswordLength < internal.MIN_PASSWORD_LENGTH || c.PasswordLength > internal.MAX_PASSWORD_LENGTH {
return fmt.Errorf("password length must be between %d and %d", internal.MIN_PASSWORD_LENGTH, internal.MAX_PASSWORD_LENGTH)
}
return nil
}