Marc Cataford
98fda3b404
All checks were successful
Pull-Request / tests (pull_request) Successful in 1m9s
Pull-Request / static-analysis (pull_request) Successful in 1m38s
Pull-Request / post-run (pull_request) Successful in 30s
Push / pre-run (push) Successful in 26s
Push / tests (push) Successful in 1m4s
Push / static-analysis (push) Successful in 1m28s
Push / post-run (push) Successful in 40s
34 lines
833 B
Go
34 lines
833 B
Go
// File Definition fetcher
|
|
//
|
|
// Handles extracting service definitions from local files.
|
|
|
|
package service_definition
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/goccy/go-yaml"
|
|
"os"
|
|
)
|
|
|
|
type FileDefinitionFetcher struct{}
|
|
|
|
func NewFileDefinitionFetcher() *FileDefinitionFetcher {
|
|
return &FileDefinitionFetcher{}
|
|
}
|
|
|
|
// Retrieves a service definition from the given filepath.
|
|
func (f FileDefinitionFetcher) GetDefinition(path string) (ServiceDefinition, error) {
|
|
var definition ServiceDefinition
|
|
|
|
defData, err := os.ReadFile(path)
|
|
|
|
if err != nil {
|
|
return ServiceDefinition{}, fmt.Errorf("Could not find service configuration file: %s", path)
|
|
}
|
|
|
|
if err = yaml.Unmarshal(defData, &definition); err != nil {
|
|
return ServiceDefinition{}, fmt.Errorf("Service definition does not satisfy expected schema: %s", path)
|
|
}
|
|
|
|
return definition, nil
|
|
}
|