Files
cloudsave/cmd/web/server/config/config.go
Aurélie DELHAIE 46f312078d
Some checks failed
CloudSave/pipeline/head Something is wrong with the build of this commit
fix sec
2025-09-07 01:31:14 +02:00

42 lines
751 B
Go

package config
import (
"encoding/json"
"fmt"
"os"
"path/filepath"
)
type (
Configuration struct {
Server ServerConfiguration `json:"server"`
Remote RemoteConfiguration `json:"remote"`
}
ServerConfiguration struct {
Port int `json:"port"`
}
RemoteConfiguration struct {
URL string `json:"url"`
}
)
func Load(path string) (Configuration, error) {
f, err := os.OpenFile(filepath.Clean(path), os.O_RDONLY, 0)
if err != nil {
return Configuration{}, fmt.Errorf("failed to open configuration file: %w", err)
}
defer f.Close()
d := json.NewDecoder(f)
var c Configuration
err = d.Decode(&c)
if err != nil {
return Configuration{}, fmt.Errorf("failed to parse configuration file (%s): %w", path, err)
}
return c, nil
}