add db connection, refactor code, add db migration files
This commit is contained in:
59
internal/foundry/requests/config.go
Normal file
59
internal/foundry/requests/config.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package requests
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrorSidWrongFormat = errors.New("Session id wrong format")
|
||||
ErrorSidNotFound = errors.New("Session id didn't find in response header")
|
||||
)
|
||||
|
||||
const (
|
||||
AuthPath = "/auth"
|
||||
LicensePath = "/license"
|
||||
JoinPath = "/join"
|
||||
PlayersPath = "/players"
|
||||
SetupPath = "/setup"
|
||||
UpdatePath = "/update"
|
||||
|
||||
SocketPath = "/socket.io"
|
||||
)
|
||||
|
||||
var WsTypeData = map[string]string{
|
||||
AuthPath: "getAuthData",
|
||||
LicensePath: "getAuthData",
|
||||
JoinPath: "getJoinData",
|
||||
PlayersPath: "getPlayersData",
|
||||
SetupPath: "getSetupData",
|
||||
UpdatePath: "getUpdateData",
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Host string
|
||||
Password string
|
||||
SessionID string
|
||||
}
|
||||
|
||||
func (conf *Config) SetSessionTokenFromHeader(resp http.Header) (bool, error) {
|
||||
setCookieHeader := resp.Get("Set-Cookie")
|
||||
if setCookieHeader == "" {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
for value := range strings.SplitSeq(setCookieHeader, ";") {
|
||||
if strings.Contains(value, "session") {
|
||||
sessionCookie := strings.Split(value, "=")
|
||||
if len(sessionCookie) != 2 {
|
||||
return false, ErrorSidWrongFormat
|
||||
}
|
||||
|
||||
conf.SessionID = sessionCookie[1]
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
Reference in New Issue
Block a user