refactor foundry lib structure; add transport classes for db,http,websocket; add action interface instead of multiple function that accepts action classes; add changing foundry status on websocket responses
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
package requests
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
json_model "gitea.local.lab/Lbenedar/foundry_helper_service/internal/foundry/models/json"
|
||||
)
|
||||
|
||||
func (conf *Config) GetSessionId() error {
|
||||
func (conf *FoundryHttpRequest) GetSessionId() error {
|
||||
getResp, err := http.Get(fmt.Sprintf("http://%s%s", conf.Host, AuthPath))
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -18,7 +20,7 @@ func (conf *Config) GetSessionId() error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (conf *Config) GetSessionToken() (bool, error) {
|
||||
func (conf *FoundryHttpRequest) GetSessionToken() (bool, error) {
|
||||
req, err := http.NewRequest("GET", fmt.Sprintf("http://%s%s", conf.Host, AuthPath), nil)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -42,21 +44,21 @@ func (conf *Config) GetSessionToken() (bool, error) {
|
||||
return conf.SetSessionTokenFromHeader(resp.Header)
|
||||
}
|
||||
|
||||
func (conf *Config) GetStatus() (*json_model.Status, error) {
|
||||
func (conf *FoundryHttpRequest) GetStatus() (*json_model.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 {
|
||||
statusByte := bytes.Buffer{}
|
||||
_, err = io.Copy(&statusByte, getResp.Body)
|
||||
if err != nil && err != io.EOF {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var status json_model.Status
|
||||
err = json.Unmarshal(statusByte, &status)
|
||||
err = json.Unmarshal(statusByte.Bytes(), &status)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user