config page
This commit is contained in:
21
backend-golang/app.go
Normal file
21
backend-golang/app.go
Normal 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
18
backend-golang/config.go
Normal 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 ""
|
||||
}
|
||||
Reference in New Issue
Block a user