Search

CN-114995869-B - Configuration file analysis method, device, equipment and medium

CN114995869BCN 114995869 BCN114995869 BCN 114995869BCN-114995869-B

Abstract

The application discloses a configuration file analysis method, device, equipment and medium, which comprise the steps of analyzing a configuration file to obtain a target key-value key value pair in the configuration file, judging the data type of the value in the target key-value key value pair, determining a multi-level key-value pair corresponding to the target key-value key value from a storage medium if the data type of the value is an object type, analyzing the father-son relationship of each key-value pair in the multi-level key-value pair, determining a combined value based on the father-son relationship, and modifying the value in the target key-value pair to be the combined value. Therefore, the accurate and efficient analysis and assignment of the configuration file can be ensured.

Inventors

  • LI RUIHAN

Assignees

  • 济南浪潮数据技术有限公司
  • 济南浪潮数据技术有限公司

Dates

Publication Date
20260421
Application Date
20220531
Priority Date
20220531

Claims (8)

  1. 1. A method for parsing a configuration file, comprising: analyzing the configuration file to obtain a target key-value key value pair in the configuration file; judging the data type of the value in the target key-value key pair; If the data type of the value is an object type, determining a multi-level key-value key value pair corresponding to the target key-value key value from a storage medium; analyzing father-son relations of each key-value key value pair in the multi-level key-value key value pairs, and determining a combined value based on the father-son relations; modifying the value in the target key-value key value pair into the combined value; The method comprises the steps of determining a multi-level key-value pair corresponding to the target key-value key value from a storage medium, wherein the multi-level key-value pair corresponding to the target key-value key value is determined from the storage medium based on the key value in the target key-value key value pair, and the key value of the highest level in the multi-level key-value pair is the same as the key value in the target key-value pair; The method comprises the steps of analyzing father-son relations of each key-value key pair in the multi-level key-value pair, determining a combined value based on the father-son relations, determining a root node in the multi-level key-value pair, searching a child node of the root node, assigning the key-value pair of the child node to a key of the root node as an object if the child node does not have the child node, continuing to judge the father-son relations until the node without the child node is found, and determining the combined value based on the father-son relations of each key-value pair, wherein the value of the final root node is formed by combining all the child nodes and the grandchild node or the key-value of great grandson nodes.
  2. 2. The method for parsing a configuration file according to claim 1, wherein parsing the configuration file to obtain a target key-value key pair in the configuration file includes: And analyzing the configuration file based on the anti-serialization function to obtain a target key-value key value pair in the configuration file.
  3. 3. The method for parsing a configuration file according to claim 1, wherein after modifying the value in the target key-value key pair to the combined value, the method further comprises: and carrying out serialization operation on the modified target key-value key value pair based on the serialization function to obtain a new configuration file.
  4. 4. The profile parsing method according to claim 1, wherein if the data type of the value in the target key-value key pair is a scalar or an array, further comprising: Searching a key-value key value pair which is the same as the key value in the target key-value key value pair in the storage medium; and modifying the value in the target key-value key value pair into the value in the searched key-value key value pair.
  5. 5. The method for parsing a configuration file according to any one of claims 1 to 4, further comprising, after parsing the configuration file to obtain a target key-value key pair in the configuration file: the value in the target key-value key value pair is used as a character string type to be stored; Correspondingly, the judging the data type of the value in the target key-value key pair includes: And judging the data type of the value in the target key-value key pair based on the saved value.
  6. 6. A profile parsing apparatus, comprising: the configuration file analysis module is used for analyzing the configuration file to obtain a target key-value key value pair in the configuration file; the data type judging module is used for judging the data type of the value in the target key-value key pair; the multi-level key-value pair determining module is used for determining a multi-level key-value pair corresponding to the target key-value key value from a storage medium if the data type of the value is an object type; The combined value determining module is used for analyzing the father-son relationship of each key-value key value pair in the multi-level key-value key value pairs and determining a combined value based on the father-son relationship; the value modification module is used for modifying the value in the target key-value key value pair into the combined value; the method comprises the steps of determining a multi-level key-value key value pair corresponding to a target key-value key value from a storage medium, wherein the multi-level key-value key value pair corresponding to the target key-value key value pair is determined from the storage medium based on the key value in the target key-value key value pair, and the key value of the highest level in the multi-level key-value key value pair is identical to the key value in the target key-value key value pair; Analyzing father-son relations of each key-value key value pair in the multi-level key-value pair, determining a combined value based on the father-son relations, determining a root node in the multi-level key-value pair, searching a child node of the root node, if the child node does not have the child node, assigning the key-value pair of the child node as an object to the key of the root node, if the child node has the child node, continuing to perform father-son relation judgment until a node without the child node is found, determining the combined value based on the father-son relations of each key-value pair, and finally combining the value of the root node by all the child nodes and the grandchild node or the key-value of great grandson nodes.
  7. 7. An electronic device comprising a memory and a processor, wherein: The memory is used for storing a computer program; the processor is configured to execute the computer program to implement the configuration file parsing method according to any one of claims 1 to 5.
  8. 8. A computer readable storage medium for storing a computer program, wherein the computer program when executed by a processor implements the profile parsing method of any one of claims 1 to 5.

