|
|
|
@ -4,7 +4,7 @@ import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"net/http"
|
|
|
|
|
"strconv"
|
|
|
|
|
// "io"
|
|
|
|
|
"time"
|
|
|
|
|
"caj-larsson/bog/dataswamp"
|
|
|
|
|
"caj-larsson/bog/dataswamp/namespace"
|
|
|
|
|
"caj-larsson/bog/dataswamp/swampfile"
|
|
|
|
@ -31,7 +31,7 @@ func buildFileDataRepository(config FileConfig) swampfile.Repository {
|
|
|
|
|
return r
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func buildUserAgentRepository(config DatabaseConfig) namespace.Repository {
|
|
|
|
|
func buildNamespaceRepository(config DatabaseConfig) namespace.Repository {
|
|
|
|
|
if config.Backend != "sqlite" {
|
|
|
|
|
panic("Can only handle sqlite")
|
|
|
|
|
}
|
|
|
|
@ -84,15 +84,22 @@ func (b *Bog) routes() {
|
|
|
|
|
b.router.HandleFunc("/", b.fileHandler)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *Bog) cleanNamespaces(){
|
|
|
|
|
for true {
|
|
|
|
|
b.file_service.CleanUpExpiredFiles()
|
|
|
|
|
time.Sleep(time.Minute * 10)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func New(config *Configuration) *Bog {
|
|
|
|
|
b := new(Bog)
|
|
|
|
|
b.address = config.bindAddress()
|
|
|
|
|
|
|
|
|
|
fsSwampRepo := buildFileDataRepository(config.File)
|
|
|
|
|
uaRepo := buildUserAgentRepository(config.Database)
|
|
|
|
|
nsRepo := buildNamespaceRepository(config.Database)
|
|
|
|
|
|
|
|
|
|
b.file_service = dataswamp.NewSwampFileService(
|
|
|
|
|
uaRepo, fsSwampRepo, config.Quota.ParsedSizeBytes(), config.Quota.ParsedDuration(),
|
|
|
|
|
nsRepo, fsSwampRepo, config.Quota.ParsedSizeBytes(), config.Quota.ParsedDuration(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
b.router = new(http.ServeMux)
|
|
|
|
@ -101,5 +108,6 @@ func New(config *Configuration) *Bog {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *Bog) Run() {
|
|
|
|
|
go b.cleanNamespaces()
|
|
|
|
|
http.ListenAndServe(b.address, b.router)
|
|
|
|
|
}
|
|
|
|
|