refactor api methods
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s

This commit is contained in:
2026-10-08 22:18:53 +02:00
parent ffa4786113
commit 85295deb22
7 changed files with 52 additions and 89 deletions
-59
View File
@@ -1,59 +0,0 @@
package helpers
import (
"log/slog"
"resty.dev/v3"
)
type Login struct {
Email string
Password string
}
type LoginResponse struct {
Token string
}
func GetToken(client *resty.Client) (token string) {
var login LoginResponse
_, err := client.R().
SetBody(Login{
Email: "thomas.peetz@thpeetz.de",
Password: "admin",
}).
SetHeader("Accept", "application/json").
SetResult(&login).
Post("http://127.0.0.1:8550/api/login")
if err != nil {
slog.Info("Health", "error", err.Error())
}
slog.Info("health", "token", login.Token)
return login.Token
}
func GetJSON(client *resty.Client, token string, url string, v any) {
_, err := client.R().
SetAuthToken(token).
SetHeader("Accept", "application/json").
SetResult(v).
Get(url)
if err != nil {
slog.Info(url, "error", err.Error())
}
}
func PostJSON(client *resty.Client, url string, v any) {
_, err := client.R().
SetBody(Login{
Email: "thomas.peetz@thpeetz.de",
Password: "admin",
}).
SetHeader("Accept", "application/json").
SetResult(v).
Post(url)
if err != nil {
slog.Info("Health", "error", err.Error())
}
slog.Info(url, "token", v)
}