How to define the struct in the correct way, look at the following code snippet:
defmodule SapOdataService.Worker do defstruct uri: "", user: nil, password: nil Should I define the default value as nil or?
You have a few options.
You can list the key value pairs explicitly using nil for blank values
defmodule User do defstruct name: "zero_coding", age: nil end You can pass a list of atoms that will all default to nil:
defmodule User do defstruct [:name, :age] end You can do a mix of the above a list of atoms that will all default to nil:
defmodule User do defstruct [:age, name: "zero_coding"] end You can also enforce specific keys that must be specified when creating the struct
defmodule User do @enforce_keys [:name] defstruct [:name, :age] end nil) first, then the explicit defaults. defstruct [name: "zero_coding", :age] gives error.
defstructand every value will have a nil as a default, which may make sense in your case I guess.urlvalue it makes sense to leave nil as a default value, sometimes it makes sense to make "example.com" as a default value, sometimes it makes sense to make it an empty string and etc. It's completely up to you and what you think it more suitable for your situation.defstruct [:user, :password, url: ""], so you don't have to repeatnilover and over.