package main import ( "encoding/json" "net/http" "git.dev.alexdunmow.com/block/pluginsdk/plugin" "git.dev.alexdunmow.com/block/pluginsdk/route" ) const pluginName = "signups-3f2a10" // Registration is the plugin entry registration. var Registration = plugin.PluginRegistration{ Name: pluginName, Version: "1.0.0", HTTPHandler: newHTTPHandler, } var current plugin.CoreServices func newHTTPHandler(deps plugin.CoreServices) http.Handler { current = deps r := route.New(pluginName) r.Handle(http.MethodGet, "/signups", route.Public, handleSignups) return r } func handleSignups(w http.ResponseWriter, r *http.Request) { table, err := current.DataTables.GetTableByKey(r.Context(), "signups") if err != nil { http.Error(w, "not found", http.StatusNotFound) return } rows, err := current.DataTables.ListRows(r.Context(), table.ID, 100, 0) if err != nil { http.Error(w, "could not load sign-ups", http.StatusInternalServerError) return } _ = json.NewEncoder(w).Encode(rows) }