Documentation
¶
Index ¶
- Constants
- func AuthMiddleware(cognito service.CognitoService) gin.HandlerFunc
- func CORSMiddleware() gin.HandlerFunc
- func CreateFileJob(clientset kubernetes.Interface, payload *FilePayload, ...) (*string, error)
- func LogrusMiddleware(logger *logrus.Logger) gin.HandlerFunc
- func MakePvc(name string, deploymentName string, discordId string) *corev1.PersistentVolumeClaim
- func MakeVolumeMounts() []corev1.VolumeMount
- func MakeVolumes(pvcName string) []corev1.Volume
- func UpdateServerArgs(kubeService service.KubernetesService, deploymentName string, ...) error
- type Client
- type Config
- type CreateServerHandler
- type CreateServerRequest
- type CreateServerResponse
- func CreateDedicatedServerDeployment(config *Config, kubeService service.KubernetesService, ...) (*CreateServerResponse, error)
- func PatchServerDeployment(config *Config, kubeService service.KubernetesService, ...) (response *CreateServerResponse, err error)
- func UpdateServerDetails(ctx context.Context, cognito service.CognitoService, res *CreateServerResponse, ...) (*CreateServerResponse, error)
- type DeleteServerHandler
- type FilePayload
- type GetServerHandler
- type GetServerResponse
- type InstallFileHandler
- type Message
- type Modifier
- type PatchServerHandler
- type ScaleServerHandler
- type ScaleServerRequest
- type WebSocketManager
Constants ¶
const ( // Difficulties & Death penalties VERY_EASY = "veryeasy" EASY = "easy" HARD = "hard" // only valid for portals VERY_HARD = "veryhard" // combat only & only valid for portals CASUAL = "casual" // only valid for portals HARDCORE = "hardcore" // deathpenalty only // Resources & Raids NONE = "none" // Raid only MUCH_LESS = "muchless" LESS = "less" MORE = "more" MUCHMORE = "muchmore" MOST = "most" // resource only // Server states RUNNING = "running" TERMINATED = "terminated" )
Variables ¶
This section is empty.
Functions ¶
func AuthMiddleware ¶
func AuthMiddleware(cognito service.CognitoService) gin.HandlerFunc
AuthMiddleware is the custom authentication middleware that checks the Authorization header to ensure a given discord id belong to a given refresh token.
func CORSMiddleware ¶
func CORSMiddleware() gin.HandlerFunc
func CreateFileJob ¶
func CreateFileJob(clientset kubernetes.Interface, payload *FilePayload, user *service.CognitoUser) (*string, error)
CreateFileJob Creates a new kubernetes job which attaches the valheim server PVC, downloads mods from S3, and installs mods onto the PVC before restarting the Valheim server.
func LogrusMiddleware ¶
func LogrusMiddleware(logger *logrus.Logger) gin.HandlerFunc
func MakePvc ¶
func MakePvc(name string, deploymentName string, discordId string) *corev1.PersistentVolumeClaim
MakePvc Returns the PVC object from the Kubernetes API for creating a new volume.
func MakeVolumeMounts ¶
func MakeVolumeMounts() []corev1.VolumeMount
MakeVolumeMounts Creates the PVC volume mount locations for the deployment pod. These volume mounts are the only places files can be installed that will persist outside the life of the server.
func MakeVolumes ¶
MakeVolumes creates the volumes that will be mounted for both the server deployment and any file installation jobs.
func UpdateServerArgs ¶
func UpdateServerArgs(kubeService service.KubernetesService, deploymentName string, server *CreateServerResponse) error
UpdateServerArgs Update's a deployment's args to reflect what is in Cognito. This avoids complex argument merging logic by simply having the frontend update cognito with the new server args.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client represents a WebSocket client connection
type Config ¶
type Config struct { Name string `json:"name"` World string `json:"world"` CpuRequest int `json:"cpu_requests"` MemoryRequest int `json:"memory_requests"` Port string `json:"port"` Password string `json:"password"` EnableCrossplay bool `json:"enable_crossplay"` Public bool `json:"public"` InstanceId string `json:"instance_id"` Modifiers []Modifier `json:"modifiers"` SaveIntervalSeconds int `json:"save_interval_seconds"` BackupCount int `json:"backup_count"` InitialBackupSeconds int `json:"initial_backup_seconds"` BackupIntervalSeconds int `json:"backup_interval_seconds"` }
func MakeConfigWithDefaults ¶
func MakeConfigWithDefaults(options *CreateServerRequest) *Config
MakeConfigWithDefaults creates a new ServerConfig with default values that can be selectively overridden by provided options
func (*Config) ToStringArgs ¶
type CreateServerHandler ¶
type CreateServerHandler struct{}
func (*CreateServerHandler) HandleRequest ¶
func (h *CreateServerHandler) HandleRequest(c *gin.Context, kubeService service.KubernetesService, cognito service.CognitoService, ctx context.Context)
HandleRequest Handles the /api/v1/server/create to create a new Valheim dedicated server container. This route is responsible for creating the initial deployment and pvc which in turn creates the replicaset and pod for the server. Future server management like mod installation, user termination requests, custom world uploads, etc... will use the /api/v1/server/scale route to scale the replicas to 0-1 without removing the deployment or PVC.
type CreateServerRequest ¶
type CreateServerRequest struct { Name *string `json:"name"` World *string `json:"world"` MemoryRequest *int `json:"memory_request"` CpuRequest *int `json:"cpu_request"` Password *string `json:"password"` Port *string `json:"port"` EnableCrossplay *bool `json:"enable_crossplay,omitempty"` Public *bool `json:"public,omitempty"` Modifiers []Modifier `json:"modifiers,omitempty"` SaveIntervalSeconds *int `json:"save_interval_seconds,omitempty"` BackupCount *int `json:"backup_count,omitempty"` InitialBackupSeconds *int `json:"initial_backup_seconds,omitempty"` BackupIntervalSeconds *int `json:"backup_interval_seconds,omitempty"` }
func (*CreateServerRequest) Validate ¶
func (c *CreateServerRequest) Validate() error
type CreateServerResponse ¶
type CreateServerResponse struct { ServerIp string `json:"server_ip"` ServerPort int `json:"server_port"` ServerMemory int `json:"server_memory"` ServerCpu int `json:"server_cpu"` CpuLimit int `json:"cpu_limit"` MemoryLimit int `json:"memory_limit"` WorldDetails Config `json:"world_details"` PvcName string `json:"mod_pvc_name"` DeploymentName string `json:"deployment_name"` State string `json:"state"` }
func CreateDedicatedServerDeployment ¶
func CreateDedicatedServerDeployment(config *Config, kubeService service.KubernetesService, user *service.CognitoUser) (*CreateServerResponse, error)
CreateDedicatedServerDeployment Creates the valheim dedicated server deployment and pvc given the server configuration.
func PatchServerDeployment ¶
func PatchServerDeployment(config *Config, kubeService service.KubernetesService, user *service.CognitoUser) (response *CreateServerResponse, err error)
PatchServerDeployment Updates a server deployment with new container args.
func UpdateServerDetails ¶
func UpdateServerDetails(ctx context.Context, cognito service.CognitoService, res *CreateServerResponse, user *service.CognitoUser, state string) (*CreateServerResponse, error)
UpdateServerDetails Updates the custom:server_details field in Cognito with the information from the scaled server.
type DeleteServerHandler ¶
type DeleteServerHandler struct{}
func (*DeleteServerHandler) HandleRequest ¶
func (d *DeleteServerHandler) HandleRequest(c *gin.Context, kubeService service.KubernetesService, cognito service.CognitoService, ctx context.Context)
type FilePayload ¶
type FilePayload struct { Prefix *string `json:"prefix"` Destination string `json:"destination"` IsArchive bool `json:"is_archive"` Operation string `json:"operation"` }
func (*FilePayload) Validate ¶
func (f *FilePayload) Validate() error
Validate Validates that the payload provide is not malformed or missing information.
type GetServerHandler ¶
type GetServerHandler struct{}
func (*GetServerHandler) HandleRequest ¶
func (g *GetServerHandler) HandleRequest(c *gin.Context, cognito service.CognitoService, ctx context.Context)
type GetServerResponse ¶
type GetServerResponse struct { Servers []CreateServerResponse `json:"servers"` CpuLimit int `json:"cpu_limit"` MemoryLimit int `json:"memory_limit"` }
type InstallFileHandler ¶
type InstallFileHandler struct{}
func (*InstallFileHandler) HandleRequest ¶
func (h *InstallFileHandler) HandleRequest(c *gin.Context, kubeService service.KubernetesService)
type Message ¶
type Message struct { Type string `json:"type"` Content interface{} `json:"content"` DiscordId string `json:"discord_id"` }
Message represents the structure of messages being passed
type PatchServerHandler ¶
type PatchServerHandler struct{}
func (*PatchServerHandler) HandleRequest ¶
func (p *PatchServerHandler) HandleRequest(c *gin.Context, kubeService service.KubernetesService, cognito service.CognitoService, ctx context.Context)
HandleRequest Much of this logic overlaps with the /create endpoint. It uses the same request body, validation logic, and method structure. The primary difference is in how it patches the container run args for a deployment rather than creating a new one.
type ScaleServerHandler ¶
type ScaleServerHandler struct{}
func (*ScaleServerHandler) HandleRequest ¶
func (h *ScaleServerHandler) HandleRequest(c *gin.Context, kubeService service.KubernetesService, cognito service.CognitoService, ctx context.Context)
type ScaleServerRequest ¶
type ScaleServerRequest struct {
Replicas *int32 `json:"replicas"`
}
type WebSocketManager ¶
type WebSocketManager struct { Channel *amqp.Channel Connection *amqp.Connection // contains filtered or unexported fields }
WebSocketManager handles multiple WebSocket connections
func NewRouter ¶
func NewRouter(ctx context.Context, kubeService service.KubernetesService, cognitoService service.CognitoService) (*gin.Engine, *WebSocketManager)
NewRouter Create a new gin router and instantiates the routes and route handlers for the entire API.
func NewWebSocketManager ¶
func NewWebSocketManager() (*WebSocketManager, error)
NewWebSocketManager creates a new WebSocket manager
func (*WebSocketManager) HandleWebSocket ¶
func (w *WebSocketManager) HandleWebSocket(c *gin.Context)
func (*WebSocketManager) Run ¶
func (w *WebSocketManager) Run()
Run Listens to go routine channels for websocket events when clients connect, disconnect, or broadcast a message. This function keeps track of client state like who is connected and disconnected