package main import ( "encoding/json" "net/http" "git.dev.alexdunmow.com/block/pluginsdk/plugin" "git.dev.alexdunmow.com/block/pluginsdk/route" ) const pluginName = "newsletter-9a0b11" // 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, "/subscribers", route.Public, handleList) return r } func handleList(w http.ResponseWriter, r *http.Request) { table, err := current.DataTables.GetTableByKey(r.Context(), "subscribers") 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 rows", http.StatusInternalServerError) return } _ = json.NewEncoder(w).Encode(rows) }