TOML reads Configuration from a toml-compatible document file. Read more about toml's implementation at: https://github.com/toml-lang/toml Accepts the absolute path of the configuration file. An error will be shown to the user via panic with the error message. Error may occur when the file does not
(filename string)
| 123 | // app.Configure(iris.WithConfiguration(iris.TOML("myconfig.tml"))) or |
| 124 | // app.Run([iris.Runner], iris.WithConfiguration(iris.TOML("myconfig.tml"))). |
| 125 | func TOML(filename string) Configuration { |
| 126 | c := DefaultConfiguration() |
| 127 | |
| 128 | // check for globe configuration file and use that, otherwise |
| 129 | // return the default configuration if file doesn't exist. |
| 130 | if filename == globalConfigurationKeyword { |
| 131 | filename = homeConfigurationFilename(".tml") |
| 132 | if _, err := os.Stat(filename); os.IsNotExist(err) { |
| 133 | panic("default configuration file '" + filename + "' does not exist") |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | // get the abs |
| 138 | // which will try to find the 'filename' from current workind dir too. |
| 139 | tomlAbsPath, err := filepath.Abs(filename) |
| 140 | if err != nil { |
| 141 | panic(fmt.Errorf("toml: %w", err)) |
| 142 | } |
| 143 | |
| 144 | // read the raw contents of the file |
| 145 | data, err := os.ReadFile(tomlAbsPath) |
| 146 | if err != nil { |
| 147 | panic(fmt.Errorf("toml :%w", err)) |
| 148 | } |
| 149 | |
| 150 | // put the file's contents as toml to the default configuration(c) |
| 151 | if _, err := toml.Decode(string(data), &c); err != nil { |
| 152 | panic(fmt.Errorf("toml :%w", err)) |
| 153 | } |
| 154 | // Author's notes: |
| 155 | // The toml's 'usual thing' for key naming is: the_config_key instead of TheConfigKey |
| 156 | // but I am always prefer to use the specific programming language's syntax |
| 157 | // and the original configuration name fields for external configuration files |
| 158 | // so we do 'toml: "TheConfigKeySameAsTheConfigField" instead. |
| 159 | return c |
| 160 | } |
| 161 | |
| 162 | // Configurator is just an interface which accepts the framework instance. |
| 163 | // |
searching dependent graphs…