diff --git a/containerinfo b/containerinfo index 1e86634..3e6ad17 100755 Binary files a/containerinfo and b/containerinfo differ diff --git a/containerinfo.go b/containerinfo.go index df0d83a..2d443ab 100644 --- a/containerinfo.go +++ b/containerinfo.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "net/http" "log" "fmt" @@ -10,7 +11,37 @@ import ( "github.com/joho/godotenv" ) +type Response struct { + Name string `json:"name"` + IPAddress string `json:"IPAddress"` + MACAddress string `json:"MacAddress"` + Memory string `json:"memory"` + CPUs string `json:"cpus"` + restartPolicy struct { + Name string `json:"Name"` + MaxRetry int `json:"MaximumRetryCount"` + } `json:"restartPolicy"` + Restarts int `json:"restarts"` + State struct { + Status string `json:"Status"` + Running bool `json:"Running"` + Paused bool `json:"Paused"` + Restarting bool `json:"Restarting"` + OOMKilled bool `json:"OOMKilled"` + Dead bool `json:"Dead"` + PID int `json:"Pid"` + ExitCode int `json:"ExitCode"` + Err string `json:"Error"` + StartedAt string `json:"StartedAt"` + FinishedAt string `json:"FinishedAt"` + } `json:"state"` + Created string `json:"created"` + Image string `json:"image"` +} + func main() { + // Clear the screen + fmt.Print("\033[2J") // Load environment variables from .env file err := godotenv.Load() if err != nil { @@ -35,13 +66,32 @@ func main() { } defer resp.Body.Close() + // Get the statuscode of the endpoint fmt.Println("Status code: ", resp.StatusCode) + // Read the contents of the body body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatal(err) } - fmt.Println(string(body)) + // Unmarshal the JSON into a Response struct + var r Response + err = json.Unmarshal(body, &r) + if err != nil { + log.Fatal(err) + } + // Print the response + fmt.Println("") + fmt.Println("Containername:", r.Name) + fmt.Println("MAX Memory:", r.Memory) + fmt.Println("CPU amount:", r.CPUs) + fmt.Println("Restarts:", r.Restarts) + fmt.Println("Status:", r.State.Status) + fmt.Println("PID:", r.State.PID) + fmt.Println("StartedAt:", r.State.StartedAt) + fmt.Println("FinishedAt:", r.State.FinishedAt) + fmt.Println("Created:", r.Created) + fmt.Println("") } diff --git a/containertime b/containertime index d8e1441..f063950 100755 Binary files a/containertime and b/containertime differ diff --git a/containertime.go b/containertime.go index 1548b0d..e9877f9 100644 --- a/containertime.go +++ b/containertime.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "net/http" "log" "fmt" @@ -10,7 +11,15 @@ import ( "github.com/joho/godotenv" ) +type Response struct { + Action string `json:"action"` + Completed string `json:"completed"` + ExpireDate string `json:"expireDate"` +} + func main() { + // Clear the screen + fmt.Print("\033[2J") // Load environment variables from .env file err := godotenv.Load() if err != nil { @@ -35,13 +44,24 @@ func main() { } defer resp.Body.Close() + // Get the statuscode of the endpoint fmt.Println("Status code: ", resp.StatusCode) + // Read the contents of the body body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatal(err) } - fmt.Println(string(body)) + // Unmarshal the JSON into a Response struct + var r Response + err = json.Unmarshal(body, &r) + if err != nil { + log.Fatal(err) + } + // Print the response + fmt.Println("") + fmt.Println("Container expire time: ", r.ExpireDate) + fmt.Println("") } diff --git a/hello b/hello new file mode 100755 index 0000000..2b34d8b Binary files /dev/null and b/hello differ diff --git a/hello.go b/hello.go index f5904a2..89d6657 100644 --- a/hello.go +++ b/hello.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "net/http" "log" "fmt" @@ -10,7 +11,13 @@ import ( "github.com/joho/godotenv" ) +type Response struct { + Message string `json:"message"` +} + func main() { + // Clear the screen + fmt.Print("\033[2J") // Load environment variables from .env file err := godotenv.Load() if err != nil { @@ -35,13 +42,25 @@ func main() { } defer resp.Body.Close() + // Get the statuscode of the endpoint fmt.Println("Status code: ", resp.StatusCode) + // Read the contents of the body body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatal(err) } - fmt.Println(string(body)) + // Unmarshal the JSON into a Response struct + var r Response + err = json.Unmarshal(body, &r) + if err != nil { + log.Fatal(err) + } + + // Print the response + fmt.Println("") + fmt.Println(r.Message) + fmt.Println("") } diff --git a/keystatus b/keystatus index 827c620..1fbf578 100755 Binary files a/keystatus and b/keystatus differ diff --git a/keystatus.go b/keystatus.go index 014ab7d..322ec8e 100644 --- a/keystatus.go +++ b/keystatus.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "net/http" "log" "fmt" @@ -10,7 +11,15 @@ import ( "github.com/joho/godotenv" ) +type Response struct { + KeyexpireString string `json:"keyexpireString"` + ExpireDate string `json:"expireDate"` + expireEpoc int `json:"expireEpoc"` +} + func main() { + // Clear the screen + fmt.Print("\033[2J") // Load environment variables from .env file err := godotenv.Load() if err != nil { @@ -35,13 +44,25 @@ func main() { } defer resp.Body.Close() + // Get the statuscode of the endpoint fmt.Println("Status code: ", resp.StatusCode) + // Read the contents of the body body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatal(err) } - fmt.Println(string(body)) + // Unmarshal the JSON into a Response struct + var r Response + err = json.Unmarshal(body, &r) + if err != nil { + log.Fatal(err) + } + // Print the response + fmt.Println("") + fmt.Println("Key expire fulldate: ", r.KeyexpireString) + fmt.Println("Key expire date: ", r.ExpireDate) + fmt.Println("") } \ No newline at end of file diff --git a/newkey b/newkey index 830b389..d47ad4b 100755 Binary files a/newkey and b/newkey differ diff --git a/newkey.go b/newkey.go index a39ed4c..3f7291d 100644 --- a/newkey.go +++ b/newkey.go @@ -1,6 +1,7 @@ package main import ( + "encoding/json" "net/http" "log" "fmt" @@ -10,7 +11,15 @@ import ( "github.com/joho/godotenv" ) +type Response struct { + Action string `json:"action"` + Completed string `json:"completed"` + NewAPIKey int `json:"newAPIKey"` +} + func main() { + // Clear the screen + fmt.Print("\033[2J") // Load environment variables from .env file err := godotenv.Load() if err != nil { @@ -35,13 +44,28 @@ func main() { } defer resp.Body.Close() + // Get the statuscode of the endpoint fmt.Println("Status code: ", resp.StatusCode) + // Read the contents of the body body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatal(err) } - fmt.Println(string(body)) + // Unmarshal the JSON into a Response struct + var r Response + err = json.Unmarshal(body, &r) + if err != nil { + log.Fatal(err) + } + + // Print the response + fmt.Println("") + fmt.Println("New API Key: ", r.NewAPIKey) + fmt.Println("") + + // Old printing methode, kept for archiving purposes + // fmt.Println(string(body)) }