initial commit
This commit is contained in:
33
internal/service/config.go
Normal file
33
internal/service/config.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
DatabasePath string `json:"databasePath"`
|
||||
TemplateDirectoryPath string `json:"templateDirectoryPath"`
|
||||
HostName string `json:"hostName"`
|
||||
}
|
||||
|
||||
func ReadConfigFrom(reader io.Reader) (Config, error) {
|
||||
var config Config
|
||||
err := json.NewDecoder(reader).Decode(&config)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
config.DatabasePath, err = filepath.Abs(config.DatabasePath)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
config.TemplateDirectoryPath, err = filepath.Abs(config.TemplateDirectoryPath)
|
||||
if err != nil {
|
||||
return Config{}, err
|
||||
}
|
||||
|
||||
return config, nil
|
||||
}
|
Reference in New Issue
Block a user