2023-01-10 09:57:26 -05:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2023-01-11 03:53:29 -05:00
|
|
|
"encoding/json"
|
2023-01-10 09:57:26 -05:00
|
|
|
"net/http"
|
|
|
|
"log"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"io/ioutil"
|
|
|
|
|
|
|
|
"github.com/joho/godotenv"
|
|
|
|
)
|
|
|
|
|
2023-01-11 03:53:29 -05:00
|
|
|
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"`
|
|
|
|
}
|
|
|
|
|
2023-01-10 09:57:26 -05:00
|
|
|
func main() {
|
2023-01-11 03:53:29 -05:00
|
|
|
// Clear the screen
|
|
|
|
fmt.Print("\033[2J")
|
2023-01-10 09:57:26 -05:00
|
|
|
// Load environment variables from .env file
|
|
|
|
err := godotenv.Load()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Error loading .env file")
|
|
|
|
}
|
|
|
|
|
|
|
|
token := os.Getenv("TOKEN")
|
|
|
|
|
|
|
|
// Make an HTTP request to api.discord-linux.com
|
|
|
|
req, err := http.NewRequest("GET", "https://api.discord-linux.com/info", nil)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
req.Header.Set("Accept", "application/json")
|
|
|
|
req.Header.Add("Content-Type", "Application/json")
|
|
|
|
req.Header.Add("x-discord-linux-auth", token)
|
|
|
|
|
|
|
|
client := http.Client{}
|
|
|
|
resp, err := client.Do(req)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
defer resp.Body.Close()
|
|
|
|
|
2023-01-11 03:53:29 -05:00
|
|
|
// Get the statuscode of the endpoint
|
2023-01-10 09:57:26 -05:00
|
|
|
fmt.Println("Status code: ", resp.StatusCode)
|
|
|
|
|
2023-01-11 03:53:29 -05:00
|
|
|
// Read the contents of the body
|
2023-01-10 09:57:26 -05:00
|
|
|
body, err := ioutil.ReadAll(resp.Body)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2023-01-11 03:53:29 -05:00
|
|
|
// Unmarshal the JSON into a Response struct
|
|
|
|
var r Response
|
|
|
|
err = json.Unmarshal(body, &r)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
2023-01-10 09:57:26 -05:00
|
|
|
|
2023-01-11 03:53:29 -05:00
|
|
|
// 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("")
|
2023-01-10 09:57:26 -05:00
|
|
|
}
|