CN112416383A - Hot updating method and device for golang program and computer equipment - Google Patents

Hot updating method and device for golang program and computer equipment Download PDF

Info

Publication number
CN112416383A
CN112416383A CN202010068077.8A CN202010068077A CN112416383A CN 112416383 A CN112416383 A CN 112416383A CN 202010068077 A CN202010068077 A CN 202010068077A CN 112416383 A CN112416383 A CN 112416383A
Authority
CN
China
Prior art keywords
program
golang
code segment
code
storage unit
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010068077.8A
Other languages
Chinese (zh)
Inventor
任运宜
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shanghai Bilibili Technology Co Ltd
Original Assignee
Shanghai Bilibili Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Bilibili Technology Co Ltd filed Critical Shanghai Bilibili Technology Co Ltd
Priority to CN202010068077.8A priority Critical patent/CN112416383A/en
Publication of CN112416383A publication Critical patent/CN112416383A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates

Abstract

The invention discloses a heat updating method for a golang program, which comprises the following steps: receiving a golang program updating request, and acquiring a first code segment corresponding to a target function in the updating request; adding the first code segment to a content store of a rules engine; calling the first code segment from the content storage unit to replace a second code segment corresponding to the target function according to an execution rule of the rule engine; executing a golang program comprising said first code segment. The invention also provides a golang program hot updating device, computer equipment and a computer readable storage medium. According to the method and the device, after the new code segment is added to the rule engine, the old code segment is converted into the new code segment according to the execution rule of the rule engine, so that the online updating of the golang program is realized, and the flexibility and the efficiency of the golang program updating are improved.

Description

