Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use any instead of interface #80

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions cmd/structuresmith/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (app *Structuresmith) renderFileStructure(file FileStructure) error {
}

// handleFileCreation creates or copies a file based on provided content or source.
func handleFileCreation(fullPath, content string, values map[string]interface{}) error {
func handleFileCreation(fullPath, content string, values map[string]any) error {
// Attempt to create a templated file
err := createTemplatedFile(fullPath, content, values)
if err != nil {
Expand Down Expand Up @@ -221,8 +221,8 @@ func (app *Structuresmith) processProject(p Project, globalGroups map[string][]F

// mergeValues merges group-level values with file-level.
// For slices and non-map values, the value from src will overwrite the one in dst.
func mergeValues(dst, src map[string]interface{}) map[string]interface{} {
merged := make(map[string]interface{})
func mergeValues(dst, src map[string]any) map[string]any {
merged := make(map[string]any)

// Copy values from dst into the new map
for key, val := range dst {
Expand All @@ -233,8 +233,8 @@ func mergeValues(dst, src map[string]interface{}) map[string]interface{} {
for key, srcVal := range src {
if dstVal, exists := merged[key]; exists {
// If both values are maps, merge them recursively
if srcMap, srcOk := srcVal.(map[string]interface{}); srcOk {
if dstMap, dstOk := dstVal.(map[string]interface{}); dstOk {
if srcMap, srcOk := srcVal.(map[string]any); srcOk {
if dstMap, dstOk := dstVal.(map[string]any); dstOk {
merged[key] = mergeValues(dstMap, srcMap)
continue
}
Expand Down Expand Up @@ -315,7 +315,7 @@ func downloadFileContent(fileURL string) (string, error) {
}

// createTemplatedFile creates a file from a template content and values.
func createTemplatedFile(path, content string, values map[string]interface{}) error {
func createTemplatedFile(path, content string, values map[string]any) error {
f, err := os.Create(path)
if err != nil {
return fmt.Errorf("creating file: %w", err)
Expand Down
6 changes: 3 additions & 3 deletions cmd/structuresmith/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ type ProjectConfig struct {

// TemplateGroupRef links a template group with specific values.
type TemplateGroupRef struct {
GroupName string `yaml:"groupName"`
Values map[string]interface{} `yaml:"values"`
GroupName string `yaml:"groupName"`
Values map[string]any `yaml:"values"`
}

// FileStructure describes a file to be created from a template or URL.
Expand All @@ -35,7 +35,7 @@ type FileStructure struct {
Source string `yaml:"source"`
SourceURL string `yaml:"sourceUrl"`
Content string `yaml:"content"`
Values map[string]interface{}
Values map[string]any
}

// Template represents a template consisting of multiple files.
Expand Down
Loading