removing hardcoded url

This commit is contained in:
Voronsky
2024-06-07 00:07:47 -04:00
parent 1a7337b489
commit 3bab899bf1
2 changed files with 6 additions and 3 deletions

View File

@@ -3,6 +3,7 @@ package pterogo
import ( import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt"
"io" "io"
"log/slog" "log/slog"
"net/http" "net/http"
@@ -34,11 +35,12 @@ type Server struct {
// Taken from the Pterodactyl API page. This will return an error if it fails at any point // Taken from the Pterodactyl API page. This will return an error if it fails at any point
// Otherwise, it will return a map of unique servers , based off their identifier // Otherwise, it will return a map of unique servers , based off their identifier
// A Bearer Auth token is required // A Bearer Auth token is required
func listServers(auth_token string) (map[string]Server, error) { func listServers(auth_token string, url string) (map[string]Server, error) {
client := &http.Client{} client := &http.Client{}
logger := slog.New(slog.NewJSONHandler(os.Stdout, nil)) logger := slog.New(slog.NewJSONHandler(os.Stdout, nil))
//Build GET Request //Build GET Request
req, err := http.NewRequest("GET", "https://panel.12egc.com/api/client", nil) route := fmt.Sprintf("%s/api/client", url)
req, err := http.NewRequest("GET", route, nil)
if err != nil { if err != nil {
slog.Error("Failed to make a new request", "Error", err) slog.Error("Failed to make a new request", "Error", err)
return nil, err return nil, err

View File

@@ -17,7 +17,8 @@ func TestListServers(t *testing.T) {
log.Fatalf(`No env file found`) log.Fatalf(`No env file found`)
} }
bearer_auth_token := os.Getenv("PTERO_API_KEY") bearer_auth_token := os.Getenv("PTERO_API_KEY")
s, err := listServers(bearer_auth_token) base_url := os.Getenv("BASE_URL")
s, err := listServers(bearer_auth_token, base_url)
if err != nil { if err != nil {
log.Fatalf(`ListServers() = %q, %v, want nil, error`, s, err) log.Fatalf(`ListServers() = %q, %v, want nil, error`, s, err)
} }