Changed the source to use a more pretty output. Updated the prebuilds to reflect the changes

This commit is contained in:
ultimateplayer1999 2023-01-11 09:53:29 +01:00
parent 84c7831e7c
commit 956c07e85c
Signed by: ultimateplayer1999
GPG Key ID: 690D4E43F8B51E51
10 changed files with 139 additions and 5 deletions

Binary file not shown.

View File

@ -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("")
}

Binary file not shown.

View File

@ -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("")
}

BIN
hello Executable file

Binary file not shown.

View File

@ -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("")
}

BIN
keystatus

Binary file not shown.

View File

@ -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("")
}

BIN
newkey

Binary file not shown.

View File

@ -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))
}