tbh i forgot
This commit is contained in:
@@ -81,6 +81,14 @@ func VerifyLogRequest(request *http.Request) (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
// Writes a configuration file populated with defaults
|
||||
func createConfigWithDefaults(path string) error {
|
||||
config, _ := defaultConfig.ReadFile("default_config.json")
|
||||
err := os.WriteFile(path, config, 0644)
|
||||
return err
|
||||
}
|
||||
|
||||
// Helper for configReader() that does the actual reading
|
||||
//
|
||||
// Also validates the populated fields
|
||||
@@ -88,7 +96,7 @@ func configReaderParse(filePath string, configOptionStorage *globals.Config) err
|
||||
jsonData, err := os.ReadFile(filePath)
|
||||
if err == nil {
|
||||
if err = json.Unmarshal(jsonData, &configOptionStorage); err != nil {
|
||||
LogLine("Configuration file is invalid JSON", 5)
|
||||
LogLine("Configuration file is invalid JSON", 4)
|
||||
return errors.New("Config file could not be read")
|
||||
}
|
||||
} else {
|
||||
@@ -112,17 +120,10 @@ func configReaderParse(filePath string, configOptionStorage *globals.Config) err
|
||||
return nil
|
||||
}
|
||||
|
||||
// tbd what exactly happens here
|
||||
func configValidator(config globals.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func configPopulator(config globals.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Creates the configuration file populated with defaults
|
||||
func createConfigWithDefaults() {
|
||||
// populates the appconfig with default values
|
||||
func configPopulator(configOptionStorage *globals.Config) {
|
||||
jsonData, _ := defaultConfig.ReadFile("default_config.json")
|
||||
json.Unmarshal(jsonData, &configOptionStorage)
|
||||
}
|
||||
|
||||
// Reads config file and stores the options in configOptionStorage
|
||||
@@ -132,29 +133,39 @@ func createConfigWithDefaults() {
|
||||
// %LOCALAPPDATA%\servtex\configFileName
|
||||
// ~/.config/servtex/configFileName
|
||||
func ConfigReader(configFileName string, configOptionStorage *globals.Config) error {
|
||||
var defaultPath string
|
||||
|
||||
// populate default config
|
||||
configPopulator(configOptionStorage)
|
||||
configRead := false
|
||||
|
||||
// read config file from disk
|
||||
exePath, err := os.Executable()
|
||||
if err == nil {
|
||||
path := filepath.Join(filepath.Dir(exePath), configFileName)
|
||||
err = configReaderParse(path, configOptionStorage)
|
||||
if err == nil { return nil }
|
||||
defaultPath = filepath.Join(filepath.Dir(exePath), configFileName)
|
||||
err = configReaderParse(defaultPath, configOptionStorage)
|
||||
if err == nil { configRead = true }
|
||||
}
|
||||
|
||||
localappdata := os.Getenv("LOCALAPPDATA")
|
||||
if localappdata != "" {
|
||||
if !configRead && localappdata != "" {
|
||||
path := filepath.Join(localappdata, "servtex", configFileName)
|
||||
err = configReaderParse(path, configOptionStorage)
|
||||
if err == nil { return nil }
|
||||
}
|
||||
|
||||
if !configRead {
|
||||
path := filepath.Join("~", ".config", "servtex", configFileName)
|
||||
err = configReaderParse(path, configOptionStorage)
|
||||
if err != nil { return err }
|
||||
|
||||
err = configPopulator(*configOptionStorage)
|
||||
if err != nil { return err }
|
||||
|
||||
err = configValidator(*configOptionStorage)
|
||||
if err != nil { return err }
|
||||
// create default config file for user to edit
|
||||
if err != nil && defaultPath != "" {
|
||||
LogLine(fmt.Sprintf("Configuration file does not exist. Creating with defaults at %s", defaultPath), 4)
|
||||
err = createConfigWithDefaults(defaultPath)
|
||||
if err != nil {
|
||||
LogLine("Configuration file could not be created", 4)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -286,18 +297,6 @@ func LatexCompile() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Returns intersection of two slices
|
||||
func sliceIntersection[T comparable](left []T, right []T) (intersection []T) {
|
||||
for _, leftItem := range left {
|
||||
for _, rightItem := range right {
|
||||
if leftItem == rightItem {
|
||||
intersection = append(intersection, leftItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
return intersection
|
||||
}
|
||||
|
||||
// Checks whether the proxy is trusted. Returns trusted status and the proxy.
|
||||
//
|
||||
// If X-Forwarded-For chain is passed, only the last in chain will be considered
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"timezone": "Europe/Berlin"
|
||||
"timezone": "Europe/Berlin",
|
||||
"logFilePath": "./servtex.log",
|
||||
"logLevel": "warning",
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"timezone": "Europe/Berlin"
|
||||
"timezone": "Europe/Berlin",
|
||||
"logFilePath": "./servtex.log",
|
||||
"logLevel": "debug",
|
||||
|
||||
|
||||
@@ -88,7 +88,6 @@ func SSEventHandler(writer http.ResponseWriter, request *http.Request) {
|
||||
for range time.Tick(time.Second) {
|
||||
select {
|
||||
case <-request.Context().Done():
|
||||
backend.LogLine("SSE Context Done", 1)
|
||||
return
|
||||
default:
|
||||
if lastExecution == globals.LatexExec.TimestampRFC {
|
||||
|
||||
@@ -30,7 +30,6 @@ type Config struct {
|
||||
}
|
||||
var AppConfig Config
|
||||
|
||||
|
||||
type LatexExecution struct {
|
||||
ExecutionLock sync.Mutex
|
||||
ExecutionState string
|
||||
|
||||
12
main.go
12
main.go
@@ -72,14 +72,12 @@ func main() {
|
||||
fmt.Print("\r")
|
||||
|
||||
// shutdown
|
||||
context, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||
// known issue: sse blocks shutdown if a client is still connected
|
||||
context, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
if err = server.Shutdown(context); err != nil {
|
||||
backend.LogLine("Graceful Shutdown failed", 4)
|
||||
}
|
||||
if err = serverSecure.Shutdown(context); err != nil {
|
||||
backend.LogLine("Graceful Shutdown failed", 4)
|
||||
}
|
||||
server.Shutdown(context)
|
||||
serverSecure.Shutdown(context)
|
||||
|
||||
backend.LogLine("Stopped", 2)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user