Client library - need for global variable

Hi…

I am creating a client library in which there is an authentication check - say -->

defmodule Auth do
   def auth_key do
      "ABcd1234"
   end
end

defmodule Action do
   import Auth
   def func do 
      key = auth_key( )
      unless validate(key) do
            raise_error_message()
      end
  end
end

Now the issue is the auth_key has to be set by the users of this library. In a OOP oriented language this is easy. I had a global variable for auth_key and users of the library simply overwrite the default value of the variable. How can I do it in Elixir??

Is it a static value that the user of the library should configure? If so, you should use elixir’s/Mix config support.

http://elixir-lang.org/docs/stable/mix/Mix.Config.html

1 Like