config page

This commit is contained in:
josc146
2023-05-05 23:23:34 +08:00
parent f212eea1b7
commit f6be32825f
18 changed files with 400 additions and 54 deletions

21
backend-golang/app.go Normal file
View File

@@ -0,0 +1,21 @@
package backend_golang
import (
"context"
)
// App struct
type App struct {
ctx context.Context
}
// NewApp creates a new App application struct
func NewApp() *App {
return &App{}
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) OnStartup(ctx context.Context) {
a.ctx = ctx
}

18
backend-golang/config.go Normal file
View File

@@ -0,0 +1,18 @@
package backend_golang
import (
"encoding/json"
"os"
)
func (a *App) SaveConfig(config interface{}) string {
jsonData, err := json.MarshalIndent(config, "", " ")
if err != nil {
return err.Error()
}
if err := os.WriteFile("config.json", jsonData, 0644); err != nil {
return err.Error()
}
return ""
}