Skip to content

Add simplemap backend#36

Open
mpodlodowski wants to merge 2 commits into
heetch:masterfrom
mpodlodowski:map-backend
Open

Add simplemap backend#36
mpodlodowski wants to merge 2 commits into
heetch:masterfrom
mpodlodowski:map-backend

Conversation

@mpodlodowski

Copy link
Copy Markdown

No description provided.

@yaziine yaziine left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey @mpodlodowski, thank you for submitting this PR. I have left a comment feel free to tell me what do you think.

Let's refer this to #12.

}

return nil, backend.ErrNotFound
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think that this is redundant with what we do in the convert function. Moreover you are not handling all the primitive and this is very problematic, for example if the type is an int64 the method will end with a backend.ErrNotFound error.
What can you do to improve this ?
There is also the Unmarshaler and StructLoader interface which can be used maybe you can take a look at them (it's just a proposal not sure that is the correct way to go).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thank you! Tried the StructLoader way, take a look :)

@rogpeppe rogpeppe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM modulo a few issues, thanks! I suspect that map[string]string is the way to go here.

continue
}
mapRef := reflect.ValueOf(mapVal)
f.Value.Set(mapRef)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will panic if the mapVal does not have the same type as f.Value. We could return an error if the types aren't identical, but this might be perceived as being overly restrictive, because (for example) you wouldn't be able to use an int-valued map item to fill a float-valued struct field.

Perhaps it would be easiest to implement the Backend on map[string]string instead of map[string]interface{} and then just implement the Get method?

)

// Backend that loads config from map
type Backend struct {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

How about just:

type Backend map[string]interface{}

?
Then we wouldn't need the NewBackend constructor function.

Timeout time.Duration `config:"Timeout"`
}

b := simplemap.NewBackend(map[string]interface{}{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's have some test cases that test error cases, such as mismatched types, please.

@grihabor

Copy link
Copy Markdown

@mpodlodowski thanks for your code! Are you planning to make it to the end?

@grihabor grihabor mentioned this pull request Jun 18, 2021
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.

4 participants