internal/component: Check for provisionable

This commit is contained in:
Tom Wiesing 2022-12-13 10:10:51 +01:00
parent 5053c982aa
commit 2a308ee03c
No known key found for this signature in database
6 changed files with 24 additions and 20 deletions

1
go.mod
View file

@ -11,6 +11,7 @@ require (
github.com/go-sql-driver/mysql v1.6.0
github.com/gorilla/mux v1.8.0
github.com/gorilla/websocket v1.5.0
github.com/julienschmidt/httprouter v1.3.0
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.28.0
github.com/tkw1536/goprogram v0.2.4

2
go.sum
View file

@ -27,6 +27,8 @@ github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkr
github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=

View file

@ -7,7 +7,7 @@ import (
"github.com/FAU-CDI/wisski-distillery/internal/dis/component"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/exporter"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/exporter/logger"
"github.com/gorilla/mux"
"github.com/julienschmidt/httprouter"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/instances"
"github.com/FAU-CDI/wisski-distillery/pkg/httpx"
@ -33,7 +33,7 @@ var (
func (*Info) Routes() []string { return []string{"/dis/"} }
func (info *Info) Handler(ctx context.Context, route string) (handler http.Handler, err error) {
router := mux.NewRouter()
router := httprouter.New()
{
socket := &httpx.WebSocket{
Context: ctx,
@ -46,40 +46,35 @@ func (info *Info) Handler(ctx context.Context, route string) (handler http.Handl
}
// handle everything
router.Path(route).HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, route+"/index", http.StatusTemporaryRedirect)
router.HandlerFunc(http.MethodGet, route, func(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "index", http.StatusTemporaryRedirect)
})
// add a handler for the index page
router.Path(route + "index").Handler(httpx.HTMLHandler[indexContext]{
router.Handler(http.MethodGet, "index", httpx.HTMLHandler[indexContext]{
Handler: info.index,
Template: indexTemplate,
})
// add a handler for the component page
router.Path(route + "components").Handler(httpx.HTMLHandler[componentContext]{
router.Handler(http.MethodGet, "components", httpx.HTMLHandler[componentContext]{
Handler: info.components,
Template: componentsTemplate,
})
// add a handler for the component page
router.Path(route + "ingredients/{slug}").Handler(httpx.HTMLHandler[ingredientsContext]{
router.Handler(http.MethodGet, "ingredients/{slug}", httpx.HTMLHandler[ingredientsContext]{
Handler: info.ingredients,
Template: ingredientsTemplate,
})
// add a handler for the instance page
router.Path(route + "instance/{slug}").Handler(httpx.HTMLHandler[instanceContext]{
router.Handler(http.MethodGet, "instance/{slug}", httpx.HTMLHandler[instanceContext]{
Handler: info.instance,
Template: instanceTemplate,
})
router.Path(route + "api/login").Handler(httpx.RedirectHandler(func(r *http.Request) (string, int, error) {
// enforce POST
if r.Method != http.MethodPost {
return "", 0, httpx.ErrMethodNotAllowed
}
router.Handler(http.MethodPost, "api/login", httpx.RedirectHandler(func(r *http.Request) (string, int, error) {
// parse the form
if err := r.ParseForm(); err != nil {
return "", 0, err

View file

@ -17,6 +17,10 @@ type Meta struct {
sc map[string]*Storage
}
var (
_ component.Provisionable = (*Meta)(nil)
)
// Storage returns a Storage for the instance with the given slug.
// When slug is nil, returns a global storage.
func (meta *Meta) Storage(slug string) *Storage {

View file

@ -21,9 +21,10 @@ type SQL struct {
}
var (
_ component.Backupable = (*SQL)(nil)
_ component.Snapshotable = (*SQL)(nil)
_ component.Installable = (*SQL)(nil)
_ component.Backupable = (*SQL)(nil)
_ component.Snapshotable = (*SQL)(nil)
_ component.Installable = (*SQL)(nil)
_ component.Provisionable = (*SQL)(nil)
)
func (sql *SQL) Path() string {

View file

@ -18,9 +18,10 @@ type Triplestore struct {
}
var (
_ component.Backupable = (*Triplestore)(nil)
_ component.Snapshotable = (*Triplestore)(nil)
_ component.Installable = (*Triplestore)(nil)
_ component.Backupable = (*Triplestore)(nil)
_ component.Snapshotable = (*Triplestore)(nil)
_ component.Installable = (*Triplestore)(nil)
_ component.Provisionable = (*Triplestore)(nil)
)
func (ts *Triplestore) Path() string {