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

feat: add support for base64 encoding #13

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

zimt28
Copy link

@zimt28 zimt28 commented Dec 16, 2023

Closes #10

@emadalam
Copy link
Owner

@zimt28 How about introducing a new type base64 instead of adding it as an additional option. I suggest this because using it as an option will make the option useless for cases where type: :str is not used. Furthermore, we already use types like :host, :uri etc which is nothing more than string, and other types like :num, :int etc are ultimately parsed from string. The whole point of this parsing is to ultimately get values from environment variable string values that can be translated/validated into some stricter business types.

Also it would be much easier to simply implement the additional parser function for this base64 use case, no other change would be required in the core setup or functionality elsewhere.

What do you think?

lib/mahaul/parser.ex

  def parse(val, :base64) do
    case Base.decode64(val) do
     {:ok, decoded} -> {:ok, decoded}
      _ -> @error_tuple
    end
  end

lib/mahaul/constants.ex#L14

@type var_type :: :str | :num | :int | :bool | :port | :host | :uri | :base64

lib/mahaul/constants.ex#L42

@supported_types [:str, :enum, :num, :int, :bool, :port, :host, :uri, :base64]

@emadalam
Copy link
Owner

P.S:

  • Thank you for the PR ❣️
  • Use dev branch to merge changes so we can make a single release on hex ✌️

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.

[Feature Request]: Add base64 option
2 participants