Files
warewulf/internal/pkg/api/apiconfig/server.go
Christian Goll 9ba1aa8d63 api changes to modify unexported fields
changes can now not be done directly but must
go to SetNode or SetProfile. Although its also
now possible to access the field direclty with
GetNodePtr

Signed-off-by: Christian Goll <cgoll@suse.com>
2024-10-17 15:30:54 -04:00

45 lines
1.0 KiB
Go

package apiconfig
import (
"log"
"os"
"gopkg.in/yaml.v3"
)
// 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
}