add index template {ls,sh} (#33)

This commit is contained in:
T. von Dein
2026-06-15 15:18:21 +02:00
parent ec1ce56b2d
commit d0d1d69791
15 changed files with 875 additions and 100 deletions

View File

@@ -110,12 +110,14 @@ func Repl(conf *cfg.Config) error {
fmt.Println(err)
}
err = CallAPI(conf, parts[0], parts[1], data)
raw, err := CallAPI(conf, parts[0], parts[1], data)
if err != nil {
fmt.Printf("failed to call API: %s\n", esErrorString(err))
}
reader.SetPrompt("> ")
if err := prettyfiJson(conf, raw); err != nil {
fmt.Println(err)
}
}
return nil
@@ -125,7 +127,7 @@ func encodeAuth(username, password string) string {
return base64.StdEncoding.EncodeToString([]byte(username + ":" + password))
}
func CallAPI(conf *cfg.Config, verb, path, data string) error {
func CallAPI(conf *cfg.Config, verb, path, data string) ([]byte, error) {
verb = strings.ToUpper(verb)
// we're using port-forwards anyway
@@ -137,7 +139,7 @@ func CallAPI(conf *cfg.Config, verb, path, data string) error {
req, err := http.NewRequest(verb, conf.DefaultCluster.Uri+path, bytes.NewBuffer([]byte(data)))
if err != nil {
return err
return nil, err
}
req.Header.Add("Content-Type", "application/json")
@@ -147,16 +149,16 @@ func CallAPI(conf *cfg.Config, verb, path, data string) error {
// actually execute the request
resp, err := client.Do(req)
if err != nil {
return err
return nil, err
}
// Read and print response
body, err := io.ReadAll(resp.Body)
if err != nil {
return fmt.Errorf("failed to read response body: %s", err)
return nil, fmt.Errorf("failed to read response body: %s", err)
}
return prettyfiJson(conf, body)
return body, nil
}
func prettyfiJson(conf *cfg.Config, raw []byte) error {