Files
warewulf/internal/pkg/api/apiconfig/server.go
2022-10-14 17:40:16 +02:00

45 lines
1.0 KiB
Go

package apiconfig
import (
"log"
"os"
"gopkg.in/yaml.v2"
)
// ServerApiConfig contains configuration parameters for an API server.
type ServerApiConfig struct {
// Version contains the full version of the API server, eg: 1.0.0.
Version string `yaml:"version"`
// Prefix contains the version url prefix for the API server, eg: v1.
Prefix string `yaml:"prefix"`
// Port is the where the API server listens.
Port uint32 `yaml:"port"`
}
// ServerConfig is the full server configuration.
type ServerConfig struct {
ApiConfig ServerApiConfig `yaml:"api"`
TlsConfig TlsConfig `yaml:"tls"`
}
// NewServer loads the server config from the given configFilePath.
func NewServer(configFilePath string) (config ServerConfig, err error) {
log.Printf("Loading api server configuration from: %v\n", configFilePath)
var fileBytes []byte
fileBytes, err = os.ReadFile(configFilePath)
if err != nil {
return
}
err = yaml.Unmarshal(fileBytes, &config)
if err != nil {
return
}
log.Printf("api server config: %#v\n", config)
return
}