refactor: minor changes and fixes
This commit is contained in:
parent
b791b84890
commit
dc8a9cff20
5 changed files with 11 additions and 25 deletions
|
|
@ -114,7 +114,6 @@ var listPluginsCmd = &cobra.Command{
|
|||
Msg("response returned bad status")
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println(string(body))
|
||||
err = json.Unmarshal(body, &plugins)
|
||||
if err != nil {
|
||||
log.Error().Err(err).
|
||||
|
|
@ -125,7 +124,7 @@ var listPluginsCmd = &cobra.Command{
|
|||
for _, pluginName := range args {
|
||||
// make request to /list endpoint
|
||||
res, body, err = c.MakeRequest(client.HTTPEnvelope{
|
||||
Path: fmt.Sprintf("/plugins/%s", pluginName),
|
||||
Path: fmt.Sprintf("/plugins/%s/info", pluginName),
|
||||
Method: http.MethodGet,
|
||||
})
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@ import (
|
|||
type DataFormat string
|
||||
|
||||
const (
|
||||
List DataFormat = "list"
|
||||
JSON DataFormat = "json"
|
||||
FORMAT_YAML DataFormat = "yaml"
|
||||
List DataFormat = "list"
|
||||
JSON DataFormat = "json"
|
||||
YAML DataFormat = "yaml"
|
||||
)
|
||||
|
||||
func (df DataFormat) String() string {
|
||||
|
|
@ -22,12 +22,12 @@ func (df DataFormat) String() string {
|
|||
|
||||
func (df *DataFormat) Set(v string) error {
|
||||
switch DataFormat(v) {
|
||||
case List, JSON, FORMAT_YAML:
|
||||
case List, JSON, YAML:
|
||||
*df = DataFormat(v)
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("must be one of %v", []DataFormat{
|
||||
List, JSON, FORMAT_YAML,
|
||||
List, JSON, YAML,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -48,7 +48,7 @@ func Marshal(data interface{}, outFormat DataFormat) ([]byte, error) {
|
|||
} else {
|
||||
return bytes, nil
|
||||
}
|
||||
case FORMAT_YAML:
|
||||
case YAML:
|
||||
if bytes, err := yaml.Marshal(data); err != nil {
|
||||
return nil, fmt.Errorf("failed to marshal data into YAML: %w", err)
|
||||
} else {
|
||||
|
|
@ -72,7 +72,7 @@ func Unmarshal(data []byte, v interface{}, inFormat DataFormat) error {
|
|||
if err := json.Unmarshal(data, v); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal data into JSON: %w", err)
|
||||
}
|
||||
case FORMAT_YAML:
|
||||
case YAML:
|
||||
if err := yaml.Unmarshal(data, v); err != nil {
|
||||
return fmt.Errorf("failed to unmarshal data into YAML: %w", err)
|
||||
}
|
||||
|
|
@ -98,7 +98,7 @@ func DataFormatFromFileExt(path string, defaultFmt DataFormat) DataFormat {
|
|||
return JSON
|
||||
case ".yaml", ".yml", ".YAML", ".YML":
|
||||
// The file is a YAML file
|
||||
return FORMAT_YAML
|
||||
return YAML
|
||||
}
|
||||
return defaultFmt
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package service
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
|
@ -35,7 +34,6 @@ func (s *Service) ListPlugins() http.HandlerFunc {
|
|||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
fmt.Printf("%v", plugins)
|
||||
|
||||
w.Write(body)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,16 +64,6 @@ func (s *Service) ListProfiles() http.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
// func (s *Service) CreateProfiles() http.HandlerFunc {
|
||||
// return func(w http.ResponseWriter, r *http.Request) {
|
||||
// var (
|
||||
// path = chi.URLParam(r, "path")
|
||||
// err error
|
||||
// )
|
||||
|
||||
// }
|
||||
// }
|
||||
|
||||
func (s *Service) GetProfile() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
|
|
|
|||
|
|
@ -184,15 +184,14 @@ func LoadPluginsFromDir(dirpath string) (map[string]makeshift.Plugin, error) {
|
|||
|
||||
// helper to check for valid extensions
|
||||
var hasValidExt = func(path string) bool {
|
||||
var validExts = []string{".so", ".dylib", ".dll"}
|
||||
return slices.Contains(validExts, filepath.Ext(path))
|
||||
return slices.Contains([]string{".so", ".dylib", ".dll"}, filepath.Ext(path))
|
||||
}
|
||||
|
||||
// walk all files in directory only loading *valid* plugins
|
||||
err = filepath.Walk(dirpath, func(path string, info fs.FileInfo, err error) error {
|
||||
// skip trying to load generator plugin if directory or error
|
||||
// only try loading if file has .so extension
|
||||
if info.IsDir() || err != nil || hasValidExt(path) {
|
||||
if info.IsDir() || err != nil || !hasValidExt(path) {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue