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

Handle simple values #13

Merged
merged 7 commits into from
Feb 8, 2021
Merged

Handle simple values #13

merged 7 commits into from
Feb 8, 2021

Conversation

mkatychev
Copy link
Contributor

@mkatychev mkatychev commented Feb 8, 2021

This PR adds "simple" primitive types as defined in IsSimpleValue to the "flat map" output:

// IsSimpleValue is intended to see if the underlying value allows a flat map to be retained
func IsSimpleValue(i interface{}) bool {
	switch i.(type) {
	case string,
		float32, float64,
		uint8, uint16, uint32, uint64,
		int8, int16, int32, int64,
		bool:
		return true
	}
	return false
}

Previously only map[string]string were considered to be "flat" associative arrays

So the presence of the integer 12 would mean that fetching the value for key1 necessitated declaring the read type as complex for all keys found in the map:

# file.yaml
key1: val
key2: {nested_key: val}
[file.vars]
key1.path = "file.yaml"
key1.type = "yaml{}"
key2.path = "file.yaml"
key2.type = "yaml{}"

This is no longer the case and flat values can also be mixed complex values without both needing the complex read type declaration:

[file.vars]
key1.path = "file.yaml"
# key1.type is deferred thus taking "yaml" from the file stem
key2.path = "file.yaml"
key2.type = "yaml{}"

@mkatychev mkatychev marked this pull request as ready for review February 8, 2021 16:28
e2e.sh Show resolved Hide resolved
generate.go Outdated Show resolved Hide resolved
if err != nil {
return nil, err
}
return linkMap, nil
}

func decodeEnv(linkMap LinkMap, env CfgMap) error {
// baseContext is the struct that maps to the TOML table's ctx name
type baseContext struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we use a different name other than context? This makes me think of go's standard context.Context type

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that a lot but I really think that the inherent meaning of the word here supersedes the namespace confusion it might cause. "Context" in terms of what you want the output of key value store to be is really important.

Copy link

@jsgoyette jsgoyette left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

generate.go Outdated Show resolved Hide resolved
output.go Outdated Show resolved Hide resolved
@mkatychev mkatychev merged commit e8bdf1c into master Feb 8, 2021
@mkatychev mkatychev deleted the handle_simple_values branch February 8, 2021 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants