This commit introduces support for running Bedrock servers and sets up context folders for managing server versions and working directories. It includes updates to the .gitignore file, configuration options, and command-line execution logic.
61 lines
2.0 KiB
Go
61 lines
2.0 KiB
Go
package config
|
|
|
|
import "context"
|
|
|
|
type Config struct {
|
|
ServerSoftware ServerSoftware `json:"software"` // Server software to run
|
|
Version string `json:"version"` // Server version to run, default is latest
|
|
PathRoot string `json:"root"` // Root to storage server and other
|
|
VersionFolder string `json:"version_folder"` // Folder to storage all versions from platform
|
|
Cwd string `json:"cwd"` // folder to exec server
|
|
Workdir string `json:"workdir"` // folder to storage files, required is same partition of VersionFolder
|
|
}
|
|
|
|
type ConfigContext string
|
|
|
|
const (
|
|
ContextName = ConfigContext("bdsConfig")
|
|
ContextNameVersionFolder = ConfigContext("versionFolder")
|
|
ContextNameCwd = ConfigContext("cwd")
|
|
ContextNameUpper = ConfigContext("upper")
|
|
ContextNameWorkdir = ConfigContext("workdir")
|
|
)
|
|
|
|
func SetFolders(ctx context.Context, versionFolder, cwd, upper, workdir string) context.Context {
|
|
// versionFolder, cwd, upper, workdir string
|
|
ctx = context.WithValue(ctx, ContextNameVersionFolder, versionFolder)
|
|
ctx = context.WithValue(ctx, ContextNameCwd, cwd)
|
|
ctx = context.WithValue(ctx, ContextNameUpper, upper)
|
|
return context.WithValue(ctx, ContextNameWorkdir, workdir)
|
|
}
|
|
|
|
func GetFolders(ctx context.Context) (versionFolder, cwd, upper, workdir string) {
|
|
if v, ok := ctx.Value(ContextNameVersionFolder).(string); ok && v != "" {
|
|
versionFolder = v
|
|
}
|
|
if v, ok := ctx.Value(ContextNameCwd).(string); ok && v != "" {
|
|
cwd = v
|
|
}
|
|
if v, ok := ctx.Value(ContextNameUpper).(string); ok && v != "" {
|
|
upper = v
|
|
}
|
|
if v, ok := ctx.Value(ContextNameWorkdir).(string); ok && v != "" {
|
|
workdir = v
|
|
}
|
|
return
|
|
}
|
|
|
|
func SetConfigToContext(ctx context.Context, config *Config) context.Context {
|
|
return context.WithValue(ctx, ContextName, config)
|
|
}
|
|
|
|
func GetConfigFromContext(ctx context.Context) *Config {
|
|
switch v := ctx.Value(ContextName).(type) {
|
|
case *Config:
|
|
return v
|
|
case Config:
|
|
return &v
|
|
}
|
|
return nil
|
|
}
|