tbh i forgot
This commit is contained in:
@@ -81,6 +81,14 @@ func VerifyLogRequest(request *http.Request) (err error) {
|
|||||||
return nil
|
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
|
// Helper for configReader() that does the actual reading
|
||||||
//
|
//
|
||||||
// Also validates the populated fields
|
// Also validates the populated fields
|
||||||
@@ -88,7 +96,7 @@ func configReaderParse(filePath string, configOptionStorage *globals.Config) err
|
|||||||
jsonData, err := os.ReadFile(filePath)
|
jsonData, err := os.ReadFile(filePath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if err = json.Unmarshal(jsonData, &configOptionStorage); 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")
|
return errors.New("Config file could not be read")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -112,17 +120,10 @@ func configReaderParse(filePath string, configOptionStorage *globals.Config) err
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// tbd what exactly happens here
|
// populates the appconfig with default values
|
||||||
func configValidator(config globals.Config) error {
|
func configPopulator(configOptionStorage *globals.Config) {
|
||||||
return nil
|
jsonData, _ := defaultConfig.ReadFile("default_config.json")
|
||||||
}
|
json.Unmarshal(jsonData, &configOptionStorage)
|
||||||
|
|
||||||
func configPopulator(config globals.Config) error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Creates the configuration file populated with defaults
|
|
||||||
func createConfigWithDefaults() {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reads config file and stores the options in configOptionStorage
|
// Reads config file and stores the options in configOptionStorage
|
||||||
@@ -132,29 +133,39 @@ func createConfigWithDefaults() {
|
|||||||
// %LOCALAPPDATA%\servtex\configFileName
|
// %LOCALAPPDATA%\servtex\configFileName
|
||||||
// ~/.config/servtex/configFileName
|
// ~/.config/servtex/configFileName
|
||||||
func ConfigReader(configFileName string, configOptionStorage *globals.Config) error {
|
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()
|
exePath, err := os.Executable()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
path := filepath.Join(filepath.Dir(exePath), configFileName)
|
defaultPath = filepath.Join(filepath.Dir(exePath), configFileName)
|
||||||
err = configReaderParse(path, configOptionStorage)
|
err = configReaderParse(defaultPath, configOptionStorage)
|
||||||
if err == nil { return nil }
|
if err == nil { configRead = true }
|
||||||
}
|
}
|
||||||
|
|
||||||
localappdata := os.Getenv("LOCALAPPDATA")
|
localappdata := os.Getenv("LOCALAPPDATA")
|
||||||
if localappdata != "" {
|
if !configRead && localappdata != "" {
|
||||||
path := filepath.Join(localappdata, "servtex", configFileName)
|
path := filepath.Join(localappdata, "servtex", configFileName)
|
||||||
err = configReaderParse(path, configOptionStorage)
|
err = configReaderParse(path, configOptionStorage)
|
||||||
if err == nil { return nil }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
path := filepath.Join("~", ".config", "servtex", configFileName)
|
if !configRead {
|
||||||
err = configReaderParse(path, configOptionStorage)
|
path := filepath.Join("~", ".config", "servtex", configFileName)
|
||||||
if err != nil { return err }
|
err = configReaderParse(path, configOptionStorage)
|
||||||
|
|
||||||
err = configPopulator(*configOptionStorage)
|
// create default config file for user to edit
|
||||||
if err != nil { return err }
|
if err != nil && defaultPath != "" {
|
||||||
|
LogLine(fmt.Sprintf("Configuration file does not exist. Creating with defaults at %s", defaultPath), 4)
|
||||||
err = configValidator(*configOptionStorage)
|
err = createConfigWithDefaults(defaultPath)
|
||||||
if err != nil { return err }
|
if err != nil {
|
||||||
|
LogLine("Configuration file could not be created", 4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -286,18 +297,6 @@ func LatexCompile() error {
|
|||||||
return nil
|
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.
|
// 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
|
// 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",
|
"logFilePath": "./servtex.log",
|
||||||
"logLevel": "warning",
|
"logLevel": "warning",
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"timezone": "Europe/Berlin"
|
"timezone": "Europe/Berlin",
|
||||||
"logFilePath": "./servtex.log",
|
"logFilePath": "./servtex.log",
|
||||||
"logLevel": "debug",
|
"logLevel": "debug",
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ func SSEventHandler(writer http.ResponseWriter, request *http.Request) {
|
|||||||
for range time.Tick(time.Second) {
|
for range time.Tick(time.Second) {
|
||||||
select {
|
select {
|
||||||
case <-request.Context().Done():
|
case <-request.Context().Done():
|
||||||
backend.LogLine("SSE Context Done", 1)
|
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
if lastExecution == globals.LatexExec.TimestampRFC {
|
if lastExecution == globals.LatexExec.TimestampRFC {
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ type Config struct {
|
|||||||
}
|
}
|
||||||
var AppConfig Config
|
var AppConfig Config
|
||||||
|
|
||||||
|
|
||||||
type LatexExecution struct {
|
type LatexExecution struct {
|
||||||
ExecutionLock sync.Mutex
|
ExecutionLock sync.Mutex
|
||||||
ExecutionState string
|
ExecutionState string
|
||||||
|
|||||||
12
main.go
12
main.go
@@ -72,14 +72,12 @@ func main() {
|
|||||||
fmt.Print("\r")
|
fmt.Print("\r")
|
||||||
|
|
||||||
// shutdown
|
// 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()
|
defer cancel()
|
||||||
if err = server.Shutdown(context); err != nil {
|
server.Shutdown(context)
|
||||||
backend.LogLine("Graceful Shutdown failed", 4)
|
serverSecure.Shutdown(context)
|
||||||
}
|
|
||||||
if err = serverSecure.Shutdown(context); err != nil {
|
|
||||||
backend.LogLine("Graceful Shutdown failed", 4)
|
|
||||||
}
|
|
||||||
backend.LogLine("Stopped", 2)
|
backend.LogLine("Stopped", 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user