This is a creation in Article, where the information may have evolved or changed.
Configuration files are commonly used in the project to configure the initialization parameters, and the format of the configuration file there are many, different operating systems, programming languages will have a different format of the configuration file, this article lists some common configuration file format.
Different configuration file formats have different user-friendliness, there are simple and complex support for the function, it is difficult to say that the configuration file is the best, sometimes need to consider from many aspects, such as windows earlier development like to use, int
Java like to use properties
, General programming like yaml
, and json
Other formats, this article will not rank these formats, but a brief introduction of these formats, users can choose according to their actual situation.
Ini
INI file is a configuration file that has no fixed standard format. It is made up of simple text with simple structure and is often used in Windows operating systems. INI file is derived from the acronym "initial (Initial)" in English and is corresponding to its purpose-initialization program.
File format is relatively simple, divided into 节
,, 参数
注释
. The following is a simple INI configuration file:
https://github.com/Microsoft/Windows-driver-samples/blob/master/print/v4PrintDriverSamples/ V4printdriver-hostbasedsampledriver/usb_host_based_sample-manifest.ini
12345678910111213 |
[Driverconfig]drivercategory=printfax.printer datafile=usb_host_based_sample.gpd ; Note:please Replace the GUID below when building a production driver.printerdriverid={00000000-0000-0000-0000-000000000000 }flags=hostbaseddevice eventfile=usb_host_based_sample_events.xml requiredfiles=unires. Dll,stdnames. Gpd,msxpsinc. GPD [Bidifiles]bidiusbfile=usb_host_based_sample_extension.xml bidiusbjsfile=usb_host_based_sample.js |
Properties
Properties is a file extension of a file that is primarily used in Java-related technologies to store configurable parameters for an application. They can also store strings for internationalization and localization, which are known as Property resource Bundles (Properties Resource Bundles).
Each parameter is stored as a pair of strings: one stores the name parameter (called "Key") and the other stores the value.
The rows in each properties file typically store a single property. There may be several formats for each row, including key = value, key = value, key: value, and key value.
The. properties file can use a pound sign (#) or an exclamation mark (!) as the first non-whitespace character in a row to indicate that all text following it is a comment. A backslash (\) is used to escape characters. Here is a properties file:
https://github.com/netgloo/spring-boot-samples/blob/master/spring-boot-mysql-springdatajpa-hibernate/src/ Main/resources/application.properties
12345678910111213141516 |
# ===============================# = DATA source# ===============================# Set here Configurations for the database connection #ConnectionUrl forTheDatabase "Netgloo_blog"Spring.datasource.url = Jdbc:mysql://localhost:3306/netgloo_blog?usessl=false# Username and PasswordSpring.datasource.username = Rootspring.datasource.Password= root# Keep TheConnectionAliveifIdle forA long Time(NeededinchProduction) Spring.datasource.testWhileIdle =trueSpring.datasource.validationQuery =SELECT 1 |
Json
JSON (JavaScript Object Notation) is a lightweight data exchange language that is text-based and easy to read. Although JSON is a subset of JavaScript, JSON is a language-independent text format and uses some of the same habits as the C language family.
JSON data formats are language-independent and are derived from JavaScript, but many programming languages now support the generation and parsing of JSON-formatted data, and are often used as configuration files.
JSON is used to describe a data structure that exists in the following form.
- Object: An object to
{
begin with, and to }
end. An object contains a series of non-sorted name/value pairs, using partitions between each name/value pair ,
- Name/value (collection): Used between names and values
:
, the general form is:{name:value}
- Sequential list of values (Array): One or more values are used, and after partitioning, they are used to
[,]
form such lists
- Strings: A string of characters enclosed in "".
- Value: A series of 0-9 numeric combinations that can be negative or fractional. It can also be expressed in exponential form by E or E.
- Boolean value: expressed as true or false.
The format description for JSON can be referenced in RFC 4627.
Here is an example of a JSON configuration file:
Https://github.com/hashicorp/vault/blob/master/command/server/test-fixtures/config.hcl.json
123456789101112131415161718192021 |
{"Listener":[{"TCP":{"Address":"127.0.0.1:443"}}],"cluster_cipher_suites":"Tls_ecdhe_rsa_with_aes_128_gcm_sha256,tls_ecdhe_ecdsa_with_aes_128_cbc_sha","Storage":{"Consul":{"Foo":"Bar","disable_clustering":"true"}},"Telemetry":{"statsite_address":"Baz"},"Max_lease_ttl":"10h","Default_lease_ttl":"10h","cluster_name":"Testcluster","UI":true} |
Xml
XML is a markup language. tags refer to information symbols that can be understood by a computer, which can be used to process articles that contain various kinds of information between computers.
XML was a prototype since 1995 and was proposed to the World Wide Web Consortium (XML1.0), which was released in February 1998.
XML is designed to transmit and carry data information, so it is often used to make configuration files.
XML instance:
Https://github.com/kpavlov/spring-cloud-config-sample/blob/master/src/main/resources/spring-config.xml
12345678910111213141516171819 |
<?xml version= "1.0" encoding= "UTF-8"?><beans xmlns="Http://www.springframework.org/schema/beans" Xmlns:xsi="Http://www.w3.org/2001/XMLSchema-instance" Xmlns:context="Http://www.springframework.org/schema/context" xsi:schemalocation="Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd Http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd "><context:property-placeholder location =" ${config.uri}/company.properties, Classpath:product.properties, ${config.uri}/${product.name}/${product.version} /common.properties, ${config.uri}/${product.name}/${product.version}/${config.stage}/stage.properties, ${ Config.uri}/${product.name}/${product.version}/${config.stage}/${config.node}/node.properties "System-properties-mode="FALLBACK"/><context:annotation-config/> <context:component-scan base-package="Spring"/></Beans> |
Yaml
YAML (/ˈjæməl/, subharmonic resembles Camel camel) is a highly readable format used to express data sequences. Clark Evans first published the language in 2001, and Ingy Döt net and Oren Ben-kiki are also common designers of the language. There are currently several programming languages or scripting languages that support (or parse) this language.
YAML is a recursive abbreviation for "Yaml Ain ' t a Markup Language" (Yaml is not a markup language). In developing this language, the meaning of YAML is actually: "Yet another Markup Language" (still a markup language, but in order to emphasize that the language is centered on data, instead of focusing on markup language, it is renamed with reverse abbreviations.)
Yaml's syntax is similar to other high-level languages, and it can simply express data patterns such as lists, hash lists, and scalars. It uses whitespace notation indentation and a large number of dependent appearances, which are more appropriate for expressing hierarchical data structures.
YAML 1.2 is a superset of the JSON format.
https://github.com/prometheus/prometheus/blob/master/config/testdata/conf.good.yml
123456789101112131415161718192021 |
# My global configglobal:scrape_interval:15s evaluation_interval:30s # Scrape_timeout is set to the global Defaul T (10s). External_labels:monitor:codelab foo:barrule_files:-< span class= "Ruby" > "First.rules" - "My/*.rules" remote_write:- url: http: //remote1/push write_relabel_configs:- source_labels: [__name__ ] regex: expensive.* action:drop- url: http://remote2/push |
TOML Https://zh.wikipedia.org/wiki/TOML
TOML is designed to be a small-scale, easy-to-use, semantic configuration file format that is designed to convert to a hash table without ambiguity.
The name "TOML" is the initials of Tom's obvious, Minimal Language (Tom's Plain, minimalist language). "Tom" refers to its author Tom Preston-werner.
TOML is already in use in some software engineering and can be executed in many programming languages.
The grammar of TOML is broadly composed of key = "value"
, [节名]
and #注释
constituted.
It supports the following data types: string, shape, float, Boolean, datetime, array, and chart.
123456789101112131415161718192021222324252627282930313233 |
# This is a TOML document.title = "TOML Example"[owner]name = "Tom Preston-werner"DOB = 1979- to- -T07: +:xx- ,:xx # First Class dates[Database]Server = "192.168.1.1"ports =[8001,8001,8002]Connection_max = theenabled = true[Servers]# Indentation (tabs and/or spaces) is allowed and not required[Servers.alpha]IP = "10.0.0.1" DC = "EQDC10"[Servers.beta]IP = "10.0.0.2" DC = "EQDC10"[Clients]data =[ ["Gamma","Delta"], [1,2] ]# line breaks is OK when inside arrayshosts =["Alpha","Omega"] |
Hocon
Hocon, full name human-optimized Config object Notation (humanized representation) is a human-readable data format and a superset of JSON and properties. It is developed by Lightbend (known to people in Scala) and is primarily used in conjunction with the play framework. It is also used as a configuration format in puppet.
It's basically Scala's official development, so it's used in some Scala projects. Because it is a superset of the JSON and properties formats, it has a more flexible format.
The format definition can refer to the official documentation: Hocon.
Here is an example of it:
Https://github.com/marcospereira/play-i18n-hocon/blob/master/samples/scala/conf/application.conf
12345678910111213 |
Play.http.secret.key = "Changeme" play.modules { # Disable built-in i18n module disabled + = Play.api.i18n.I18nModule # Enable Hocon module enabled + = Com.marcospereira.play.i18n.HoconI18nModule} play.i18n { langs = ["en"]} |
Plist
In OS X's Cocoa,nextstep and GNUstep programming framework, the property list file is a file used to store the serialized object. The file name extension for the property list file is. plist, so it is commonly referred to as a plist file.
plist files are typically used to store user settings or to store bundled information, which is provided by the resource branch in the Legacy Mac OS.
https://github.com/wahlmanj/com.plex.pms.plist/blob/master/com.plex.pms.plist
1234567891011121314151617181920212223 |
<?xml version= "1.0" encoding= "UTF-8"?><! DOCTYPE plist Public "-//apple computer//dtd plist 1.0//en""Http://www.apple.com/DTDs/PropertyList-1.0.dtd" ><plist version="1.0"><dict><key>Label</key><string>Com.plex.pms</string><key>KeepAlive</key><true/><key>Programarguments</key><array><string>/applications/plex\ Media\ server.app/contents/macos/plex\ Media\ Server</string></array><key>Runatload</key><true/><key>UserName</key><string>__username__</string><key>WorkingDirectory</key><string>/applications</string><key>ServiceDescription</key><string>Pms</string></dict></plist> |