mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
- 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
28 lines
594 B
Go
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)
|
|
}
|
|
}
|