Hot updating method and device for golang program and computer equipment
Technical Field
The invention relates to the technical field of golang program hot updating, in particular to a method, a device, computer equipment and a computer readable storage medium for golang program hot updating.
Background
Since the golang language is a static programming language, and after data of the golang language is stored in the storage unit, the storage position is determined and unchangeable, and therefore, a program written by the golang language has strong stability. However, for an application program requiring expansion capability, the feature of the golang language that is not changeable after storage can be expensive to implement for function expansion. For example, when the version of the application program in the golang language is upgraded, the application program needs to be stopped, and then the new code is written and executed, so that the new version application program is executed. That is, when an application program in the existing golang language is updated, the application program is generally updated after the service is stopped. Therefore, the efficiency is low and the flexibility is poor.
Disclosure of Invention
In view of this, the present invention provides a method, an apparatus, a computer device, and a computer readable storage medium for hot-updating a golang program, which can solve the problem that the golang program stops service during the updating process.
First, to achieve the above object, the present invention provides a method for hot-updating a golang program, the method comprising:
receiving a golang program updating request, and acquiring a first code segment corresponding to a target function in the updating request; adding the first code segment to a content store of a rules engine; calling the first code segment from the content storage unit to replace a second code segment corresponding to the target function according to an execution rule of the rule engine; executing a golang program comprising said first code segment.
In one example, the adding the first code segment to a content store of a rules engine comprises: analyzing the first code segment by an AST technology to obtain a corresponding executable code segment; adding the executable code segment to the content storage unit.
In one example, the obtaining the first code segment corresponding to the target function in the update request includes: comparing the code data corresponding to the golang program updating request with the code data of the previous version of the golang program in a text mode to find out a difference code; determining the first code segment included in the difference code segment according to a format of a code.
In one example, the execution rule includes: acquiring code segments of all versions corresponding to one function in the golang program in the content storage unit; searching the editing time of each version of code segment in all the versions of code segments; and selecting the code segment corresponding to the editing time with the minimum difference value with the current time for calling.
In one example, the rules engine further comprises an execution priority, and the golang program hot update method further comprises: acquiring type identifications of all code segments corresponding to the golang program in the content storage unit; and successively calling code segments corresponding to the golang program from the content storage unit according to the type identifier and the execution priority.
In one example, the type identifies code segments for identifying different sub-functions in the golang program; the type identifications of the code segments of different versions of the same sub-functionality are the same.
In one example, the rules engine is implemented by way of a syntax tree.
In order to achieve the above object, the present invention also provides a golang program hot-update apparatus including:
the device comprises an acquisition module, a processing module and a processing module, wherein the acquisition module is used for receiving a golang program updating request and acquiring a first code segment corresponding to a target function in the updating request; an adding module for adding the first code segment to a content storage unit of a rules engine; the calling module is used for calling the first code segment from the content storage unit to replace the second code segment corresponding to the target function according to the execution rule of the rule engine; an execution module for executing a golang program comprising said first code segment.
Further, the present invention also proposes a computer device, including a memory and a processor, where the memory stores a computer program operable on the processor, and the computer program, when executed by the processor, implements the steps of the above-mentioned golang program hot update method.
Further, to achieve the above object, the present invention also provides a computer-readable storage medium storing a computer program, which is executable by at least one processor to cause the at least one processor to perform the steps of the golang program thermal update method as described above.
Compared with the prior art, the method, the device, the computer equipment and the computer-readable storage medium for hot updating the golang program, provided by the invention, can obtain the first code segment corresponding to the target function in the update request after receiving the golang program update request; then adding the first code segment to a content storage unit of a rule engine, and calling the first code segment from the content storage unit to replace a second code segment corresponding to the target function according to an execution rule of the rule engine; finally, the golang program including said first code segment is executed. Through the mode, after the new code segment is added to the rule engine, the old code segment is converted into the new code segment according to the execution rule of the rule engine, so that the online updating of the golang program is realized, and the flexibility and the efficiency of the golang program updating are improved.
Drawings
FIG. 1 is a schematic diagram of an application environment of an embodiment of the present invention;
FIG. 2 is a schematic flow chart diagram illustrating a method for performing a hot update on a golang program according to an embodiment of the present invention;
FIG. 3 is a flowchart illustrating one embodiment of step S202 of FIG. 2;
FIG. 4 is a schematic flow chart based on another embodiment of FIG. 2;
FIG. 5 is a flow diagram of the application of the rules engine in an embodiment of the present invention;
FIG. 6 is a diagram of a rule engine architecture based on a syntax tree in an embodiment of the present invention;
FIG. 7 is a diagram of an alternative hardware architecture for the computer device of the present invention;
fig. 8 is a schematic diagram of program modules of an embodiment of the golang program hot-update apparatus according to the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
It should be noted that the description relating to "first", "second", etc. in the present invention is for descriptive purposes only and is not to be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature. In addition, technical solutions between various embodiments may be combined with each other, but must be realized by a person skilled in the art, and when the technical solutions are contradictory or cannot be realized, such a combination should not be considered to exist, and is not within the protection scope of the present invention.
Fig. 1 is a schematic diagram of an application environment according to an embodiment of the present invention. Referring to fig. 1, the computer device 1 is connected to a development platform, and after receiving a hot update request of a golang program sent by the development platform, may obtain a first code segment corresponding to a target function in the update request, and then add the first code segment to a content storage unit of a rule engine; then, the first code segment is called from the content storage unit to replace a second code segment corresponding to the target function according to the execution rule of the rule engine, so that the golang program comprising the first code segment is executed. In the present embodiment, the computer device 1 may be used as a terminal device such as a mobile terminal, e.g., a mobile phone, a tablet, a portable device, or a PC, a server, etc. In other embodiments, the computer device 1 may also be a stand-alone functional module, and then be attached to a mobile terminal such as a mobile phone, a tablet, or a portable device, or a PC or a server, so as to implement the function of hot update of the golang program. Of course, the computer device 1 may also provide an interactive interface, then receive a golang program update request input by a user through the interactive interface, and then obtain the first code segment corresponding to the target function in the update request from a storage unit of the computer device or an external device. And are not limiting herein.
Fig. 2 is a schematic flow chart of an embodiment of the heat updating method for the golang program of the present invention. It is to be understood that the flow charts in the embodiments of the present method are not intended to limit the order in which the steps are performed. The following description will exemplarily describe a computer device as an execution subject by taking the application environment shown in fig. 1 as an example.
As shown in fig. 2, the heat update method of the golang program may include steps S200 to S206, wherein:
step S200, receiving a golang program update request, and acquiring a first code segment corresponding to a target function in the update request.
Step S202, adding the first code segment to a content storage unit of a rules engine.
Specifically, the computer device 1 is connected to a development platform, and then, when the development platform updates a code of a golang program, a golang program update request is sent to the computer device 1, where the golang program update request includes code data, and the code data is a code of the golang program, and therefore includes a first code corresponding to an updated target function. After receiving the golang program update request, the computer device 1 obtains a first code segment corresponding to a target function in the golang program update request. In this embodiment, the obtaining the first code segment corresponding to the target function in the update request includes: comparing the code data corresponding to the golang program updating request with the code data of the previous version of the golang program in a text mode to find out a difference code; the first code segment included in the difference code segment is then determined according to the format of the code. Specifically, the computer device 1 may determine the first code segment corresponding to the target function updated this time by performing text comparison between the code data corresponding to the golang program update request and the code data of the previous version of the golang program, then finding out a difference code, and according to the format of the code, such as the minimum execution unit of the code and the format of the code function, finding out the function head and the function tail of the code function.
And after the computer equipment 1 acquires the first code segment, adding the first code segment into a content storage unit in a rule engine. In this embodiment, the rules engine is a system for managing and executing a golang program, for example, an application program constructed by a syntax tree, including a syntax tree constructed based on the golang language, or a syntax tree constructed based on another language such as JAVA, and is not limited herein. The rule engine is constructed in a syntax tree mode, and newly added code programs can be managed more flexibly and effectively. After the computer device 1 constructs the rule engine, it also provides sufficient storage units for the rule engine, including content storage units and other storage units. The content storage unit is used for storing execution codes related to the golang program, and other storage units are used for storing other data of the rule engine, such as system data, log data and other explanatory data of the rule engine.
Referring to FIG. 3, in an exemplary embodiment, step S202 may include steps S300-S302.
Step S300, parsing the first code segment by the AST technology to obtain a corresponding executable code segment.
Step S302, adding the executable code segment to the content storage unit.
Specifically, since the obtained code segment generally includes at least a plurality of code functions, for a first code segment including a plurality of code functions, an executable code segment therein needs to be parsed. In this embodiment, the computer device 1 sets an AST (Abstract Syntax Tree) parsing rule in advance according to a subdivision function of the golang program, and then parses the first code segment by using an AST technology, so as to parse an executable code segment corresponding to the first code segment. The technique of the AST analyzing the code segments is commonly used, and is not described herein. The computer device 1 parses the first code segment by the AST technique to obtain a corresponding executable code segment, and then adds the executable code to the content storage unit. By storing the executable code in the content storage unit, recompilation of the code can be omitted, and therefore, the efficiency of the golang program update is also improved.
Step S204, the first code segment is called from the content storage unit to replace the second code segment corresponding to the target function according to the execution rule of the rule engine.
In step S206, a golang program including the first code segment is executed.
Specifically, after the computer device 1 constructs the rule engine, an execution rule is further set, where the execution rule is used to describe and control a code segment corresponding to the golang program in the content storage unit according to what manner the rule engine executes. Therefore, after the computer device 1 adds the first code segment to the content storage unit in the rule engine, the computer device 1 will further call the first code segment from the content storage unit to replace the second code segment corresponding to the target function according to the execution rule.
In this embodiment, the execution rule includes: and acquiring code segments of all versions corresponding to one function in the golang program in the content storage unit, searching the editing time of each code segment of all versions, and selecting the code segment corresponding to the editing time with the minimum difference with the current time for calling. For example, when the a function in the golang program is updated currently for a total of 3 times, the content storage unit includes executable code segments corresponding to 3 versions of the a function. Then, the computer device 1 searches the edit time of the executable code of these 3 versions corresponding to the a function, such as T1, T2, and T3, according to the execution rule; and then calculating the difference values of T1, T2 and T3 and the current time respectively to obtain C1, C2 and C3, wherein C1> C2> C3. Then, the computer device 1 selects the executable code corresponding to T3 to call according to the execution rule. Through the time sequence, the code segment which is updated latest can be well selected and executed.
Referring to fig. 4, in an exemplary embodiment, the rule engine further includes an execution priority, and the golang program hot update method may further include steps S400 to S402 in addition to steps S200 to S206.
Step S400, obtaining the type identifiers of all code segments corresponding to the golang program in the content storage unit.
Step S402, successively calling code segments corresponding to the golang program from the content storage unit according to the type identifier and the execution priority.
Specifically, the computer device 1 sets a type identifier in advance for a code segment of each sub-function in the golang program, where the type identifier is used to identify code segments of different sub-functions in the golang program; the type identifications of the code segments of different versions of the same sub-functionality are the same. Therefore, when there are a plurality of target functions updated by the golang program, then, the computer device 1 may select a code segment with a type identifier corresponding to each target function according to the execution rule, and then sequentially execute the selected code segments to replace the original code segments with corresponding type identifiers according to the preset execution priority and the type identifier corresponding to each target function. Thus, an update of code segments that methodically implement multiple sub-functions may be achieved.
Please refer to fig. 5 and fig. 6, which are diagrams illustrating application effects in an embodiment of the present invention. Fig. 5 is a flowchart of application of the rule engine, and fig. 6 is a diagram of a rule engine architecture based on a syntax tree.
In this embodiment, after the computer device 1 inputs the executable code update request corresponding to the golang program update request to the rule engine, the rule engine may load the corresponding execution rule and then output the execution result. Specifically, when the rule engine is based on a syntax tree architecture, the rule engine may specifically include: a rule specification section and a rule execution section. The rule description part comprises a rule name, an execution rule and an execution priority, the rule name describes the name of the rule in the rule engine, the execution flow and the execution method of the rule engine described by the execution rule, and the execution priority describes the execution sequence of different code contents of the code content part. The rule execution part comprises a start, a code content and an end, the code content part storing executable code of sub-functions of the golang program. Therefore, the rule engine adds to the code content part after receiving the executable code, and then after "start", the rule engine selects the corresponding executable code from the "code content" according to the "execution rule" and the "execution priority" and executes until "end". In this embodiment, the rule engine based on syntax tree can support more encoding logic, such as If, else and nested function logic, and define variables in the rule, change function names in the rule, and complex four arithmetic operations.
As can be seen from the foregoing, the method for hot-updating a golang program according to this embodiment can obtain, after receiving a golang program update request, a first code segment corresponding to a target function in the update request; then adding the first code segment to a content storage unit of a rule engine, and calling the first code segment from the content storage unit to replace a second code segment corresponding to the target function according to an execution rule of the rule engine; finally, the golang program including said first code segment is executed. Through the mode, after the new code segment is added to the rule engine, the old code segment is converted into the new code segment according to the execution rule of the rule engine, so that the online updating of the golang program is realized, and the flexibility and the efficiency of the golang program updating are improved.
In addition, the present invention also provides a computer device, which is shown in fig. 7 and is a schematic diagram of an optional hardware architecture of the computer device of the present invention.
In this embodiment, the computer device 1 may include, but is not limited to, a memory 11, a processor 12, and a network interface 13, which may be communicatively connected to each other through a system bus. The computer device 1 is connected to a network (not shown in fig. 7) through a network interface 13, and is connected to other computer devices (not shown in fig. 7) through the network for data interaction. The network may be a wireless or wired network such as an Intranet (Intranet), the Internet (Internet), a Global System of Mobile communication (GSM), Wideband Code Division MultIPle Access (WCDMA), a 4G network, a 5G network, Bluetooth (Bluetooth), Wi-Fi, or a communication network.
It is noted that fig. 7 only shows the computer device 1 with components 11-13, but it is to be understood that not all shown components are required to be implemented, and that more or less components may be implemented instead.
The memory 11 includes at least one type of readable storage medium, which includes a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Read Only Memory (ROM), an Electrically Erasable Programmable Read Only Memory (EEPROM), a Programmable Read Only Memory (PROM), a magnetic memory, a magnetic disk, an optical disk, etc. In some embodiments, the storage 11 may be an internal storage unit of the computer device 1, such as a hard disk or a memory of the computer device 1. In other embodiments, the memory 11 may also be an external storage device of the computer device 1, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like provided in the computer device 1. Of course, the memory 11 may also comprise both an internal storage unit of the computer device 1 and an external storage device thereof. In this embodiment, the memory 11 is generally used for storing an operating system and various application software installed in the computer device 1, program codes of the golang program hot-update apparatus 200, and the like. Furthermore, the memory 11 may also be used to temporarily store various types of data that have been output or are to be output.
The processor 12 may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor, or other data Processing chip in some embodiments. The processor 12 is generally used for controlling the overall operation of the computer device 1, such as performing data interaction or communication related control and processing. In this embodiment, the processor 12 is configured to run the program code stored in the memory 11 or process data, for example, run an application program of the golang program hot-updating apparatus 200, which is not limited herein.
The network interface 13 may comprise a wireless network interface or a wired network interface, and the network interface 13 is typically used for establishing a communication connection between the computer device 1 and another computer device.
In this embodiment, when the golang program hot-updating apparatus 200 is installed and operated in the computer device 1, when the golang program hot-updating apparatus 200 is operated, after receiving a golang program updating request, the first code segment corresponding to the target function in the updating request can be acquired; then adding the first code segment to a content storage unit of a rule engine, and calling the first code segment from the content storage unit to replace a second code segment corresponding to the target function according to an execution rule of the rule engine; finally, the golang program including said first code segment is executed. Through the mode, after the new code segment is added to the rule engine, the old code segment is converted into the new code segment according to the execution rule of the rule engine, so that the online updating of the golang program is realized, and the flexibility and the efficiency of the golang program updating are improved.
The hardware structure and functions of the computer apparatus of the present invention have been described in detail so far. Hereinafter, various embodiments of the present invention will be proposed based on the above-described computer apparatus.
Fig. 8 is a block diagram of a golang program hot-update apparatus 200 according to an embodiment of the present invention.
In this embodiment, the golang program hot-update apparatus 200 includes a series of computer program instructions stored in the memory 11, and when the computer program instructions are executed by the processor 12, the golang program hot-update function of the embodiment of the present invention can be realized. In some embodiments, the golang program thermal update apparatus 200 may be divided into one or more modules based on the particular operations implemented by the various portions of the computer program instructions. For example, in fig. 8, the golang program hot-update apparatus 200 may be divided into an acquisition module 201, an addition module 202, a calling module 203, and an execution module 204. Wherein:
the obtaining module 201 is configured to receive a golang program update request, and obtain a first code segment corresponding to a target function in the update request.
The adding module 202 is configured to add the first code segment to a content storage unit of a rule engine.
Specifically, the computer device is connected to a development platform, and then, when the development platform updates a code of a golang program, a golang program update request is sent to the computer device, where the golang program update request includes code data, and generally, the code data is a code of the golang program, and therefore, the first code corresponding to an updated target function is also included. After receiving the golang program update request, the obtaining module 201 obtains the first code segment corresponding to the target function in the golang program update request. In this embodiment, the obtaining the first code segment corresponding to the target function in the update request includes: comparing the code data corresponding to the golang program updating request with the code data of the previous version of the golang program in a text mode to find out a difference code; the first code segment included in the difference code segment is then determined according to the format of the code. Specifically, the obtaining module 201 may perform text comparison on code data corresponding to the golang program update request and code data of a previous version of the golang program, then find out a difference code, and determine a first code segment corresponding to the target function updated this time by finding out a function header and a function trailer of the code function according to a format of the code, for example, a minimum execution unit of the code and a format of the code function.
After the obtaining module 201 obtains the first code segment, the adding module 202 adds the first code segment to a content storage unit in a rule engine. In this embodiment, the rules engine is a system for managing and executing a golang program, for example, an application program constructed by a syntax tree, including a syntax tree constructed based on the golang language, or a syntax tree constructed based on another language such as JAVA, and is not limited herein. The rule engine is constructed in a syntax tree mode, and newly added code programs can be managed more flexibly and effectively. After the computer device constructs the rule engine, sufficient storage units, including content storage units and other storage units, are provided for the rule engine. The content storage unit is used for storing execution codes related to the golang program, and other storage units are used for storing other data of the rule engine, such as system data, log data and other explanatory data of the rule engine.
In an exemplary embodiment, the adding module 202 parses the first code segment by the AST technology to obtain a corresponding executable code segment, and then adds the executable code segment to the content storage unit. Specifically, since the obtained code segment generally includes at least a plurality of code functions, for a first code segment including a plurality of code functions, an executable code segment therein needs to be parsed. In this embodiment, the adding module 202 sets an AST (Abstract Syntax Tree) parsing rule in advance according to a subdivision function of the golang program, and then parses the first code segment by using an AST technology, so as to parse an executable code segment corresponding to the first code segment. The technique of the AST analyzing the code segments is commonly used, and is not described herein. The adding module 202 parses the first code segment by the AST technique to obtain a corresponding executable code segment, and then adds the executable code to the content storage unit. By storing the executable code in the content storage unit, recompilation of the code can be omitted, and therefore, the efficiency of the golang program update is also improved.
The calling module 203 is configured to call the first code segment from the content storage unit according to the execution rule of the rule engine to replace the second code segment corresponding to the target function.
The executing module 204 is configured to execute a golang program including the first code segment.
Specifically, after the computer device constructs the rule engine, an execution rule is further set, where the execution rule is used to describe and control a code segment corresponding to the golang program in the content storage unit according to what manner the rule engine executes. Therefore, after the adding module 202 adds the first code segment to the content storage unit in the rule engine, the calling module 203 will further call the first code segment from the content storage unit to replace the second code segment corresponding to the target function according to the execution rule.
In this embodiment, the execution rule includes: and acquiring code segments of all versions corresponding to one function in the golang program in the content storage unit, searching the editing time of each code segment of all versions, and selecting the code segment corresponding to the editing time with the minimum difference with the current time for calling. For example, when the a function in the golang program is updated currently for a total of 3 times, the content storage unit includes executable code segments corresponding to 3 versions of the a function. Then, the calling module 203 searches the edit time of the executable code of the 3 versions corresponding to the a function, such as T1, T2 and T3, according to the execution rule; and then calculating the difference values of T1, T2 and T3 and the current time respectively to obtain C1, C2 and C3, wherein C1> C2> C3. Then, the calling module 203 selects the executable code corresponding to T3 to call according to the execution rule. Through the chronological order, the execution module 204 may preferably select the code segment that is updated most recently for execution.
In an exemplary embodiment, the rule engine further includes an execution priority, and the calling module 203 is further configured to obtain type identifiers of all code segments corresponding to the golang program in the content storage unit, and then successively call the code segments corresponding to the golang program from the content storage unit according to the type identifiers and the execution priority.
Specifically, the computer device sets a type identifier in advance for each code segment of a sub-function in the golang program, where the type identifier is used to identify code segments of different sub-functions in the golang program; the type identifications of the code segments of different versions of the same sub-functionality are the same. Therefore, when there are multiple target functions updated by the golang program, then, the calling module 203 may select a code segment with a type identifier corresponding to each target function according to an execution rule, then sequentially execute the selected code segments to replace the original code segments with the corresponding type identifiers according to a preset execution priority and the type identifier corresponding to each target function, and finally, the executing module 204 sequentially executes the code segments. Therefore, the golang program updating apparatus can realize the updating of code segments that orderly realize a plurality of sub-functions.
As can be seen from the above, the computer device is capable of obtaining, after receiving a golang program update request, a first code segment corresponding to a target function in the update request; then adding the first code segment to a content storage unit of a rule engine, and calling the first code segment from the content storage unit to replace a second code segment corresponding to the target function according to an execution rule of the rule engine; finally, the golang program including said first code segment is executed. Through the mode, after the new code segment is added to the rule engine, the old code segment is converted into the new code segment according to the execution rule of the rule engine, so that the online updating of the golang program is realized, and the flexibility and the efficiency of the golang program updating are improved.
The above-mentioned serial numbers of the embodiments of the present invention are merely for description and do not represent the merits of the embodiments.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (such as a mobile phone, a computer, a server, an air conditioner, or a network device) to execute the method according to the embodiments of the present invention.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (10)