Description

Configuration file analysis method, device, equipment and medium Technical Field The present application relates to the field of configuration file analysis technologies, and in particular, to a configuration file analysis method, device, equipment, and medium. Background Configuration files are important file types in project applications, and any program needs to have definition and parsing of the configuration files. Such as the common json, ini, property, yml, etc. file types. Wherein yml is a format with high readability and easy understanding for expressing data serialization, and the data structure adopts the form of key value pairs. The key-value key value pair is a data structure commonly used in configuration files, and has a corresponding data structure and built-in functions for java, python, golang languages. Whether the assignment configuration items are resolved correctly or not determines whether the configuration variables can be read correctly or not, whether the program can execute correctly or not, and particularly resolving and assigning complex nested configuration items in the configuration file are important contents in the configuration file resolving process. How to guarantee accurate and efficient parsing of configuration files containing complex nested configuration items is a current urgent problem to be solved. Disclosure of Invention In view of the above, the present application aims to provide a method, an apparatus, a device, and a medium for analyzing a configuration file, which can ensure that the configuration file is analyzed and assigned accurately and efficiently. The specific scheme is as follows: In a first aspect, the present application discloses a method for analyzing a configuration file, including: analyzing the configuration file to obtain a target key-value key value pair in the configuration file; judging the data type of the value in the target key-value key pair; If the data type of the value is an object type, determining a multi-level key-value key value pair corresponding to the target key-value key value from a storage medium; analyzing father-son relations of each key-value key value pair in the multi-level key-value key value pairs, and determining a combined value based on the father-son relations; and modifying the value in the target key-value key value pair into the combined value. Optionally, the determining, from the storage medium, the multi-level key-value pair corresponding to the target key-value pair includes: determining a multi-level key-value key value pair corresponding to the target key-value key value pair from the storage medium based on the key value in the target key-value key value pair; Wherein the key value of the highest level in the multi-level key-value pair is the same as the key value in the target key-value pair. Optionally, the analyzing the parent-child relationship of each key-value key pair in the multi-level key-value key-pair, and determining the combined value based on the parent-child relationship includes: Determining a root node in the multi-level key-value pair, And searching the child nodes of the root node, if the child nodes do not have child nodes, assigning key-value key value pairs of the child nodes as objects to the keys of the root node, if the child nodes have child nodes, continuing to judge the father-son relationship until the nodes without child nodes are found, and determining a combined value based on the father-son relationship of each key-value key value pair. Optionally, the parsing the configuration file to obtain a target key-value key value pair in the configuration file includes: And analyzing the configuration file based on the anti-serialization function to obtain a target key-value key value pair in the configuration file. Optionally, after modifying the value in the target key-value key pair to the combined value, the method further includes: and carrying out serialization operation on the modified target key-value key value pair based on the serialization function to obtain a new configuration file. Optionally, if the data type of the value in the target key-value key pair is scalar or array, the method further includes: Searching a key-value key value pair which is the same as the key value in the target key-value key value pair in the storage medium; and modifying the value in the target key-value key value pair into the value in the searched key-value key value pair. Optionally, after the parsing the configuration file to obtain the target key-value key value pair in the configuration file, the method further includes: the value in the target key-value key value pair is used as a character string type to be stored; Correspondingly, the judging the data type of the value in the target key-value key pair includes: And judging the data type of the value in the target key-value key pair based on the saved value. In a second aspect, the present application discloses a configuration file