9b0b6b1ecf
- ntfy - keyserver - webhook - webserver functional modules.
35 lines
751 B
Go
35 lines
751 B
Go
package webserver
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
type Config struct {
|
|
Enabled bool
|
|
ContentDir string
|
|
}
|
|
|
|
type Module struct {
|
|
cfg Config
|
|
}
|
|
|
|
func New(cfg Config) *Module {
|
|
return &Module{cfg: cfg}
|
|
}
|
|
|
|
func (m *Module) Name() string { return "webserver" }
|
|
|
|
// RegisterRoutes uses a catch-all "/" handler — must be registered
|
|
// LAST in main.go, after any more specific routes (keyserver, webhook),
|
|
// since gorilla/mux matches in registration order.
|
|
func (m *Module) RegisterRoutes(r *mux.Router) {
|
|
fs := http.FileServer(http.Dir(m.cfg.ContentDir))
|
|
r.PathPrefix("/").Handler(fs)
|
|
}
|
|
|
|
func (m *Module) Start(ctx context.Context) error { return nil }
|
|
func (m *Module) Stop(ctx context.Context) error { return nil }
|