1. A method for hot-updating a golang program, said method comprising the steps of:
receiving a golang program updating request, and acquiring a first code segment corresponding to a target function in the updating request;
adding the first code segment to a content store of a rules engine;
calling the first code segment from the content storage unit to replace a second code segment corresponding to the target function according to an execution rule of the rule engine;
executing a golang program comprising said first code segment.
2. A golang program hot update method according to claim 1, wherein said adding said first code segment to a rule engine's content storage unit comprises:
analyzing the first code segment by an AST technology to obtain a corresponding executable code segment;
adding the executable code segment to the content storage unit.
3. A method for hot update of a golang program according to claim 1, wherein said obtaining a first code segment corresponding to a target function in said update request comprises:
comparing the code data corresponding to the golang program updating request with the code data of the previous version of the golang program in a text mode to find out a difference code;
determining the first code segment included in the difference code segment according to a format of a code.
4. A golang program hot update method according to claim 1, wherein the execution rules comprise:
acquiring code segments of all versions corresponding to one function in the golang program in the content storage unit;
searching the editing time of each version of code segment in all the versions of code segments;
and selecting the code segment corresponding to the editing time with the minimum difference value with the current time for calling.
5. A golang program hot update method according to claim 1, wherein the rules engine further comprises an execution priority, the golang program hot update method further comprising:
acquiring type identifications of all code segments corresponding to the golang program in the content storage unit;
and successively calling code segments corresponding to the golang program from the content storage unit according to the type identifier and the execution priority.
6. A method for hot-updating a golang program according to claim 5, wherein the type identifies code segments for identifying different sub-functions in the golang program; the type identifications of the code segments of different versions of the same sub-functionality are the same.
7. A golang program hot-update method according to claim 1, wherein the rules engine is implemented by means of a syntax tree.
8. A golang program hot-update apparatus, comprising:
the device comprises an acquisition module, a processing module and a processing module, wherein the acquisition module is used for receiving a golang program updating request and acquiring a first code segment corresponding to a target function in the updating request;
an adding module for adding the first code segment to a content storage unit of a rules engine;
the calling module is used for calling the first code segment from the content storage unit to replace the second code segment corresponding to the target function according to the execution rule of the rule engine;
an execution module for executing a golang program comprising said first code segment.
9. Computer device, characterized in that it comprises a memory, a processor, said memory having stored thereon a computer program operable on said processor, said computer program, when executed by said processor, implementing the steps of the golang program thermal update method according to any of the claims 1-7.
10. A computer-readable storage medium, characterized in that it stores a computer program which is executable by at least one processor for causing the at least one processor to carry out the steps of the golang program thermal update method according to any of the claims 1-7.
CN202010068077.8A 2020-01-21 2020-01-21 Hot updating method and device for golang program and computer equipment Pending CN112416383A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010068077.8A CN112416383A (en) 2020-01-21 2020-01-21 Hot updating method and device for golang program and computer equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010068077.8A CN112416383A (en) 2020-01-21 2020-01-21 Hot updating method and device for golang program and computer equipment

