Files
Foundry-Scrapping-API/internal/foundry/requests/post_requests.go
2026-04-08 18:19:20 +03:00

77 lines
1.8 KiB
Go

package requests
import (
"bytes"
"fmt"
"net/http"
"net/url"
)
func (conf *Config) PostAuthenticationData() (*http.Response, error) {
authData := url.Values{}
authData.Add("adminPassword", conf.Password)
authData.Add("action", "adminAuth")
req, err := http.NewRequest("POST", fmt.Sprintf("http://%s%s", conf.Host, AuthPath), bytes.NewBuffer([]byte(authData.Encode())))
if err != nil {
return nil, err
}
header := conf.GetRequestHeader()
header.Set("Content-Length", fmt.Sprintf("%d", len(authData.Encode())))
req.Header = header.Clone()
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
return resp, nil
}
func (conf *Config) PostLaunchWorld(world string) (*http.Response, error) {
launchData := url.Values{}
launchData.Add("world", world)
launchData.Add("action", "launchWorld")
req, err := http.NewRequest("POST", fmt.Sprintf("http://%s%s", conf.Host, SetupPath), bytes.NewBuffer([]byte(launchData.Encode())))
if err != nil {
return nil, err
}
header := conf.GetRequestHeader()
header.Set("Content-Length", fmt.Sprintf("%d", len(launchData.Encode())))
req.Header = header.Clone()
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
return resp, nil
}
func (conf *Config) PostReturnToSetup() (*http.Response, error) {
launchData := url.Values{}
launchData.Add("action", "shutdown")
req, err := http.NewRequest("POST", fmt.Sprintf("http://%s%s", conf.Host, JoinPath), bytes.NewBuffer([]byte(launchData.Encode())))
if err != nil {
return nil, err
}
header := conf.GetRequestHeader()
header.Set("Content-Length", fmt.Sprintf("%d", len(launchData.Encode())))
req.Header = header.Clone()
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return nil, err
}
return resp, nil
}