Method for acquiring configuration information, electronic device, and medium
By setting up a parameter replacement module in the front-end service and using environment variables to automatically replace configuration information, it solves the problem of high management costs and code quality assurance when the running environment of the front-end service changes, and achieves automatic configuration and efficient and accurate replacement of configuration information.
Patent Information
- Application Number
- PCT/CN2024/079354
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-04-27
- Filing Date
- 2024-02-29
- Publication Date
- 2024-10-31
AI Technical Summary
When the front-end service operating environment changes, the existing technology requires manual resetting and packaging of server address information, resulting in high management costs and inability to guarantee code quality.
By setting up a parameter replacement module in the front-end service and using environment variables to automatically replace configuration information, manual participation is reduced and configuration efficiency and accuracy are improved.
It realizes the automatic configuration of front-end services in the new environment, reduces management costs, improves the accuracy of configuration information, and avoids the complexity of manual configuration.
Smart Images

Figure CN2024079354_31102024_PF_FP_ABST
Abstract
Description
Method, electronic device and medium for obtaining configuration information
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on April 27, 2023, with application number 202310475856.3 and application name “A method, electronic device and medium for obtaining configuration information”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The present application relates to the field of computer technology, and in particular to a method, electronic device, and medium for obtaining configuration information. Background Art
[0003] Front-end services are the front-end components of a website, running on client browsers and displaying web pages to users. These services require different configuration information (parameters that support them) when running in different environments. These services can request the configuration information required by the environment using an Application Programming Interface (API), based on the address of a back-end server or a third-party server.
[0004] Currently, the address information of the backend server or third-party server corresponding to the front-end service operating environment is generally set in the front-end service code and packaged and compiled. When the client starts the front-end service, the front-end service requests to read the configuration information required for the operating environment through the API based on the address information of the backend server or third-party server in the packaged content. However, when adding or changing the operating environment (for example, after the front-end service completes testing in the test operating environment, it needs to be accepted in the acceptance environment, and the environment has changed at this time), the address information of the backend server or third-party server corresponding to the added or changed environment needs to be set in the code again and repackaged. At this time, due to the change in the packaged content, the information generated by the package compilation, such as the digest (Message-Digest Algorithm 5, MD5) code and the secure hash (Secure Hash Algorithm, SHA) code, will also change accordingly. If the front-end service code is modified, the MD5 code and SHA code generated by the package compilation will also change accordingly. Therefore, it is impossible to determine whether there is any change in the front-end service code, that is, the quality of the repackaged front-end service code cannot be guaranteed.
[0005] To solve the above problems, some solutions propose to separate the configuration information from the front-end service code and manually configure the configuration information required for the front-end service when adding or changing the operating environment. This will increase the manual management cost.
[0006] Summary of the Invention
[0007] In order to solve the above-mentioned problem of manually configuring the configuration information required for the front-end service, which will increase the labor management cost, the first aspect of the embodiment of the present application provides a method for obtaining configuration information, which includes obtaining the publishing environment of the front-end service; determining the first configuration information based on the publishing environment of the front-end service; writing the first configuration information into the first environment variable information of the front-end service running container, and obtaining the second environment variable information; when the front-end service is started in the publishing environment, the second configuration information in the configuration file of the front-end service is replaced with the first configuration information based on the second environment variable information.
[0008] Based on the above solution, when the front-end service is started in a new environment, the configuration information that matches the current environment can be automatically replaced with the existing configuration information without manual configuration. This can reduce management costs, improve configuration efficiency, and improve the configuration accuracy of the front-end service configuration information.
[0009] In some optional instances, the method further includes: setting a parameter replacement module in the front-end service;
[0010] Replacing the second configuration information in the configuration file of the front-end service with the first configuration information based on the second environment variable information includes: running the parameter replacement module in the front-end service; using the parameter replacement module to read the second environment variable information, and replacing the second configuration information in the configuration file of the front-end service with the first configuration information based on the second environment variable information.
[0011] In some optional instances, replacing the second configuration information in the configuration file of the front-end service with the first configuration information based on the second environment variable information includes: obtaining the first configuration information from the second environment variable information; and replacing the second configuration information in the configuration file of the front-end service with the first configuration information.
[0012] In some optional instances, determining the first configuration information based on the publishing environment of the front-end service includes: acquiring the first configuration information based on an operating environment identifier corresponding to the publishing environment of the front-end service.
[0013] In some optional instances, obtaining the first configuration information based on the operating environment identifier corresponding to the publishing environment of the front-end service includes: determining the operating environment identifier corresponding to the publishing environment of the front-end service; and determining the configuration information matching the operating environment identifier as the first configuration information.
[0014] In some optional instances, the method further includes: presetting configuration information corresponding to different operating environments on the deployment platform.
[0015] In some optional instances, the operating environment includes a development environment, a test environment, and a production environment.
[0016] In some optional instances, writing the first configuration information into the first environment variable information of the front-end service running container and obtaining the second environment variable information includes: replacing the configuration information in the first environment variable information of the front-end service running container with the first configuration information and obtaining the second environment variable information.
[0017] In some optional instances, the method further includes: sending a request to the second electronic device based on the current domain name of the front-end service and the first configuration information, and obtaining response data from the second electronic device.
[0018] In some optional instances, the response data of the server response may include files and / or pictures.
[0019] In a second aspect, an embodiment of the present application provides an electronic device, comprising: a memory for storing instructions executed by one or more processors of the electronic device, and a processor, which is one of the one or more processors of the electronic device, for executing the method for obtaining configuration information mentioned in the present application.
[0020] In a third aspect, an embodiment of the present application provides a readable storage medium, on which instructions are stored. When the instructions are executed on an electronic device, the electronic device executes the method for obtaining configuration information mentioned in the present application.
[0021] In a fourth aspect, an embodiment of the present application provides a computer program product, which includes instructions for implementing the method for obtaining configuration information mentioned in the embodiment of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] FIG1 is a schematic diagram of an application scenario provided by an embodiment of the present application;
[0023] FIG2 is a schematic diagram of a method for obtaining configuration information provided in an embodiment of the present application;
[0024] FIG3 is a schematic diagram of the structure of an apparatus for obtaining configuration information provided in an embodiment of the present application;
[0025] FIG4 is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application for implementing the method for obtaining configuration information provided in an embodiment of the present application. DETAILED DESCRIPTION
[0026] The illustrative embodiments of the present application include but are not limited to a method, an electronic device, and a medium for obtaining configuration information.
[0027] In order to solve the above problems, the present application provides a method for obtaining configuration information. The server can first preset the configuration information corresponding to different environments, and preset different operating environment identifiers to identify different operating environments, such as production environments or development environments. At the same time, a parameter replacement module can be set in the front-end service. When the publishing platform of the server publishes the front-end service, the publishing environment of the front-end service is determined, and the configuration information corresponding to the publishing environment is obtained. When the front-end service is started on the server, the parameter replacement module in the front-end service is run to read the environment variable information in which the configuration information has been written, thereby obtaining the configuration information written in the environment variable information. In this way, when the front-end service is started in a new operating environment, the configuration information that matches the current operating environment can be automatically replaced with the existing configuration information. There is no need for manual participation in the configuration, which can reduce management costs, improve configuration efficiency, and improve the configuration accuracy of the configuration information of the front-end service.
[0028] In some instances, the operating environment of the front-end service can be determined based on the operating environment identifier. Specifically, if the operating environment identifier is prod, it means that the operating environment of the service is the production environment. If the operating environment identifier is dev, it means that the operating environment of the service is the development environment.
[0029] Figure 1 is a schematic diagram of an application scenario provided by an embodiment of the present application. As shown in Figure 1, in a specific implementation, the server 110 can replace the configuration information in the configuration file of the front-end service with the configuration information 111 that matches the operating environment. When the front-end service is started in the new operating environment corresponding to the client 120, it can send a request to the server 110 and obtain response data of the server 110 based on the response to the sent request.
[0030] The following is a detailed description of the method for obtaining configuration information mentioned in the embodiment of the present application. Figure 2 is a schematic diagram of a method for obtaining configuration information provided in an embodiment of the present application. The method for obtaining configuration information shown in Figure 2 can be executed by an electronic device, which can be a server.
[0031] As shown in FIG2 , the method for obtaining configuration information may include:
[0032] 201: Preset configuration information corresponding to different operating environments on the deployment platform.
[0033] It is understandable that the development process of the front-end service may include stages such as development, testing, and production, and the operating environment of the server used in each stage of the development process is different. For example, the operating environment of the server used by the front-end service in the development stage is the development environment, the operating environment of the server used in the testing stage is the testing environment, and the operating environment of the server used in the production stage is the production environment. Among them, the development environment can be a Windows development environment or a Linux development environment. In the actual development process, the front-end service may also include other stages, and accordingly, may also include other operating environments, which are not specifically limited in the embodiments of the present application.
[0034] It is understood that the configuration information corresponding to different operating environments may have different operating environment identifiers. The operating environment identifier may indicate the operating environment of the server used by the front-end service. That is, the operating environment of the front-end service can be determined based on the operating environment identifier. For example, if the operating environment identifier is dev, it may indicate that the server's operating environment is the development environment. If the operating environment identifier is test, it may indicate that the server's operating environment is the test environment. If the operating environment identifier is prod, it may indicate that the server's operating environment is the production environment.
[0035] In order to ensure that the front-end service can run normally in any operating environment, the configuration information corresponding to different operating environments can be preset on the deployment platform. For example, the development environment can be preset with the operating environment identifier dev, and the configuration information corresponding to the development environment can be preset as "GOOGLE_ANALYTICS_ID": "google001". The test environment can be preset with the operating environment identifier test, and the configuration information corresponding to the test environment can be preset as "GOOGLE_ANALYTICS_ID": "google002". The production environment can be preset with the operating environment identifier prod, and the configuration information corresponding to the production environment can be preset as "GOOGLE_ANALYTICS_ID": "google003".
[0036] 202: Set up the parameter replacement module in the front-end service.
[0037] It is understandable that a startup script language (shell) can be added to the front-end service as a parameter replacement module. The script language can replace the configuration information in the configuration file of the front-end service, wherein the configuration file can be set in the file format of config.json.
[0038] It can be understood that when starting the front-end service, the parameter replacement module can be run, and the parameter replacement module can be used to read the environment variable information corresponding to the front-end service running environment, and the configuration information in the configuration file of the front-end service can be replaced with the configuration information in the read environment variable information with the help of the replacement command, that is, the configuration information in the configuration file of the front-end service is replaced with the configuration information in the environment variable information that matches the running environment of the front-end service.
[0039] 203: Obtain first configuration information corresponding to the publishing environment of the front-end service, write the first configuration information into first environment variable information of the front-end service running container, and obtain second environment variable information.
[0040] It is understood that when a publishing platform publishes a front-end service, it can determine the publishing environment of the front-end service and obtain first configuration information corresponding to the publishing environment. For example, it can obtain an operating environment identifier corresponding to the publishing environment, and then, based on the operating environment identifier, it can determine first configuration information that matches the operating environment identifier of the publishing environment from configuration information preset on the configuration platform.
[0041] In some optional instances, when the publishing environment of the front-end service is a development environment, the operating environment identifier dev corresponding to the development environment can be obtained, and then the first configuration information {"GOOGLE_ANALYTICS_ID":"google001"} that matches the operating environment identifier dev of the development environment can be determined from the configuration information preset in the configuration platform based on the operating environment identifier dev.
[0042] In some optional instances, when the publishing environment of the front-end service is a test environment, the operating environment identifier test corresponding to the test environment can be obtained, and then the first configuration information {"GOOGLE_ANALYTICS_ID":"google002"} that matches the operating environment identifier test of the test environment can be determined from the configuration information preset in the configuration platform based on the operating environment identifier test.
[0043] In some optional instances, when the publishing environment of the front-end service is a production environment, the operating environment identifier prod corresponding to the production environment can be obtained, and then the first configuration information {"GOOGLE_ANALYTICS_ID":"google003"} that matches the operating environment identifier prod of the production environment can be determined from the configuration information preset in the configuration platform based on the operating environment identifier prod.
[0044] 204: When the front-end service is started in the publishing environment, the parameter replacement module is run to replace the second configuration information in the configuration file of the front-end service with the first configuration information.
[0045] It can be understood that when the front-end service is started in the release environment, since a parameter replacement module is set in the front-end service, when the front-end service is started, the parameter replacement module in the front-end service can be run, and the parameter replacement module is used to read the second environment variable information of the front-end service running container, and then the second configuration information in the configuration file of the front-end service is replaced with the first configuration information in the second environment variable information with the help of the replacement command, so that the front-end service can run normally in the release environment.
[0046] In some optional implementations, when the publishing environment of the front-end service is a test environment, the second configuration information in the parameter replacement module in the front-end service is configuration information that matches the development environment. If the front-end service is started in the test environment, the parameter replacement module can be run to replace the second configuration information that matches the development environment in the configuration file of the front-end service with the first configuration information that matches the test environment with the help of a replacement command.
[0047] In some optional implementations, when the publishing environment of the front-end service is the production environment, the second configuration information in the parameter replacement module in the front-end service is the configuration information that matches the test environment. If the front-end service is started in the production environment, the parameter replacement module can be run to replace the second configuration information that matches the test environment in the configuration file of the front-end service with the first configuration information that matches the production environment with the help of the replacement command.
[0048] In some optional implementations, when the publishing environment of the front-end service is a development environment, the second configuration information in the parameter replacement module in the front-end service is configuration information that matches the production environment. If the front-end service is started in the development environment, the parameter replacement module can be run to replace the second configuration information that matches the production environment in the configuration file of the front-end service with the first configuration information that matches the development environment with the help of a replacement command.
[0049] It can be understood that after replacing the second configuration information in the front-end service with the first configuration information in the second environment variable information, when the client runs the front-end service, it can send a request to the server through the current domain name + parameter replacement module, and obtain the files and / or pictures based on the server's response to the request.
[0050] The method for obtaining configuration information provided in the embodiment of the present application is adopted. By setting a parameter replacement module in the front-end service, when the front-end service is started, the parameter replacement module in the front-end service is run to read the environment variable information in which the configuration information has been written, thereby obtaining the configuration information written in the environment variable information. In this way, when the front-end service is started in a new environment, the configuration information that matches the current environment can be automatically replaced with the existing configuration information. There is no need for manual configuration, which can reduce management costs, improve configuration efficiency, and improve the configuration accuracy of the configuration information of the front-end service.
[0051] The present application embodiment provides a device for obtaining configuration information. FIG3 is a schematic diagram of the structure of the device for obtaining configuration information provided by the present application embodiment. As shown in FIG3, the device for obtaining configuration information may include:
[0052] The first acquisition module 301 is used to obtain the publishing environment of the front-end service;
[0053] A determination module 302 is configured to determine first configuration information based on a publishing environment of a front-end service;
[0054] The second acquisition module 303 is used to write the first configuration information into the first environment variable information of the front-end service running container and obtain the second environment variable information;
[0055] The replacement module 304 is configured to replace the second configuration information in the front-end service configuration file with the first configuration information based on the second environment variable information when the front-end service is started in the publishing environment.
[0056] This embodiment is an apparatus embodiment corresponding to the above-mentioned method embodiment, and this embodiment can be implemented in conjunction with the method embodiment. The relevant technical details mentioned in the method embodiment are still valid in this embodiment and are not repeated here to reduce repetition. Accordingly, the relevant technical details mentioned in this embodiment can also be applied to the method embodiment.
[0057] An embodiment of the present application provides an electronic device, which includes a processor and a memory, wherein the memory stores at least one instruction or at least one program, and the at least one instruction or the at least one program is loaded and executed by the processor to implement the method for obtaining configuration information provided in the above method embodiment.
[0058] FIG4 is a schematic diagram of the hardware structure of an electronic device for implementing the method for obtaining configuration information provided by an embodiment of the present application. As shown in FIG4 , the electronic device may include one or more (401a and 401b are used in the figure to illustrate) processors 401 (the processor 401 may include but is not limited to processing devices such as a microprocessor MCU or a programmable logic device FPGA), a memory 402 for storing data, and a transmission device 403 for a communication function. In addition, it may also include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface and / or a power supply. It will be understood by those skilled in the art that the structure shown in FIG4 is only for illustration, and it does not limit the structure of the above-mentioned electronic device. For example, the electronic device may also include more or fewer components than those shown in FIG4 , or have a configuration different from that shown in FIG3 .
[0059] It should be noted that the one or more processors 401 and / or other data processing circuits described above may generally be referred to as "data processing circuits" in this application. The data processing circuit may be embodied in whole or in part as software, hardware, firmware, or any other combination thereof. In addition, the data processing circuit may be a single independent processing module, or may be incorporated into any of the other components of the electronic device (or mobile device) in whole or in part. As described in the embodiments of the present application, the data processing circuit acts as a processor 401 control (e.g., selection of a variable resistor terminal path connected to an interface).
[0060] The memory 402 can be used to store software programs and modules of application software, such as the program instructions / data storage device corresponding to the method for obtaining configuration information in the embodiment of the present application. The processor 401 implements the above-mentioned method for obtaining configuration information by running the software programs and modules stored in the memory 402 without executing various functional applications and data processing. The memory 402 may include a high-speed random access memory, and may also include a non-volatile random access memory, such as one or more magnetic storage devices, flash memory or other non-volatile solid-state memory. In some optional embodiments, the memory 402 may further include a memory remotely set relative to the processing, and these remote memories can be connected to electronic devices via a network. Examples of the above-mentioned network include but are not limited to the Internet, an intranet, a local area network, a mobile communication network and a combination thereof.
[0061] The transmission device 403 is used to receive or send data via a network. Specific embodiments of the aforementioned network may include a wireless network provided by a communications provider of the electronic device. In some optional embodiments, the transmission device 403 includes a network interface controller (NIC), which can be connected to other network devices via a base station to communicate with the Internet. In some optional embodiments, the transmission device 403 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.
[0062] The display may be, for example, a touch screen liquid crystal display (LED) that may enable a user to interact with a user interface of the electronic device (or mobile device).
[0063] An embodiment of the present application provides a computer-readable storage medium, which can be set in an electronic device to store at least one instruction or at least one program related to the method for obtaining configuration information in the method embodiment. The at least one instruction or the at least one program is loaded and executed by the processor to implement the method for obtaining configuration information provided by the above method embodiment.
[0064] Optionally, in an embodiment of the present application, the storage medium may be located in at least one of a plurality of network servers in a computer network. Optionally, the storage medium may include, but is not limited to, a USB flash drive, a read-only memory (ROM), a random access memory (RAM), a mobile hard drive, a magnetic disk, or an optical disk, among other media capable of storing program code.
[0065] It should be noted that in the examples and description of this patent, relational terms such as first and second, etc. are merely used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "comprise", "include" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device comprising a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. Without further limitation, an element defined by the phrase "comprising a" does not exclude the presence of other identical elements in the process, method, article or device comprising the element. Although the present application has been illustrated and described with reference to certain preferred embodiments of the present application, it should be understood by those skilled in the art that various changes may be made thereto in form and detail without departing from the spirit and scope of the present application.
[0066] It should be noted that the order of the embodiments of the present application described above is for description only and does not represent the advantages and disadvantages of the embodiments. Moreover, the above describes specific embodiments, and other embodiments are also within the scope of the appended claims. In some cases, the actions or steps described in the claims can be performed in the order of different embodiments and can achieve the expected results. In addition, the processes depicted in the drawings do not necessarily require showing a specific order or connecting order to achieve the desired results. In some embodiments, multi-tasking parallel processing is also possible or may be advantageous.
[0067] The various embodiments in this application are described in a progressive manner. References to the same or similar parts between the various embodiments are sufficient. Each embodiment focuses on the differences between the other embodiments. In particular, the embodiments of the electronic device, storage medium, and computer program product are described more simply because they are based on similarities to the method embodiments. For relevant details, references to the description of the method embodiments are sufficient.
[0068] It should be pointed out that for ordinary technicians in this field, several improvements and modifications can be made without departing from the principles of the present invention, and these improvements and modifications are also considered to be within the scope of protection of this application.
Claims
1. A method for obtaining configuration information, characterized in that: The method is applied to a first electronic device, and the method includes: Get the publishing environment of the front-end service; Determine first configuration information based on the publishing environment of the front-end service; Writing the first configuration information into the first environment variable information of the front-end service running container, and obtaining the second environment variable information; When the publishing environment is started, the front-end service replaces the second configuration information in the configuration file of the front-end service with the first configuration information based on the second environment variable information.
2. The method according to claim 1, characterized in that The method further comprises: Setting a parameter replacement module in the front-end service; The replacing the second configuration information in the configuration file of the front-end service with the first configuration information based on the second environment variable information includes: Running the parameter replacement module in the front-end service; The parameter replacement module is used to read the second environment variable information, and the second configuration information in the configuration file of the front-end service is replaced with the first configuration information based on the second environment variable information.
3. The method according to claim 2, characterized in that The replacing the second configuration information in the configuration file of the front-end service with the first configuration information based on the second environment variable information includes: Acquire the first configuration information from the second environment variable information; The second configuration information in the configuration file of the front-end service is replaced with the first configuration information.
4. The method according to claim 1, characterized in that: The determining the first configuration information based on the publishing environment of the front-end service includes: The first configuration information is obtained based on the operating environment identifier corresponding to the publishing environment of the front-end service.
5. The method according to claim 4, characterized in that The acquiring the first configuration information based on the operating environment identifier corresponding to the publishing environment of the front-end service includes: Determine the operating environment identifier corresponding to the publishing environment of the front-end service; The configuration information matching the operating environment identifier is determined as the first configuration information.
6. The method according to claim 5, characterized in that The method further comprises: Preset configuration information corresponding to different operating environments on the deployment platform.
7. The method according to claim 6, characterized in that The operating environment includes a development environment, a test environment and a production environment.
8. The method according to claim 1, characterized in that The step of writing the first configuration information into the first environment variable information of the front-end service running container and obtaining the second environment variable information includes: The configuration information in the first environment variable information of the front-end service running container is replaced with the first configuration information, and the second environment variable information is obtained.
9. The method according to claim 1, characterized in that: The method further comprises: A request is sent to a second electronic device based on the current domain name of the front-end service and the first configuration information, and response data of the second electronic device is obtained.
10. The method according to claim 9, characterized in that The response data includes: files and / or pictures.
11. An electronic device, characterized in that: include: A memory, used to store instructions executed by one or more processors of the electronic device, and the processor, which is one of the one or more processors of the electronic device, is used to execute the method for obtaining configuration information described in any one of claims 1-10.
12. A readable storage medium, characterized in that: The readable medium stores instructions, and when the instructions are executed on an electronic device, the electronic device executes the method for acquiring configuration information according to any one of claims 1 to 10.
13. A computer program product, characterized in that The computer program product comprises instructions, and the instructions are used to implement the method for acquiring configuration information according to any one of claims 1 to 10.
Citation Information
Patent Citations
Running environment switching method and device and computer-readable storage medium
CN107861863A
Environment switching method and device, terminal device and storage medium
CN109828779A
Method and device for realizing back-end environment variable replacement, equipment and medium
CN113778549A
Service deployment method and device, computer equipment and storage medium
CN115185550A
Method for acquiring configuration information, electronic equipment and medium
CN116483470A