Publications (1)

Publication Number Publication Date
CN112416383A true CN112416383A (en) 2021-02-26

Family

ID=74844010

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010068077.8A Pending CN112416383A (en) 2020-01-21 2020-01-21 Hot updating method and device for golang program and computer equipment

Country Status (1)

Country Link
CN (1) CN112416383A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114785687A (en) * 2022-06-15 2022-07-22 成都卓杭网络科技股份有限公司 Server hot updating method based on golang language, server and readable medium

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060132822A1 (en) * 2004-05-27 2006-06-22 Silverbrook Research Pty Ltd Storage of program code in arbitrary locations in memory
CN105893094A (en) * 2016-03-31 2016-08-24 百度在线网络技术(北京)有限公司 Achieving method and device for application program plug-in
CN107193609A (en) * 2017-05-27 2017-09-22 北京奇虎科技有限公司 Functional module call method and device, electronic equipment in
CN107220058A (en) * 2017-06-05 2017-09-29 厦门美柚信息科技有限公司 The realization method and system of Business Rule Engine
US20180321956A1 (en) * 2017-05-02 2018-11-08 Kai-Ting Amy Wang Multi-version asynchronous dynamic software update system and method for applications with multiple threads
CN110213370A (en) * 2019-06-03 2019-09-06 北京奇艺世纪科技有限公司 A kind of regulation engine apparatus and system
CN110221853A (en) * 2019-05-15 2019-09-10 无线生活(杭州)信息科技有限公司 The method and Nginx server of page script are updated based on Nginx
CN110471690A (en) * 2019-06-25 2019-11-19 珠海格力电器股份有限公司 Loading method, device and the storage medium of dynamic link library SO file

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20060132822A1 (en) * 2004-05-27 2006-06-22 Silverbrook Research Pty Ltd Storage of program code in arbitrary locations in memory
CN105893094A (en) * 2016-03-31 2016-08-24 百度在线网络技术(北京)有限公司 Achieving method and device for application program plug-in
US20180321956A1 (en) * 2017-05-02 2018-11-08 Kai-Ting Amy Wang Multi-version asynchronous dynamic software update system and method for applications with multiple threads
CN107193609A (en) * 2017-05-27 2017-09-22 北京奇虎科技有限公司 Functional module call method and device, electronic equipment in
CN107220058A (en) * 2017-06-05 2017-09-29 厦门美柚信息科技有限公司 The realization method and system of Business Rule Engine
CN110221853A (en) * 2019-05-15 2019-09-10 无线生活(杭州)信息科技有限公司 The method and Nginx server of page script are updated based on Nginx
CN110213370A (en) * 2019-06-03 2019-09-06 北京奇艺世纪科技有限公司 A kind of regulation engine apparatus and system
CN110471690A (en) * 2019-06-25 2019-11-19 珠海格力电器股份有限公司 Loading method, device and the storage medium of dynamic link library SO file

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
ALFRED-ZHONG: "D:\\案件信息\\268-2020100680778-golang程序热更新方法、装置以及计算机设备\\非专检索", Retrieved from the Internet <URL:《https://studygolang.com/articles/15648》> *
魔法灵猫: "Golang 热更新研究笔记", Retrieved from the Internet <URL:《https://zhuanlan.zhihu.com/p/27727950》> *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114785687A (en) * 2022-06-15 2022-07-22 成都卓杭网络科技股份有限公司 Server hot updating method based on golang language, server and readable medium
CN114785687B (en) * 2022-06-15 2022-10-21 成都卓杭网络科技股份有限公司 Server hot updating method based on golang language, server and readable medium

