Fix quota from config

master
Caj Larsson 3 years ago
parent 9eca063c9f
commit e9fc400389

@ -81,8 +81,9 @@ func New(config *Configuration) *Bog {
fsBogRepo := buildFileDataRepository(config.File)
uaRepo := buildUserAgentRepository(config.Database)
file_service := domain.NewBogFileService(
uaRepo, fsBogRepo, config.Quota.DefaultSizeBytes(), config.Quota.DefaultDuration(),
uaRepo, fsBogRepo, config.Quota.ParsedSizeBytes(), config.Quota.ParsedDuration(),
)
b.mux = buildHttpMux(file_service)
return b

@ -8,15 +8,11 @@ import (
)
type QuotaConfig struct {
default_size string
default_duration string
}
func (qc QuotaConfig) DefaultSizeBytes() int64 {
func (qc QuotaConfig) ParsedSizeBytes() int64 {
var v datasize.ByteSize
err := v.UnmarshalText([]byte(qc.default_size))
err := v.UnmarshalText([]byte(qc.DefaultSize))
if err != nil {
panic(err)
@ -25,8 +21,10 @@ func (qc QuotaConfig) DefaultSizeBytes() int64 {
return int64(v)
}
func (qc QuotaConfig) DefaultDuration() time.Duration {
d, err := time.ParseDuration(qc.default_duration)
func (qc QuotaConfig) ParsedDuration() time.Duration {
fmt.Sprintf("duration str: %s", qc.DefaultDuration)
d, err := time.ParseDuration(qc.DefaultDuration)
if err != nil {
panic(err)
@ -39,6 +37,12 @@ func (qc QuotaConfig) DefaultDuration() time.Duration {
return d
}
type QuotaConfig struct {
DefaultSize string `toml:"default_size"`
DefaultDuration string `toml:"default_duration"`
}
type ServerConfig struct {
Port int64
Host string

@ -1,7 +1,3 @@
[quota]
default_size = "1GB"
default_duration = "14D"
[server]
port = 8002
host = "127.0.0.1"
@ -12,3 +8,7 @@
[database]
backend = "sqlite"
connection = "sql.db"
[quota]
default_size = "1GB"
default_duration = "72h"

@ -3,6 +3,7 @@ package main
import (
"caj-larsson/bog/application"
"io/ioutil"
"fmt"
)
func main() {
@ -17,6 +18,8 @@ func main() {
panic(err)
}
fmt.Printf("%+v\n", config)
bog := application.New(config)
bog.Run()
}

Loading…
Cancel
Save