29 lines
547 B
Go
29 lines
547 B
Go
package helpers
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/pelletier/go-toml"
|
|
)
|
|
|
|
type Configuration struct {
|
|
Server struct {
|
|
Address string `toml:"address"`
|
|
Port int `toml:"port"`
|
|
} `toml:"server"`
|
|
}
|
|
|
|
func ParseConfig(filePath string) (*Configuration, error) {
|
|
var config Configuration
|
|
data, err := toml.LoadFile(filePath)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error parsing config file: %v", err)
|
|
}
|
|
|
|
err = data.Unmarshal(&config)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error parsing config file: %v", err)
|
|
}
|
|
|
|
return &config, nil
|
|
}
|