|
@@ -2,6 +2,7 @@ package main
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
|
+ "encoding/json"
|
|
|
"flag"
|
|
|
"fmt"
|
|
|
"io"
|
|
@@ -10,6 +11,8 @@ import (
|
|
|
"net/http"
|
|
|
"os"
|
|
|
"time"
|
|
|
+
|
|
|
+ "git.lattuga.net/boyska/circolog"
|
|
|
)
|
|
|
|
|
|
var globalOpts struct {
|
|
@@ -29,6 +32,7 @@ func init() {
|
|
|
// TODO: implement set and get of config at runtime
|
|
|
//"set": setCmd,
|
|
|
//"get": getCmd,
|
|
|
+ "status": statusCmd,
|
|
|
"pause": pauseCmd,
|
|
|
"reload": reloadCmd,
|
|
|
"restart": restartCmd,
|
|
@@ -40,6 +44,40 @@ func init() {
|
|
|
|
|
|
//func getCmd(ctlSock string, args []string) error {}
|
|
|
|
|
|
+func statusCmd(args []string) error {
|
|
|
+ flagset := flag.NewFlagSet(args[0], flag.ExitOnError)
|
|
|
+ outFormat := flagset.String("format", "plain", "Which format to use as output for this command (json, pretty, plain)")
|
|
|
+ flagset.Parse(args[1:])
|
|
|
+ resp, err := ctl.Get("http://unix/status")
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ defer resp.Body.Close()
|
|
|
+ respBytes, err := ioutil.ReadAll(resp.Body)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ respJSON := make(map[string]circolog.StatusResponse)
|
|
|
+ err = json.Unmarshal(respBytes, &respJSON)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ switch *outFormat {
|
|
|
+ case "json":
|
|
|
+ fmt.Printf("%s", string(respBytes))
|
|
|
+ case "pretty":
|
|
|
+ prettyJSON, err := json.MarshalIndent(respJSON, "", " ")
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ fmt.Printf("%s\n", prettyJSON)
|
|
|
+ case "plain":
|
|
|
+ fmt.Printf("Buffer Length: %d\n", respJSON["status"].Len)
|
|
|
+ fmt.Printf("Server Status: %s\n", respJSON["status"].Status())
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
func pauseCmd(args []string) error {
|
|
|
var dontChangeAgain time.Duration
|
|
|
flagset := flag.NewFlagSet(args[0], flag.ExitOnError)
|