29 lines
725 B
Go
29 lines
725 B
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"git.faercol.me/faercol/polyculeconnect/polyculeconnect/config"
|
|
)
|
|
|
|
// Fail displays the given error to stderr and exits the program with a returncode 1
|
|
func Fail(errMsg string) {
|
|
fmt.Fprintln(os.Stderr, errMsg)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// Fail displays the given formatted error to stderr and exits the program with a returncode 1
|
|
func Failf(msg string, args ...any) {
|
|
fmt.Fprintf(os.Stderr, msg+"\n", args...)
|
|
os.Exit(1)
|
|
}
|
|
|
|
// InitConfig inits the configuration, and fails the program if an error occurs
|
|
func InitConfig(configPath string) *config.AppConfig {
|
|
conf, err := config.New(configPath)
|
|
if err != nil {
|
|
Failf("Failed to load the configuration: %s", err.Error())
|
|
}
|
|
return conf
|
|
}
|