github.com/System-Glitch/goyave/v2@v2.10.3-0.20200819142921-51011e75d504/docs/assets/js/25.0d463913.js (about)
1 (window.webpackJsonp=window.webpackJsonp||[]).push([[25],{397:function(t,a,e){"use strict";e.r(a);var s=e(25),n=Object(s.a)({},(function(){var t=this,a=t.$createElement,e=t._self._c||a;return e("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[e("h1",{attrs:{id:"configuration"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#configuration"}},[t._v("#")]),t._v(" Configuration")]),t._v(" "),e("p"),e("div",{staticClass:"table-of-contents"},[e("ul",[e("li",[e("a",{attrs:{href:"#introduction"}},[t._v("Introduction")])]),e("li",[e("a",{attrs:{href:"#terminology"}},[t._v("Terminology")])]),e("li",[e("a",{attrs:{href:"#environment-configuration"}},[t._v("Environment configuration")])]),e("li",[e("a",{attrs:{href:"#using-the-configuration"}},[t._v("Using the configuration")]),e("ul",[e("li",[e("a",{attrs:{href:"#using-environment-variables"}},[t._v("Using environment variables")])]),e("li",[e("a",{attrs:{href:"#getting-a-value"}},[t._v("Getting a value")])]),e("li",[e("a",{attrs:{href:"#setting-a-value"}},[t._v("Setting a value")])])])]),e("li",[e("a",{attrs:{href:"#custom-config-entries"}},[t._v("Custom config entries")])]),e("li",[e("a",{attrs:{href:"#configuration-reference"}},[t._v("Configuration reference")]),e("ul",[e("li",[e("a",{attrs:{href:"#app-category"}},[t._v("App category")])]),e("li",[e("a",{attrs:{href:"#server-category"}},[t._v("Server category")])]),e("li",[e("a",{attrs:{href:"#database-category"}},[t._v("Database category")])])])]),e("li",[e("a",{attrs:{href:"#setting-up-https"}},[t._v("Setting up HTTPS")])])])]),e("p"),t._v(" "),e("h2",{attrs:{id:"introduction"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#introduction"}},[t._v("#")]),t._v(" Introduction")]),t._v(" "),e("p",[t._v("The Goyave framework lets you configure its core and your application.\nTo configure your application, use the "),e("code",[t._v("config.json")]),t._v(" file at your project's root. If you are using the template project, copy "),e("code",[t._v("config.example.json")]),t._v(" to "),e("code",[t._v("config.json")]),t._v(". "),e("code",[t._v("config.json")]),t._v(" should be ignored in your "),e("code",[t._v(".gitignore")]),t._v(" file as it can differ from one developer to another. To avoid accidental commit or change to the default project's config, it is a good practice to ignore this file and define the project's default config in "),e("code",[t._v("config.example.json")]),t._v(".")]),t._v(" "),e("p",[t._v("If this config file misses some config entries, the default values will be used. Refer to the "),e("a",{attrs:{href:"#configuration-reference"}},[t._v("configuration reference")]),t._v(" to know more.")]),t._v(" "),e("p",[t._v("All entries are "),e("strong",[t._v("validated")]),t._v(". That means that the application will not start if you provided an invalid value in your config (for example if the specified port is not a number). That also means that a goroutine trying to change a config entry with the incorrect type will panic."),e("br"),t._v("\nEntries can be registered with a default value, their type and authorized values from any package.")]),t._v(" "),e("p",[t._v("Configuration can be used concurrently safely.")]),t._v(" "),e("p",[t._v("The following JSON file is an example of default configuration:")]),t._v(" "),e("div",{staticClass:"language-json extra-class"},[e("pre",{pre:!0,attrs:{class:"language-json"}},[e("code",[e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"app"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"name"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"goyave_template"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"environment"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"localhost"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"debug"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("true")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"defaultLanguage"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"en-US"')]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"server"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"host"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"127.0.0.1"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"maintenance"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"protocol"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"http"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"domain"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"port"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("8080")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"httpsPort"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("8081")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"timeout"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"maxUploadSize"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("10")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"tls"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"cert"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/path/to/cert"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"key"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/path/to/key"')]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"database"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"connection"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"mysql"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"host"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"127.0.0.1"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"port"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("3306")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"name"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"goyave"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"username"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"root"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"password"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"root"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"options"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"charset=utf8&parseTime=true&loc=Local"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"maxOpenConnections"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("20")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"maxIdleConnections"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("20")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"maxLifetime"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("300")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"autoMigrate"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("false")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("h2",{attrs:{id:"terminology"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#terminology"}},[t._v("#")]),t._v(" Terminology")]),t._v(" "),e("p",[e("strong",[t._v("Entry")]),t._v(": a configuration entry is a value accessible using a key.")]),t._v(" "),e("p",[e("strong",[t._v("Registering an entry")]),t._v(": informs the framework that an entry with the given key is expected. Registering an entry allows to set a default value to be used if this entry is not provided in an app's configuration file, to enforce a certain type for this entry (for example if it needs to be an integer), and to set a list of allowed values.")]),t._v(" "),e("p",[e("strong",[t._v("Category")]),t._v(": a category is represented by a JSON object in your configuration file, delimited by braces. Sub-categories are categories that are not at root level, for example: "),e("code",[t._v("server.tls")]),t._v(" is a sub-category of the "),e("code",[t._v("server")]),t._v(" category.")]),t._v(" "),e("h2",{attrs:{id:"environment-configuration"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#environment-configuration"}},[t._v("#")]),t._v(" Environment configuration")]),t._v(" "),e("p",[t._v("Most projects need different configuration values based on the environment. For example, you won't connect to the same database if you're in local development, in a testing environment inside continuous integration pipelines, or in production. Goyave supports multiple configurations and will pick the appropriate one depending on the environment variable "),e("code",[t._v("GOYAVE_ENV")]),t._v(".")]),t._v(" "),e("p",[t._v("Since "),e("code",[t._v("v2.0.0")]),t._v(", you can use custom environments.")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("GOYAVE_ENV")]),t._v(" "),e("th",[t._v("Config file")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[t._v("test")]),t._v(" "),e("td",[e("code",[t._v("config.test.json")])])]),t._v(" "),e("tr",[e("td",[t._v("production")]),t._v(" "),e("td",[e("code",[t._v("config.production.json")])])]),t._v(" "),e("tr",[e("td",[e("em",[t._v("custom_env")])]),t._v(" "),e("td",[e("code",[t._v("config.custom_env.json")])])]),t._v(" "),e("tr",[e("td",[t._v("local / localhost / "),e("em",[t._v("not set")])]),t._v(" "),e("td",[e("code",[t._v("config.json")])])])])]),t._v(" "),e("h2",{attrs:{id:"using-the-configuration"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#using-the-configuration"}},[t._v("#")]),t._v(" Using the configuration")]),t._v(" "),e("p",[t._v("Before being able to use the config, import the config package:")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/System-Glitch/goyave/v2/config"')]),t._v("\n")])])]),e("p",[t._v("The configuration is loaded automatically when the server starts, but you can reload it manually if needed.")]),t._v(" "),e("p",[t._v("When the configuration is loaded, all default values are copied to the newly created map holding the configuration. Then, the configuration file is read, parsed and is applied over. This means that all entries from the file override the default ones. However, if an entry has a default value and the same entry is not present in the configuration file, then it is kept as it is. On the other hand, if an entry is present in the configuration file and not in the default values (meaning that this entry is not expected), a new entry will be registered.This new entry will be subsequently validated using the type of its initial value and have an empty slice as authorized values (meaning it can have any value of its type)")]),t._v(" "),e("p",[t._v("The following cases will raise errors when the configuration is being overridden:")]),t._v(" "),e("ul",[e("li",[t._v("When the configuration file overrides an entry with a category")]),t._v(" "),e("li",[t._v("When the configuration file overrides a category with an entry")])]),t._v(" "),e("h4",{attrs:{id:"config-load"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#config-load"}},[t._v("#")]),t._v(" config.Load")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Parameters")]),t._v(" "),e("th",[t._v("Return")])])]),t._v(" "),e("tbody",[e("tr",[e("td"),t._v(" "),e("td",[e("code",[t._v("error")])])])])]),t._v(" "),e("p",[e("strong",[t._v("Example:")])]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[t._v("config"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Load")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),e("h4",{attrs:{id:"config-loadfrom"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#config-loadfrom"}},[t._v("#")]),t._v(" config.LoadFrom")]),t._v(" "),e("p",[t._v("You may need to load a configuration file from a custom path instead of using the standard one. "),e("code",[t._v("LoadFrom")]),t._v(" lets you load a config file from the given path.")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Parameters")]),t._v(" "),e("th",[t._v("Return")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[e("code",[t._v("path string")])]),t._v(" "),e("td",[e("code",[t._v("error")])])])])]),t._v(" "),e("p",[e("strong",[t._v("Example:")]),t._v(" load the config from the path given through a flag")]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("import")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"flag"')]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"os"')]),t._v("\n\n "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/System-Glitch/goyave/v2"')]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"github.com/System-Glitch/goyave/v2/config"')]),t._v("\n \n "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("//...")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("handleFlags")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\tflag"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Usage "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tgoyave"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ErrLogger"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Println")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"usage: "')]),t._v(" "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" os"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Args"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("0")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("+")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('" -config=[config]"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tflag"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("PrintDefaults")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\tos"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Exit")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token number"}},[t._v("1")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n\tflag"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("String")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"config"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('""')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"JSON config file"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tflag"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Parse")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\tconfigDir "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" flag"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Lookup")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"config"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\tpath "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" configDir"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Value"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("String")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" path "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" configDir"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("DefValue "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" config"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("LoadFrom")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("path"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" err "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\t\tgoyave"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ErrLogger"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Println")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t\tos"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Exit")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("goyave"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ExitInvalidConfig"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t\t"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n\n"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("main")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("handleFlags")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\n\t"),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("if")]),t._v(" err "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":=")]),t._v(" goyave"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Start")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("route"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Register"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(";")]),t._v(" err "),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("!=")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n\t\tos"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Exit")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),t._v("err"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v("*")]),t._v("goyave"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Error"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("ExitCode"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n\t"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("h3",{attrs:{id:"using-environment-variables"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#using-environment-variables"}},[t._v("#")]),t._v(" Using environment variables")]),t._v(" "),e("p",[e("Badge",{attrs:{text:"Since v3.0.0"}})],1),t._v(" "),e("p",[t._v("You can use environment variables in your configuration file. Environment variables are identified by the following syntax: "),e("code",[t._v("${VARIABLE_NAME}")]),t._v(".")]),t._v(" "),e("div",{staticClass:"language-json extra-class"},[e("pre",{pre:!0,attrs:{class:"language-json"}},[e("code",[e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"database"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"host"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"${DB_HOST}"')]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("p",[e("strong",[t._v("Note:")]),t._v(" "),e("em",[t._v("This syntax is strict. If the string doesn't start with "),e("code",[t._v("${")]),t._v(" or doesn't end with "),e("code",[t._v("}")]),t._v(", it will not be considered an environment variable.")])]),t._v(" "),e("p",[e("code",[t._v("int")]),t._v(", "),e("code",[t._v("float64")]),t._v(" and "),e("code",[t._v("bool")]),t._v(" values are supported. If the configuration entry is expected to be of one of these types, the content of the environment variable will be automatically converted. If the conversion fails, a configuration loading error will be returned.")]),t._v(" "),e("h3",{attrs:{id:"getting-a-value"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#getting-a-value"}},[t._v("#")]),t._v(" Getting a value")]),t._v(" "),e("p",[t._v("All entries are accessible using "),e("strong",[t._v("dot-separated paths")]),t._v(". If you want to access the "),e("code",[t._v("name")]),t._v(" entry in the "),e("code",[t._v("app")]),t._v(" category, the key will be "),e("code",[t._v("app.name")]),t._v(".")]),t._v(" "),e("h4",{attrs:{id:"config-get"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#config-get"}},[t._v("#")]),t._v(" config.Get")]),t._v(" "),e("p",[t._v("Get a generic config entry.")]),t._v(" "),e("p",[t._v("Prefer using the "),e("code",[t._v("GetString")]),t._v(", "),e("code",[t._v("GetBool")]),t._v(", "),e("code",[t._v("GetInt")]),t._v(" and "),e("code",[t._v("GetFloat")]),t._v(" accessors. If you need a type not covered by those accessors, use "),e("code",[t._v("config.Get")]),t._v(". You may need to type-assert the returned value before using it. You can do so safely as the config values and types are validated.")]),t._v(" "),e("p",[t._v("Panics if the entry doesn't exist.")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Parameters")]),t._v(" "),e("th",[t._v("Return")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[e("code",[t._v("key string")])]),t._v(" "),e("td",[e("code",[t._v("interface{}")]),t._v(" or panic")])])])]),t._v(" "),e("p",[e("strong",[t._v("Example:")])]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[t._v("config"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Get")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"app.name"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v('// "goyave"')]),t._v("\n")])])]),e("h4",{attrs:{id:"config-getstring"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#config-getstring"}},[t._v("#")]),t._v(" config.GetString")]),t._v(" "),e("p",[t._v("Get a string config entry. Panics if the entry doesn't exist or is not a "),e("code",[t._v("string")]),t._v(" or if it doesn't exist.")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Parameters")]),t._v(" "),e("th",[t._v("Return")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[e("code",[t._v("key string")])]),t._v(" "),e("td",[e("code",[t._v("string")]),t._v(" or panic")])])])]),t._v(" "),e("p",[e("strong",[t._v("Example:")])]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[t._v("config"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetString")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"server.protocol"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v('// "http"')]),t._v("\n")])])]),e("h4",{attrs:{id:"config-getbool"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#config-getbool"}},[t._v("#")]),t._v(" config.GetBool")]),t._v(" "),e("p",[t._v("Get a bool config entry. Panics if the entry doesn't exist or is not a "),e("code",[t._v("bool")]),t._v(" or if it doesn't exist.")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Parameters")]),t._v(" "),e("th",[t._v("Return")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[e("code",[t._v("key string")])]),t._v(" "),e("td",[e("code",[t._v("bool")]),t._v(" or panic")])])])]),t._v(" "),e("p",[e("strong",[t._v("Example:")])]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[t._v("config"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetBool")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"app.debug"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// true")]),t._v("\n")])])]),e("h4",{attrs:{id:"config-getint"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#config-getint"}},[t._v("#")]),t._v(" config.GetInt")]),t._v(" "),e("p",[e("Badge",{attrs:{text:"Since v3.0.0"}})],1),t._v(" "),e("p",[t._v("Get an int config entry. Panics if the entry doesn't exist or is not an "),e("code",[t._v("int")]),t._v(" or if it doesn't exist.")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Parameters")]),t._v(" "),e("th",[t._v("Return")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[e("code",[t._v("key string")])]),t._v(" "),e("td",[e("code",[t._v("int")]),t._v(" or panic")])])])]),t._v(" "),e("p",[e("strong",[t._v("Example:")])]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[t._v("config"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetInt")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"server.port"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 8080")]),t._v("\n")])])]),e("h4",{attrs:{id:"config-getfloat"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#config-getfloat"}},[t._v("#")]),t._v(" config.GetFloat")]),t._v(" "),e("p",[e("Badge",{attrs:{text:"Since v3.0.0"}})],1),t._v(" "),e("p",[t._v("Get a float config entry. Panics if the entry doesn't exist or is not a "),e("code",[t._v("float64")]),t._v(" or if it doesn't exist.")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Parameters")]),t._v(" "),e("th",[t._v("Return")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[e("code",[t._v("key string")])]),t._v(" "),e("td",[e("code",[t._v("float64")]),t._v(" or panic")])])])]),t._v(" "),e("p",[e("strong",[t._v("Example:")])]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[t._v("config"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("GetInt")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"server.port"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// 8080")]),t._v("\n")])])]),e("h4",{attrs:{id:"config-has"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#config-has"}},[t._v("#")]),t._v(" config.Has")]),t._v(" "),e("p",[t._v("Check if a config entry exists.")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Parameters")]),t._v(" "),e("th",[t._v("Return")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[e("code",[t._v("key string")])]),t._v(" "),e("td",[e("code",[t._v("bool")])])])])]),t._v(" "),e("p",[e("strong",[t._v("Example:")])]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[t._v("config"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Has")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"app.name"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// true")]),t._v("\n")])])]),e("h3",{attrs:{id:"setting-a-value"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#setting-a-value"}},[t._v("#")]),t._v(" Setting a value")]),t._v(" "),e("p",[t._v("You can set a config value at runtime with the "),e("code",[t._v("config.Set(key, value)")]),t._v(" function. Bear in mind that this change "),e("strong",[t._v("temporary")]),t._v(" and will be lost after your application restarts or if the config is reloaded. This function is mainly used for testing purposes. Values set using this function are still being validated: your application will panic and revert changes if the validation doesn't pass.")]),t._v(" "),e("p",[t._v("Use "),e("code",[t._v("nil")]),t._v(" to unset a value.")]),t._v(" "),e("ul",[e("li",[t._v("A category cannot be replaced with an entry.")]),t._v(" "),e("li",[t._v("An entry cannot be replaced with a category.")]),t._v(" "),e("li",[t._v("New categories can be created with they don't already exist.")]),t._v(" "),e("li",[t._v("New entries can be created if they don't already exist. This new entry will be subsequently validated using the type of its initial value and have an empty slice as authorized values (meaning it can have any value of its type)")])]),t._v(" "),e("h4",{attrs:{id:"config-set"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#config-set"}},[t._v("#")]),t._v(" config.Set")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Parameters")]),t._v(" "),e("th",[t._v("Return")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[e("code",[t._v("key string")])]),t._v(" "),e("td",[e("code",[t._v("void")]),t._v(" or panic")])]),t._v(" "),e("tr",[e("td",[e("code",[t._v("value interface{}")])]),t._v(" "),e("td")])])]),t._v(" "),e("p",[e("strong",[t._v("Example:")])]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[t._v("config"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Set")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"app.name"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"my awesome app"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n")])])]),e("h2",{attrs:{id:"custom-config-entries"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#custom-config-entries"}},[t._v("#")]),t._v(" Custom config entries")]),t._v(" "),e("p",[t._v("Configuration can be expanded. It is very likely that a plugin or a package you're developing is using some form of options. These options can be added to the configuration system so it is not needed to set them in the code or to make some wiring.")]),t._v(" "),e("h4",{attrs:{id:"config-register"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#config-register"}},[t._v("#")]),t._v(" config.Register")]),t._v(" "),e("p",[t._v("Register a new config entry and its validation.")]),t._v(" "),e("p",[t._v("Each module should register its config entries in an "),e("code",[t._v("init()")]),t._v(" function, even if they don't have a default value, in order to ensure they will be validated.")]),t._v(" "),e("p",[t._v("Each module should use its own category and use a name both expressive and unique to avoid collisions. For example, the "),e("code",[t._v("auth")]),t._v(" package registers, among others, "),e("code",[t._v("auth.basic.username")]),t._v(" and "),e("code",[t._v("auth.jwt.expiry")]),t._v(", thus creating a category for its package, and two subcategories for its features.")]),t._v(" "),e("p",[t._v("To register an entry without a default value (only specify how it will be validated), set "),e("code",[t._v("Entry.Value")]),t._v(" to "),e("code",[t._v("nil")]),t._v(".")]),t._v(" "),e("p",[t._v("Panics if an entry already exists for this key and is not identical to the one passed as parameter of this function. On the other hand, if the entries are identical, no conflict is expected so the configuration is left in its current state.")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Parameters")]),t._v(" "),e("th",[t._v("Return")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[e("code",[t._v("key string")])]),t._v(" "),e("td",[e("code",[t._v("void")]),t._v(" or panic")])]),t._v(" "),e("tr",[e("td",[e("code",[t._v("kind config.Entry")])]),t._v(" "),e("td")])])]),t._v(" "),e("p",[e("strong",[t._v("Example:")])]),t._v(" "),e("div",{staticClass:"language-go extra-class"},[e("pre",{pre:!0,attrs:{class:"language-go"}},[e("code",[e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("func")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("init")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n config"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Register")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"my-plugin.name"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" config"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Entry"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n Value"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"default value"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n Type"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" reflect"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("String"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n AuthorizedValues"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n \n "),e("span",{pre:!0,attrs:{class:"token comment"}},[t._v("// Without a default value (only validation)")]),t._v("\n config"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),e("span",{pre:!0,attrs:{class:"token function"}},[t._v("Register")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("(")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"my-plugin.protocol"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" config"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("Entry"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n Value"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token boolean"}},[t._v("nil")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n Type"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" reflect"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(".")]),t._v("String"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n AuthorizedValues"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),e("span",{pre:!0,attrs:{class:"token keyword"}},[t._v("interface")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"ftp"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"sftp"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"scp"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(")")]),t._v("\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("h2",{attrs:{id:"configuration-reference"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#configuration-reference"}},[t._v("#")]),t._v(" Configuration reference")]),t._v(" "),e("h3",{attrs:{id:"app-category"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#app-category"}},[t._v("#")]),t._v(" App category")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Entry")]),t._v(" "),e("th",[t._v("Type")]),t._v(" "),e("th",[t._v("Accepted values")]),t._v(" "),e("th",[t._v("Default")]),t._v(" "),e("th",[t._v("Note")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[t._v("name")]),t._v(" "),e("td",[e("code",[t._v("string")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[t._v('"goyave"')]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[t._v("environment")]),t._v(" "),e("td",[e("code",[t._v("string")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[t._v('"localhost"')]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[t._v("debug")]),t._v(" "),e("td",[e("code",[t._v("bool")])]),t._v(" "),e("td",[e("code",[t._v("true")]),t._v(", "),e("code",[t._v("false")])]),t._v(" "),e("td",[e("code",[t._v("true")])]),t._v(" "),e("td",[t._v("When activated, print stacktrace on error and sends error message in response. "),e("strong",[t._v("Disable this in production!")])])]),t._v(" "),e("tr",[e("td",[t._v("defaultLanguage")]),t._v(" "),e("td",[e("code",[t._v("string")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[t._v('"en-US"')]),t._v(" "),e("td",[t._v("See the "),e("RouterLink",{attrs:{to:"/guide/advanced/localization.html"}},[t._v("Localization")])],1)])])]),t._v(" "),e("h3",{attrs:{id:"server-category"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#server-category"}},[t._v("#")]),t._v(" Server category")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Entry")]),t._v(" "),e("th",[t._v("Type")]),t._v(" "),e("th",[t._v("Accepted values")]),t._v(" "),e("th",[t._v("Default")]),t._v(" "),e("th",[t._v("Note")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[t._v("host")]),t._v(" "),e("td",[e("code",[t._v("string")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[t._v('"127.0.0.1"')]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[t._v("domain")]),t._v(" "),e("td",[e("code",[t._v("string")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[t._v('""')]),t._v(" "),e("td",[t._v("Used for URL generation Leave empty to use IP instead.")])]),t._v(" "),e("tr",[e("td",[t._v("protocol")]),t._v(" "),e("td",[e("code",[t._v("string")])]),t._v(" "),e("td",[t._v('"http", "https"')]),t._v(" "),e("td",[t._v('"http"')]),t._v(" "),e("td",[t._v("See the "),e("a",{attrs:{href:"#setting-up-https"}},[t._v("HTTPS")]),t._v(" section")])]),t._v(" "),e("tr",[e("td",[t._v("port")]),t._v(" "),e("td",[e("code",[t._v("int")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[e("code",[t._v("8080")])]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[t._v("httpsPort")]),t._v(" "),e("td",[e("code",[t._v("int")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[e("code",[t._v("8081")])]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[t._v("timeout")]),t._v(" "),e("td",[e("code",[t._v("int")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[e("code",[t._v("10")])]),t._v(" "),e("td",[t._v("Timeout in seconds")])]),t._v(" "),e("tr",[e("td",[t._v("maxUploadSize")]),t._v(" "),e("td",[e("code",[t._v("float64")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[e("code",[t._v("10")])]),t._v(" "),e("td",[t._v("Maximum size of the request, in MiB")])]),t._v(" "),e("tr",[e("td",[t._v("maintenance")]),t._v(" "),e("td",[e("code",[t._v("bool")])]),t._v(" "),e("td",[e("code",[t._v("true")]),t._v(", "),e("code",[t._v("false")])]),t._v(" "),e("td",[e("code",[t._v("false")])]),t._v(" "),e("td",[t._v("If "),e("code",[t._v("true")]),t._v(", start the server in maintenance mode. (Always return HTTP 503)")])])])]),t._v(" "),e("h4",{attrs:{id:"tls-sub-category"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#tls-sub-category"}},[t._v("#")]),t._v(" TLS sub-category")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Entry")]),t._v(" "),e("th",[t._v("Type")]),t._v(" "),e("th",[t._v("Accepted values")]),t._v(" "),e("th",[t._v("Default")]),t._v(" "),e("th",[t._v("Note")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[t._v("cert")]),t._v(" "),e("td",[e("code",[t._v("string")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[t._v("none")]),t._v(" "),e("td",[t._v("Path to your TLS cert")])]),t._v(" "),e("tr",[e("td",[t._v("key")]),t._v(" "),e("td",[e("code",[t._v("string")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[t._v("none")]),t._v(" "),e("td",[t._v("Path to your TLS key")])])])]),t._v(" "),e("h3",{attrs:{id:"database-category"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#database-category"}},[t._v("#")]),t._v(" Database category")]),t._v(" "),e("table",[e("thead",[e("tr",[e("th",[t._v("Entry")]),t._v(" "),e("th",[t._v("Type")]),t._v(" "),e("th",[t._v("Accepted values")]),t._v(" "),e("th",[t._v("Default")]),t._v(" "),e("th",[t._v("Note")])])]),t._v(" "),e("tbody",[e("tr",[e("td",[t._v("connection")]),t._v(" "),e("td",[e("code",[t._v("string")])]),t._v(" "),e("td",[t._v('"none", "mysql", "postgres", "sqlite3", "mssql"')]),t._v(" "),e("td",[t._v('"none"')]),t._v(" "),e("td",[t._v("See the "),e("RouterLink",{attrs:{to:"/guide/basics/database.html"}},[t._v("Database")]),t._v(" guide")],1)]),t._v(" "),e("tr",[e("td",[t._v("host")]),t._v(" "),e("td",[e("code",[t._v("string")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[t._v('"127.0.0.1"')]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[t._v("port")]),t._v(" "),e("td",[e("code",[t._v("int")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[e("code",[t._v("3306")])]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[t._v("name")]),t._v(" "),e("td",[e("code",[t._v("string")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[t._v('"goyave"')]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[t._v("username")]),t._v(" "),e("td",[e("code",[t._v("string")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[t._v('"root"')]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[t._v("password")]),t._v(" "),e("td",[e("code",[t._v("string")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[t._v('"root"')]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[t._v("otions")]),t._v(" "),e("td",[e("code",[t._v("string")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[t._v('"charset=utf8&parseTime=true&loc=Local"')]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[t._v("maxOpenConnections")]),t._v(" "),e("td",[e("code",[t._v("int")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[e("code",[t._v("20")])]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[t._v("maxIdleConnections")]),t._v(" "),e("td",[e("code",[t._v("int")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[e("code",[t._v("20")])]),t._v(" "),e("td")]),t._v(" "),e("tr",[e("td",[t._v("maxLifetime")]),t._v(" "),e("td",[e("code",[t._v("int")])]),t._v(" "),e("td",[t._v("any")]),t._v(" "),e("td",[e("code",[t._v("300")])]),t._v(" "),e("td",[t._v("The maximum time (in seconds) a connection may be reused.")])]),t._v(" "),e("tr",[e("td",[t._v("autoMigrate")]),t._v(" "),e("td",[e("code",[t._v("bool")])]),t._v(" "),e("td",[e("code",[t._v("true")]),t._v(", "),e("code",[t._v("false")])]),t._v(" "),e("td",[e("code",[t._v("false")])]),t._v(" "),e("td",[t._v("When activated, migrate all registered models at startup")])])])]),t._v(" "),e("h2",{attrs:{id:"setting-up-https"}},[e("a",{staticClass:"header-anchor",attrs:{href:"#setting-up-https"}},[t._v("#")]),t._v(" Setting up HTTPS")]),t._v(" "),e("p",[t._v("Setting up HTTPS on your Goyave application is easy. First, turn "),e("code",[t._v("server.protocol")]),t._v(" to "),e("code",[t._v("https")]),t._v(" in the config. Then, add the "),e("code",[t._v("server.tls.cert")]),t._v(" and "),e("code",[t._v("server.tls.key")]),t._v(" entries in the config. These two entries represent respectively the path to your TLS certificate and your TLS key.")]),t._v(" "),e("p",[e("strong",[t._v("Certbot example:")])]),t._v(" "),e("div",{staticClass:"language-json extra-class"},[e("pre",{pre:!0,attrs:{class:"language-json"}},[e("code",[e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n ...\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"server"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"protocol"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"https"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"tls"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("{")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"cert"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/etc/letsencrypt/live/mydomain.com/cert.pem"')]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token property"}},[t._v('"key"')]),e("span",{pre:!0,attrs:{class:"token operator"}},[t._v(":")]),t._v(" "),e("span",{pre:!0,attrs:{class:"token string"}},[t._v('"/etc/letsencrypt/live/mydomain.com/privkey.pem"')]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n "),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v(",")]),t._v("\n ...\n"),e("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("}")]),t._v("\n")])])]),e("p",[t._v("Restart your server and you should now be able to connect securely to your Goyave application! All HTTP requests will automatically be redirected to HTTPS.")])])}),[],!1,null,null,null);a.default=n.exports}}]);