Files
Foundry-Scrapping-API/internal/foundry/requests/get_requests.go

65 lines
1.4 KiB
Go

package requests
import (
"encoding/json"
"fmt"
"net/http"
"gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/models"
)
func (conf *Config) GetSessionId() error {
getResp, err := http.Get(fmt.Sprintf("http://%s%s", conf.Host, AuthPath))
if err != nil {
return err
}
_, err = conf.SetSessionTokenFromHeader(getResp.Header)
return err
}
func (conf *Config) GetSessionToken() (bool, error) {
req, err := http.NewRequest("GET", fmt.Sprintf("http://%s%s", conf.Host, AuthPath), nil)
if err != nil {
return false, err
}
header := http.Header{}
header.Set("Cookie", fmt.Sprintf("session=%s", conf.SessionID))
header.Set("Connection", "keep-alive")
header.Set("Host", conf.Host)
header.Set("Origin", fmt.Sprintf("http://%s", conf.Host))
header.Set("Referer", fmt.Sprintf("http://%s%s", conf.Host, AuthPath))
req.Header = header
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return false, err
}
return conf.SetSessionTokenFromHeader(resp.Header)
}
func (conf *Config) GetStatus() (*models.Status, error) {
getResp, err := http.Get(fmt.Sprintf("http://%s/api/status", conf.Host))
if err != nil {
return nil, err
}
defer getResp.Body.Close()
statusByte := make([]byte, 64)
_, err = getResp.Body.Read(statusByte)
if err != nil {
return nil, err
}
var status models.Status
err = json.Unmarshal(statusByte, &status)
if err != nil {
return nil, err
}
return &status, nil
}