Hello! I am a newcomer to Julia and I am trying to recreate something that I worked a bit on in Python in Julia, because I think Julia will be the better language overall for numerical performance. However, I am trying to do something that I am not sure Julia is suited for before I can get to that numerical aspect.
The code needs to interact with several outside sources of data, like databases, web APIs, etc. What I would like is for a configuration file to be able to define which files to import for each of these sources. Then, the program will import those source files and use the functions within to download data, store it away, etc. In Python I would do this with an abstract base class, and dynamically import the module based on the name saved in the configuration file. In Julia, I am not so sure. It seems there are a few options possible with metaprogramming, but I am not sure they fit exactly into what I imagine. Maybe something like the following as a minimum (but not working!) example would help:
# Main file
include("ConfigImport.jl")
function main()
imported_file = ConfigImport.import_config() # where imported file is a reference to OtherFile
imported_file.do_stuff()
end
main()
# ConfigImport.jl
module ConfigImport
using TOML
function import_config()
config_data = nothing
try
config_data = TOML.parsefile("config/config.toml")
catch e
if isa(e, SystemError)
println("It appears the config file is missing!")
elseif isa(e, TOML.ParserError)
println("It appears there is something wrong with the format of the config file!")
else
throw(e)
end
end
include(config_data["OtherFile"] * ".jl")
return Symbol(config_data["OtherFile"])
end
end
# OtherFile.jl
module OtherFile
function do_stuff()
println("Doing some stuff!")
end
end
I feel like there has to be a better design pattern or a use of macros to accomplish what I am trying to do, I just have no idea what that might be.