turash/models/params/loader.go
Damir Mukimov 4a2fda96cd
Initial commit: Repository setup with .gitignore, golangci-lint v2.6.0, and code quality checks
- Initialize git repository
- Add comprehensive .gitignore for Go projects
- Install golangci-lint v2.6.0 (latest v2) globally
- Configure .golangci.yml with appropriate linters and formatters
- Fix all formatting issues (gofmt)
- Fix all errcheck issues (unchecked errors)
- Adjust complexity threshold for validation functions
- All checks passing: build, test, vet, lint
2025-11-01 07:36:22 +01:00

28 lines
594 B
Go

package params
import (
"os"
"strings"
)
// LoadFromFile loads parameters from a JSON or YAML file.
// File format is determined by extension (.json or .yaml/.yml).
func LoadFromFile(filepath string) (*Params, error) {
data, err := os.ReadFile(filepath)
if err != nil {
return nil, err
}
// Determine format by extension
ext := strings.ToLower(filepath[strings.LastIndex(filepath, "."):])
switch ext {
case ".yaml", ".yml":
return LoadFromYAML(data)
case ".json":
return LoadFromJSON(data)
default:
// Default to JSON if unknown extension
return LoadFromJSON(data)
}
}