Similar Documents

Publication Publication Date Title
CN111068328B (en) Game advertisement configuration form generation method, terminal equipment and medium
CN112434061B (en) Task scheduling method and system supporting cyclic dependence
US20220179642A1 (en) Software code change method and apparatus
CN107797823B (en) Business rule management method and device, storage medium and computer equipment
CN108920691B (en) Front-end static resource management method and device, computer equipment and storage medium
CN113672224A (en) Method and device for generating small program page code and computer equipment
CN110597518A (en) Project construction method and device, computer equipment and storage medium
CN112631600A (en) Software construction method and system based on Flutter
CN110851151B (en) Method, device, terminal, server and storage medium for pre-installing application
CN110750286A (en) Management method, device, system, equipment and medium for upgrading Mbn through OTA
CN112416383A (en) Hot updating method and device for golang program and computer equipment
CN111556127B (en) Wearable device upgrading method and related device
CN115525534A (en) Test case generation method and platform based on swagger interface test
CN112416384A (en) Software upgrading method and device and computer equipment
CN113535206B (en) Multi-version code upgrading method and system
CN115794214A (en) Application module metadata management method, device, storage medium and device
CN116048609A (en) Configuration file updating method, device, computer equipment and storage medium
CN109522014B (en) Algorithm processing method based on new product development, electronic device and readable storage medium
CN108415814B (en) Method for automatically recording field change, application server and computer readable storage medium
CN112004155A (en) OAD upgrading method and device, smart television and readable storage medium
CN114840205A (en) Project code generation method and device and electronic equipment
CN108664259B (en) Method and terminal for installing application
CN112486556B (en) Method, system, terminal and storage medium for server to be compatible with BMC
CN112306416B (en) Method and terminal for automatically reading and writing NV (network video) parameters
CN107729013B (en) Method for managing operation buttons on web page and computer-readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination