|
|
|
@ -19,8 +19,10 @@ type Router interface {
|
|
|
|
|
|
|
|
|
|
type Bog struct {
|
|
|
|
|
router Router
|
|
|
|
|
adminRouter Router
|
|
|
|
|
file_service dataswamp.SwampFileService
|
|
|
|
|
address string
|
|
|
|
|
adminAddress string
|
|
|
|
|
logger dataswamp.Logger
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -40,22 +42,12 @@ func buildNamespaceRepository(config DatabaseConfig) namespace.Repository {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *Bog) fileHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
if r.URL.Path == "/" {
|
|
|
|
|
templ, err := template.ParseFiles("server/views/dashboard.html")
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stats, _ := b.file_service.NamespaceStats()
|
|
|
|
|
err = templ.Execute(w, stats)
|
|
|
|
|
ref := swampfile.FileReference{r.URL.Path, r.Header["User-Agent"][0]}
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
if r.URL.Path == "/" {
|
|
|
|
|
http.NotFound(w, r)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
ref := swampfile.FileReference{r.URL.Path, r.Header["User-Agent"][0]}
|
|
|
|
|
|
|
|
|
|
switch r.Method {
|
|
|
|
|
case "GET":
|
|
|
|
@ -105,8 +97,24 @@ func (b *Bog) fileHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *Bog) dashboardHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
templ, err := template.ParseFiles("server/views/dashboard.html")
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stats, _ := b.file_service.NamespaceStats()
|
|
|
|
|
err = templ.Execute(w, stats)
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
panic(err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *Bog) routes() {
|
|
|
|
|
b.router.HandleFunc("/", b.fileHandler)
|
|
|
|
|
b.adminRouter.HandleFunc("/", b.dashboardHandler)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (b *Bog) cleanNamespaces() {
|
|
|
|
@ -118,7 +126,8 @@ func (b *Bog) cleanNamespaces() {
|
|
|
|
|
|
|
|
|
|
func New(config *Configuration) *Bog {
|
|
|
|
|
b := new(Bog)
|
|
|
|
|
b.address = config.bindAddress()
|
|
|
|
|
b.address = config.Server.bindAddress()
|
|
|
|
|
b.adminAddress = config.Admin.bindAddress()
|
|
|
|
|
|
|
|
|
|
fsSwampRepo := buildFileDataRepository(config.File)
|
|
|
|
|
nsRepo := buildNamespaceRepository(config.Database)
|
|
|
|
@ -133,6 +142,7 @@ func New(config *Configuration) *Bog {
|
|
|
|
|
)
|
|
|
|
|
b.logger = logger
|
|
|
|
|
b.router = new(http.ServeMux)
|
|
|
|
|
b.adminRouter = new(http.ServeMux)
|
|
|
|
|
b.routes()
|
|
|
|
|
return b
|
|
|
|
|
}
|
|
|
|
@ -140,5 +150,6 @@ func New(config *Configuration) *Bog {
|
|
|
|
|
func (b *Bog) Run() {
|
|
|
|
|
b.logger.Info("Starting bog on address: %s", b.address)
|
|
|
|
|
go b.cleanNamespaces()
|
|
|
|
|
go func(){ http.ListenAndServe(b.adminAddress, b.adminRouter) }()
|
|
|
|
|
http.ListenAndServe(b.address, b.router)
|
|
|
|
|
}
|
|
|
|
|