This commit is contained in:
@@ -115,18 +115,20 @@ var Registry map[string]any
|
||||
|
||||
func GetToken(client *resty.Client, server config.Server) (token string) {
|
||||
var login LoginResponse
|
||||
|
||||
_, err := client.R().
|
||||
SetBody(Login{
|
||||
Email: server.Username,
|
||||
Password: server.Password,
|
||||
}).
|
||||
SetHeader("Accept", "application/json").
|
||||
SetResult(&login).
|
||||
Post(fmt.Sprintf("%s/api/login", server.Url))
|
||||
if err != nil {
|
||||
slog.Info("Health", "error", err.Error())
|
||||
body := Login{
|
||||
Email: server.Username,
|
||||
Password: server.Password,
|
||||
}
|
||||
PostJSON(client, server, "", "api", "login", body, &login)
|
||||
|
||||
// _, err := client.R().
|
||||
// SetBody(body).
|
||||
// SetHeader("Accept", "application/json").
|
||||
// SetResult(&login).
|
||||
// Post(fmt.Sprintf("%s/api/login", server.Url))
|
||||
// if err != nil {
|
||||
// slog.Info("Health", "error", err.Error())
|
||||
// }
|
||||
if config.Verbose > 2 {
|
||||
slog.Info("login", "token", login.Token)
|
||||
}
|
||||
@@ -134,14 +136,12 @@ func GetToken(client *resty.Client, server config.Server) (token string) {
|
||||
}
|
||||
|
||||
func GetData(server config.Server, apiVersion string) (data *ExportData, err error) {
|
||||
var login LoginResponse
|
||||
|
||||
client := resty.New()
|
||||
client.SetLoggerWarnLevel(true)
|
||||
PostJSON(client, server, "api/login", &login)
|
||||
token := GetToken(client, server)
|
||||
|
||||
for path, value := range Registry {
|
||||
GetJSON(client, login.Token, server, path, value)
|
||||
GetJSON(client, token, server, path, value)
|
||||
}
|
||||
export := ExportData{
|
||||
Sport: Sports,
|
||||
@@ -205,11 +205,19 @@ func GetJSON(client *resty.Client, token string, server config.Server, path stri
|
||||
if config.Verbose > 2 {
|
||||
slog.Info("GetJSON", "url", url)
|
||||
}
|
||||
_, err := client.R().
|
||||
SetAuthToken(token).
|
||||
SetHeader("Accept", "application/json").
|
||||
SetResult(v).
|
||||
Get(url)
|
||||
var err error
|
||||
if token == "" {
|
||||
_, err = client.R().
|
||||
SetHeader("Accept", "application/json").
|
||||
SetResult(v).
|
||||
Get(url)
|
||||
} else {
|
||||
_, err = client.R().
|
||||
SetAuthToken(token).
|
||||
SetHeader("Accept", "application/json").
|
||||
SetResult(v).
|
||||
Get(url)
|
||||
}
|
||||
if err != nil {
|
||||
slog.Info(url, "error", err.Error())
|
||||
}
|
||||
@@ -218,16 +226,14 @@ func GetJSON(client *resty.Client, token string, server config.Server, path stri
|
||||
}
|
||||
}
|
||||
|
||||
func PostJSON(client *resty.Client, server config.Server, path string, v any) {
|
||||
url := fmt.Sprintf("%s/%s", server.Url, path)
|
||||
func PostJSON(client *resty.Client, server config.Server, token string, apiVersion string, path string, body any, v any) {
|
||||
url := fmt.Sprintf("%s/%s/%s", server.Url, apiVersion, path)
|
||||
if config.Verbose > 2 {
|
||||
slog.Info("PostJSON", "url", url)
|
||||
}
|
||||
_, err := client.R().
|
||||
SetBody(Login{
|
||||
Email: server.Username,
|
||||
Password: server.Password,
|
||||
}).
|
||||
response, err := client.R().
|
||||
SetAuthToken(token).
|
||||
SetBody(body).
|
||||
SetHeader("Accept", "application/json").
|
||||
SetResult(v).
|
||||
Post(url)
|
||||
@@ -235,7 +241,7 @@ func PostJSON(client *resty.Client, server config.Server, path string, v any) {
|
||||
slog.Info("PostJSON", "error", err.Error())
|
||||
}
|
||||
if config.Verbose > 2 {
|
||||
slog.Info(url, "token", v)
|
||||
slog.Info("PostJSON", "response", response)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user