feat: updated pkg implementations
This commit is contained in:
parent
86f37555b2
commit
8b161135ff
10 changed files with 579 additions and 140 deletions
|
|
@ -5,14 +5,15 @@ import (
|
|||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
configurator "git.towk2.me/towk/configurator/pkg"
|
||||
makeshift "git.towk2.me/towk/makeshift/pkg"
|
||||
)
|
||||
|
||||
func (s *Service) ListPlugins() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
plugins map[string]configurator.Plugin
|
||||
plugins map[string]makeshift.Plugin
|
||||
names []string
|
||||
body []byte
|
||||
err error
|
||||
|
|
@ -38,10 +39,35 @@ func (s *Service) ListPlugins() http.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func (s *Service) GetPlugin() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
pluginName = strings.TrimPrefix(r.URL.Path, "/plugin")
|
||||
plugin makeshift.Plugin
|
||||
body []byte
|
||||
err error
|
||||
)
|
||||
|
||||
plugin, err = LoadPluginFromFile(pluginName)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
body, err = json.Marshal(plugin)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(body)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Service) CreatePlugin() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
plugin configurator.Plugin
|
||||
plugin makeshift.Plugin
|
||||
path string
|
||||
err error
|
||||
)
|
||||
|
|
@ -79,7 +105,7 @@ func (s *Service) DeletePlugin() http.HandlerFunc {
|
|||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
path string
|
||||
plugin configurator.Plugin
|
||||
plugin makeshift.Plugin
|
||||
err error
|
||||
)
|
||||
|
||||
|
|
@ -100,9 +126,9 @@ func (s *Service) DeletePlugin() http.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func getPluginFromRequestBody(r *http.Request) (configurator.Plugin, error) {
|
||||
func getPluginFromRequestBody(r *http.Request) (makeshift.Plugin, error) {
|
||||
var (
|
||||
plugin configurator.Plugin
|
||||
plugin makeshift.Plugin
|
||||
body []byte
|
||||
err error
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue