CN116755754A - Service interface generation method and device and electronic equipment - Google Patents

Service interface generation method and device and electronic equipment Download PDF

Info

Publication number
CN116755754A
CN116755754A CN202310416195.7A CN202310416195A CN116755754A CN 116755754 A CN116755754 A CN 116755754A CN 202310416195 A CN202310416195 A CN 202310416195A CN 116755754 A CN116755754 A CN 116755754A
Authority
CN
China
Prior art keywords
service interface
information
template
code
instance object
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
CN202310416195.7A
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.)
Zhongdian Jinxin Technology Co ltd
Original Assignee
Zhongdian Jinxin 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 Zhongdian Jinxin Technology Co ltd filed Critical Zhongdian Jinxin Technology Co ltd
Priority to CN202310416195.7A priority Critical patent/CN116755754A/en
Publication of CN116755754A publication Critical patent/CN116755754A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/70Software maintenance or management
    • G06F8/71Version control; Configuration management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/166Editing, e.g. inserting or deleting
    • G06F40/186Templates
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates

Abstract

The disclosure provides a service interface generation method, a device and electronic equipment, wherein the method comprises the following steps: acquiring configuration information for generating a target service interface; inquiring the instance object information matched with each instance object according to each piece of identification information in the configuration information; acquiring a template code for generating a target service interface according to the template identification information in the configuration information; updating the template code according to the object information of each instance to obtain service interface source codes; according to the service interface source code and the service release information, a target service interface is generated, so that the template code can be replaced under the conditions of communication protocol, message format and processing logic adjustment to realize the adjustment of the service interface, the service interface code does not need to be rewritten, and the workload of writing the service interface code is reduced.

Description

Service interface generation method and device and electronic equipment
Technical Field
The disclosure relates to the field of computer technology, and in particular, to a service interface generation method, a service interface generation device and electronic equipment.
Background
At present, the micro-service architecture splits the single application into a plurality of small services, and data interaction processing can be performed between the services based on the network communication interface, so that the micro-service development needs to write interface codes to issue functions as service interfaces for other micro-services to call in addition to writing the function codes.
In the related art, the writing of service interface codes is required before the program is compiled, and the communication protocol, message format and processing logic of the service interface cannot be dynamically adjusted by the micro-service running after the compiling, if the condition that the service interface communication protocol needs to be changed is met, all the service interface codes must be rewritten, so that flexibility and expansibility are limited.
Disclosure of Invention
The disclosure provides a service interface generation method, a service interface generation device and electronic equipment, so as to solve one of the technical problems in the related art to at least a certain extent. The technical scheme of the present disclosure is as follows:
according to a first aspect of an embodiment of the present disclosure, there is provided a service interface generating method, including: acquiring configuration information for generating a target service interface, wherein the configuration information comprises template identification information for generating the target service interface, service release information of the target service interface and identification information of at least one instance object associated with the target service interface; inquiring instance object information matched with each instance object according to each piece of identification information; acquiring a template code for generating the target service interface according to the template identification information in the configuration information; updating the template code according to the object information of each instance to obtain service interface source codes; and generating the target service interface according to the service interface source code and the service release information.
According to a second aspect of the embodiments of the present disclosure, there is provided a service interface generating apparatus, including: the system comprises a first acquisition module, a second acquisition module and a third acquisition module, wherein the first acquisition module is used for acquiring configuration information for generating a target service interface, and the configuration information comprises template identification information for generating the target service interface, service release information of the target service interface and identification information of at least one instance object associated with the target service interface; the query module is used for querying the instance object information matched with each instance object according to each piece of identification information; the second acquisition module is used for acquiring a template code for generating the target service interface according to the template identification information in the configuration information; the updating module is used for updating the template codes according to the object information of each instance to obtain service interface source codes; and the generating module is used for generating the target service interface according to the service interface source code and the service release information.
According to a third aspect of embodiments of the present disclosure, there is provided an electronic device, comprising: a processor; a memory for storing the processor-executable instructions; wherein the processor is configured to execute the instructions to implement a service interface generation method according to an embodiment of the first aspect of the present disclosure.
According to a fourth aspect of embodiments of the present disclosure, there is provided a computer readable storage medium, which when executed by a processor of an electronic device, causes the electronic device to perform a service interface generation method according to an embodiment of the first aspect of the present disclosure.
According to a fifth aspect of embodiments of the present disclosure, there is provided a computer program product comprising: a computer program which, when executed by a processor, implements a service interface generation method according to an embodiment of the first aspect of the present disclosure.
The technical scheme provided by the embodiment of the disclosure at least brings the following beneficial effects:
obtaining configuration information for generating a target service interface, wherein the configuration information comprises template identification information for generating the target service interface, service release information of the target service interface and identification information of at least one instance object associated with the target service interface; inquiring instance object information matched with each instance object according to each piece of identification information; inquiring instance object information matched with each instance object according to each piece of identification information; acquiring a template code for generating the target service interface according to the template identification information in the configuration information; updating the template code according to the object information of each instance to obtain service interface source codes; according to the service interface source code and the service release information, the target service interface is generated, so that a template code for generating the target service interface is obtained according to template identification information in configuration information, and the template code is updated according to example object information matched with each example object to dynamically generate the target service interface, so that the adjustment of the service interface can be realized by replacing the template code under the conditions of communication protocol, message format and processing logic adjustment, the service interface code does not need to be rewritten, and the workload of writing the service interface code is reduced.
It is to be understood that both the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the disclosure.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the disclosure and together with the description, serve to explain the principles of the disclosure and do not constitute an undue limitation on the disclosure.
Fig. 1 is a flowchart of a service interface generation method according to a first embodiment of the present disclosure.
Fig. 2 is a flowchart of a service interface generation method according to a second embodiment of the present disclosure.
Fig. 3 is a flowchart of a service interface generation method according to a third embodiment of the present disclosure.
Fig. 4 is a flowchart of a service interface generation method according to a fourth embodiment of the present disclosure.
Fig. 5 is a flowchart of a service interface generation method according to a fifth embodiment of the present disclosure.
Fig. 6 is a flowchart of a service interface generation method according to a sixth embodiment of the present disclosure.
Fig. 7 is a flowchart of a service interface generating method according to an embodiment of the present disclosure.
Fig. 8 is a schematic diagram of reticle exchange as shown in an embodiment of the present disclosure.
Fig. 9 is a schematic structural diagram of a service interface generating device shown in a seventh embodiment of the present disclosure.
Fig. 10 is a schematic structural view of an electronic device according to an exemplary embodiment of the present disclosure.
Detailed Description
In order to enable those skilled in the art to better understand the technical solutions of the present disclosure, the technical solutions of the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings.
It should be noted that the terms "first," "second," and the like in the description and claims of the present disclosure and in the foregoing figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the disclosure described herein may be capable of operation in sequences other than those illustrated or described herein. The implementations described in the following exemplary examples are not representative of all implementations consistent with the present disclosure. Rather, they are merely examples of apparatus and methods consistent with some aspects of the present disclosure as detailed in the accompanying claims.
The disclosure provides a service interface generation method, a service interface generation device and electronic equipment.
The following describes a service interface generation method, a device and an electronic device according to an embodiment of the present disclosure with reference to the accompanying drawings.
Fig. 1 is a flowchart of a service interface generation method according to a first embodiment of the present disclosure. It should be noted that, the service interface generating method implemented by the present disclosure may be applied to a service interface generating device.
As shown in fig. 1, the service interface generation method may include the steps of:
step 101, obtaining configuration information for generating a target service interface.
Wherein the configuration information includes template identification information for generating the target service interface, service release information of the target service interface, and identification information of at least one instance object associated with the target service interface.
As one example, configuration information for generating the target service interface may be obtained from a configuration file.
As another example, the service person may configure configuration information for generating the target service interface online (e.g., a related configuration page), and the service interface generating device may acquire the configuration information for generating the target service interface configured online by the service person.
The configuration information includes template identification information for generating the target service interface, service release information of the target service interface, and identification information of at least one instance object associated with the target service interface. Wherein the identifying information of each instance object may include, but is not limited to, class names, functions, etc. associated with each instance object.
Step 102, according to each piece of identification information, inquiring the instance object information matched with each instance object.
In the embodiment of the disclosure, the instance object information matched with each instance object may be obtained according to the identification information of at least one instance object associated with the target service interface, wherein the instance object information of each instance object may include a function name, function call parameter information and a function return value type, each instance object information may be structured content, for example, each instance object information may be a key value pair, wherein a key in the key value pair corresponding to each instance object is used for indicating a variable name associated with the instance object, and a value in the key value pair corresponding to each instance object is used for indicating a variable value associated with the instance object.
For example, the instance object information may include a key value pair corresponding to a specific variable, such as a packageName: replacing the packet path; importList: replacing the dynamically added dependency class; intfList: replacing the generated method source code; the instance object information may further include a key value pair corresponding to a variable associated with a class to which the instance object belongs, for example, serviceName: a service name; url: service access global url (path); value: service access name (value of FeignClient); serviceClassSimpleName: simple class name of service class (without packet path); serviceClassPath: packet path of service class (without class name); the instance object information may further include key value pairs corresponding to variables associated with functions of the instance object, for example, a methodName: the real method name of the service class; return typename: simple type name of the return value of the implementation method; return flag: the realization method returns an identifier; throwsNames: the implementation method supports the thrown exception; callParameters: and calling a parameter name list of the service class method.
And step 103, obtaining a template code for generating the target service interface according to the template identification information in the configuration information.
Further, the template codes of the plurality of settings may be queried according to the template identification information in the configuration information, so as to obtain the template code for generating the target service interface from the template codes of the plurality of settings.
It should be noted that, the format of the template code for generating the target service interface is similar to the actual code, but the content in the string may be identified and updated (e.g., replaced) by a string in the style "{ $=replacement variable name= $ }" in the template code for generating the target service interface.
In addition, it should be noted that the template code for generating the target service interface may include two parts, namely a class generating template and a function generating template, which are respectively used for generating the overall class source code and the function source code of a certain function.
In addition, it should be noted that, under the conditions of adjustment of the communication protocol, the message format and the processing logic, the template identification information in the configuration information can be modified to replace the template code, so as to realize adjustment of the service interface.
And step 104, updating the template codes according to the object information of each instance to obtain service interface source codes.
Further, the updatable content in the template code is updated by adopting the object information of each instance, and the updated template code is used as the source code of the service interface.
And 105, generating a target service interface according to the service interface source code and the service release information.
In embodiments of the present disclosure, service interface source code may be compiled and dynamically loaded into a service application (e.g., a micro-service application) for publishing as a target service interface based on service publishing information.
The service release information may include identification information of at least one service application of the following information, where the target service interface is used to provide a service for the service application; and the access address of the target service interface is used for the service application to access the target service interface.
In summary, by acquiring configuration information for generating a target service interface, wherein the configuration information includes template identification information for generating the target service interface, service release information of the target service interface, and identification information of at least one instance object associated with the target service interface; inquiring the instance object information matched with each instance object according to each piece of identification information; acquiring a template code for generating a target service interface according to the template identification information in the configuration information; updating the template code according to the object information of each instance to obtain service interface source codes; according to the service interface source code and the service release information, a target service interface is generated, therefore, according to the template identification information in the configuration information, a template code for generating the target service interface is obtained, and according to the example object information matched with each example object, the template code is updated to dynamically generate the target service interface, so that the template code can be replaced to realize the adjustment of the service interface under the conditions of adjustment of a communication protocol, a message format and a processing logic, the service interface code does not need to be rewritten, and the workload of writing the service interface code is reduced.
To clearly illustrate how the template code is updated according to the object information of each instance in the above embodiment to obtain the service interface source code, another service interface generating method is proposed in the present disclosure. Fig. 2 is a flowchart of a service interface generation method according to a second embodiment of the present disclosure.
As shown in fig. 2, the service interface generation method may include the steps of:
step 201, obtaining configuration information for generating a target service interface.
Wherein the configuration information includes template identification information for generating the target service interface, service release information of the target service interface, and identification information of at least one instance object associated with the target service interface.
Step 202, according to each piece of identification information, inquiring the instance object information matched with each instance object.
And 203, acquiring a template code for generating the target service interface according to the template identification information in the configuration information.
Step 204, for any instance object information in the instance object information, determining each function of the instance object corresponding to the instance object information, and traversing each function of the instance object corresponding to the instance object information in turn.
In order to determine the function source code corresponding to each function in the target service interface, for any instance object in the instance object information, each function of the instance object corresponding to any instance object information can be determined from any instance object information, and each function of the instance object corresponding to any instance object information can be traversed in turn.
Step 205, for the currently traversed function, a function template matching the currently traversed function is called, and a second variable name to be updated in the function template is determined according to the first variable name associated with the currently traversed function.
That is, when each function of the instance object is traversed, a function template matched with the currently traversed function can be called according to the configuration information, the matching is performed with at least one second variable name in the function template according to the first variable name associated with the currently traversed function, and the second variable name matched with the first variable name is used as the second variable name to be updated. The second variable name may be a variable name in a special string in the function template, for example, a variable name in a special string "{ $=variable name= $ }" is the second variable name.
When the number of the first variable names associated with the function currently traversed is plural, the second variable name matching any one of the first variable names in the function template is used as the second variable name to be updated for any one of the first variable names associated with the function currently traversed.
Step 206, determining a second variable value matched with the second variable name to be updated according to the first variable value indicated by the value in each first key value pair.
In the embodiment of the disclosure, the first variable value indicated by the value in each first key value pair is used as the second variable value matched with the second variable name to be updated.
And step 207, updating the second variable name to be updated in the function template by adopting the second variable value to obtain the function source code.
And further, updating the second variable name to be updated in the function template by adopting the second variable value, so that the function source codes corresponding to the functions can be obtained.
And step 208, updating the template codes according to the function source codes matched with the functions to obtain service interface source codes.
As an example, the template code may include a class generation template and a function generation template, the function generation template in the template code is updated according to the function source code matched with each function, and the class generation template is updated by using a third variable name and a corresponding third variable value associated with the class to which the instance object belongs, so as to obtain the service interface source code.
Step 209, generating a target service interface according to the service interface source code and the service release information.
It should be noted that, the execution process of steps 201 to 203 and step 209 may be implemented in any manner in each embodiment of the disclosure, which is not limited to this embodiment, and is not repeated.
In summary, each function of an instance object corresponding to any instance object information is determined by aiming at any instance object information in the instance object information, and each function of the instance object corresponding to any instance object information is traversed in turn; for the currently traversed function, a function template matched with the currently traversed function is called, and a second variable name to be updated in the function template is determined according to a first variable name associated with the currently traversed function; determining a second variable value matched with the second variable name to be updated according to the first variable value indicated by the value in each first key value pair; the second variable value is adopted to update the second variable name to be updated in the function template to obtain function source codes, and the template codes are updated according to the function source codes matched with the functions to obtain service interface source codes, so that the function source codes of the functions can be quickly generated by traversing the functions of the instance objects, substituting the variable names to be updated in the function template, the function source codes of the functions do not need to be manually written, the function source codes of the functions are saved, the generation efficiency of the function source codes of the functions is improved, the function source codes matched with the functions are updated to obtain service interface source codes, the generation efficiency of the service interface codes is improved, and the workload of writing the service interface codes is reduced.
To clearly illustrate how the template code is updated according to the function source code matched with each function in the above embodiment to obtain the service interface source code, another service interface generating method is proposed in the present disclosure. Fig. 3 is a flowchart of a service interface generation method according to a third embodiment of the present disclosure.
As shown in fig. 3, the service interface generation method may include the steps of:
step 301, obtaining configuration information for generating a target service interface.
Wherein the configuration information includes template identification information for generating the target service interface, service release information of the target service interface, and identification information of at least one instance object associated with the target service interface.
Step 302, according to each identification information, inquiring the instance object information matched with each instance object.
Step 303, obtaining a template code for generating the target service interface according to the template identification information in the configuration information.
Step 304, for any instance object information in the instance object information, determining each function of the instance object corresponding to any instance object information, and traversing each function of the instance object corresponding to any instance object information in turn.
Step 305, for the currently traversed function, calling a function template matched with the currently traversed function, and determining a second variable name to be updated in the function template according to the first variable name associated with the currently traversed function.
Step 306, determining a second variable value matching the second variable name to be updated according to the first variable value indicated by the value in each first key value pair.
And step 307, updating the second variable name to be updated in the function template by adopting the second variable value to obtain the function source code.
Step 308, determining the function list variable to be updated from the template code.
The function list variable is used for indicating functions to be called by the service interface.
As one example, in the template code, a special variable may be employed to indicate the path or function code that needs to be loaded, e.g., in the template code, a function list variable "intfList" may be employed to indicate the function source code that the template code is to call.
And 309, updating the function list variable by adopting the function source code matched with each function to obtain an intermediate template code.
As an example, intermediate template code may be obtained by updating the function list variables in the template code, such as replacing the function list variables, with function source code that matches each function.
Step 310, updating the intermediate template code according to the third variable name associated with the class to which the instance object belongs and indicated by the key in each second key value pair and the third variable value indicated by the value in the corresponding second key value pair, so as to obtain the service interface source code.
In an embodiment of the present disclosure, the instance object information further includes at least one second key value pair, a key in the second key value pair being used to indicate a third variable name associated with a class to which the instance object belongs, and a value in the second key value pair being used to indicate a third variable value.
As one possible implementation manner of the embodiment of the present disclosure, a third variable name associated with a class to which the instance object belongs and indicated by a key in each second key value pair and a third variable value indicated by a value in a corresponding second key value pair may be used to update a fourth variable name to be updated in the intermediate template code, so as to obtain service interface source code.
As an example, according to the third variable name associated with the class to which the instance object belongs, which is indicated by the key in each second key value pair, a fourth variable name to be updated is obtained from the intermediate template code; determining a fourth variable value matched with the fourth variable name to be updated according to the third variable value indicated by the value in each second key value pair; and updating the fourth variable name to be updated in the intermediate code by adopting the fourth variable value to obtain the service interface source code.
That is, from at least one fourth variable name of the intermediate template code, a fourth variable name that matches a third variable name associated with a class to which the instance object belongs, indicated by a key in the second key value pair, is determined, and a fourth variable that matches a third variable name associated with a class to which the instance object belongs, indicated by a key in the second key value pair, is taken as the fourth variable name to be updated, and further, from among the third variable values indicated by the values in the respective second key value pairs, a fourth variable value that matches the fourth variable name to be updated may be determined, and the fourth variable name to be updated in the intermediate code may be updated with the fourth variable value to obtain the service interface source code.
For example, the fourth variable to be updated in the intermediate code is named as "className", the key in the second key value pair matched with the "className" can be determined from the second key value pair in the instance object information, the value in the second key value pair matched with the "className" is taken as the fourth variable value, and the fourth variable value is adopted to update the "className" so as to obtain the service interface source code.
Step 311, generating a target service interface according to the service interface source code and the service release information.
It should be noted that, the execution process of steps 301 to 307 and step 310 may be implemented by any one of the embodiments of the disclosure, which is not limited to this embodiment, and is not repeated.
In summary, the function list variables to be updated are determined from the template codes; updating the function list variable by adopting function source codes matched with the functions to obtain an intermediate template code; and updating the intermediate template code according to the third variable name associated with the class to which the instance object belongs and the third variable value indicated by the value in the corresponding second key value pair indicated by the key in each second key value pair to obtain service interface source codes, thereby updating the function list variable in the template code and the fourth variable name matched with the third variable name associated with the class to which the instance object belongs, and efficiently and accurately generating the service interface source codes.
In order to accurately describe how to generate the target service interface according to the service interface source code and the service release information in the above embodiment, another service interface generation method is proposed in the present disclosure. Fig. 4 is a flowchart of a service interface generation method according to a fourth embodiment of the present disclosure.
As shown in fig. 4, the service interface generation method may include the steps of:
step 401, obtaining configuration information for generating a target service interface.
Wherein the configuration information includes template identification information for generating the target service interface, service release information of the target service interface, and identification information of at least one instance object associated with the target service interface.
Step 402, according to each identification information, inquiring the instance object information matched with each instance object.
Step 403, obtaining the template code for generating the target service interface according to the template identification information in the configuration information.
And step 404, updating the template code according to the object information of each instance to obtain the service interface source code.
And 405, compiling the service interface source code to obtain compiled code.
In order to accelerate the compiling efficiency and save the system resources, as an example, the service interface codes can be dynamically compiled to obtain compiled codes.
And step 406, according to the service release information, releasing the compiled code to obtain the target service interface.
In order to improve flexibility of the target service interface, in the embodiment of the present disclosure, compiled codes may be dynamically loaded into the micro-service application, and the target service interface may be published based on service publishing information. Wherein the published information may include at least one of the following information: the service application comprises identification information of the service application and an access address of a target service interface, wherein the target service interface is used for providing service for the service application, and the access address is used for the service application to access the target service interface.
It should be noted that the execution of steps 401 to 404 may be implemented in any manner of embodiments of the present disclosure, which are not limited to this and are not repeated.
In summary, the compiling code is obtained by compiling the service interface source code, and the compiling code is issued according to the service issue information to obtain the target service interface, so that the service interface source code is compiled and issued to obtain the target service interface.
In order to clearly explain how to acquire configuration information for generating a service interface in the above-described embodiments, the present disclosure proposes another service interface generation method. Fig. 5 is a flowchart of a service interface generation method according to a fifth embodiment of the present disclosure.
As shown in fig. 5, the service interface generation method may include the steps of:
step 501, a configuration file is obtained.
The configuration file comprises configuration information of at least one candidate service interface.
In the embodiment of the disclosure, the relevant service personnel may configure configuration information of at least one candidate service interface in the configuration file in advance, or obtain configuration information of the relevant service personnel configuring at least one candidate service interface on the configuration page, and generate the configuration file according to the configuration information of at least one candidate service interface in the configuration page.
Step 502, determining configuration information for generating the target service interface from configuration information of each candidate service interface of the configuration file according to identification information of the target service interface to be generated.
Wherein the configuration information includes template identification information for generating the target service interface, service release information of the target service interface, and identification information of at least one instance object associated with the target service interface.
Further, according to the identification information of the target service interface to be generated, the configuration information of each candidate service interface in the configuration file is queried to obtain the configuration information for generating the target service interface. Wherein, the identification information of the target service interface may be an ID.
Step 503, according to each identification information, inquiring the instance object information matched with each instance object.
Step 504, according to the template identification information in the configuration information, obtaining a template code for generating the target service interface.
And step 505, updating the template code according to the object information of each instance to obtain service interface source codes.
And step 506, generating a target service interface according to the service interface source code and the service release information.
It should be noted that the execution of steps 503 to 506 may be implemented in any manner of embodiments of the present disclosure, which are not limited to this and are not repeated.
In summary, by acquiring the configuration file, the configuration information for generating the target service interface is determined from the configuration information of each candidate service interface of the configuration file according to the identification information of the target service interface to be generated, thereby accurately and efficiently determining the configuration information for generating the target service interface from the configuration file according to the identification information of the target service interface to be generated.
In order to clearly explain how to query instance object information matching each instance object according to each identification information in the above embodiments, the present disclosure proposes another service interface generation method. Fig. 6 is a flowchart of a service interface generation method according to a sixth embodiment of the present disclosure.
As shown in fig. 6, the service interface generation method may include the steps of:
step 601, obtaining configuration information for generating a target service interface.
Wherein the configuration information includes template identification information for generating the target service interface, service release information of the target service interface, and identification information of at least one instance object associated with the target service interface.
Step 602, according to each piece of identification information, querying a set class code library to obtain instance object information matched with each instance object from the class code library.
In the embodiment of the disclosure, the mapping relationship between the identification information of each instance object and the instance object information may be preset, and according to the identification information of each instance object, the mapping relationship between the identification information of each instance object and the instance object information may be queried, so as to obtain the instance object information matched with each instance object.
As an example, a reflection technique may be employed to query a set class code library based on each identification information, so that instance object information matching each instance object may be obtained from the class code library.
Step 603, obtaining a template code for generating the target service interface according to the template identification information in the configuration information.
And step 604, updating the template code according to the object information of each instance to obtain service interface source codes.
Step 605, generating a target service interface according to the service interface source code and the service release information.
It should be noted that, the execution of steps 601 and 603 to 605 may be implemented by any one of the embodiments of the disclosure, which is not limited to this embodiment, and is not repeated.
In summary, the set class code library is queried according to each piece of identification information to obtain the instance object information matched with each instance object from the class code library, so that the instance object information matched with each instance object can be accurately obtained according to the identification information of each instance object, the template code can be updated according to each instance object information, a target service interface can be dynamically generated, the template code can be replaced under the conditions of communication protocol, message format and processing logic adjustment to realize the adjustment of the service interface, the service interface code does not need to be rewritten, and the workload of writing the service interface code is reduced.
In any embodiment of the present disclosure, as shown in fig. 7, the service interface generating method of the embodiment of the present disclosure may also be implemented based on the following steps:
step 701, the micro service application obtains the generated configuration information of the service interface from the configuration file, wherein the configuration information includes the generated template information of the service interface, service release information (for example, identification information of the service application, such as a service name, an access address of the standard service interface, such as an access URL, etc.), and instance object information (for example, class name, service function, etc.) associated with the service;
step 702, based on the generation configuration of the service interface, an instance object associated with the service can be obtained, and information (such as object class naming, function name, function call parameter information, function return Value type, etc.) of the service object is obtained through a reflection technology of a development language, and a Key-Value dictionary object for replacing a template variable is formed by combining the generation configuration content, wherein Key is a replacement variable name, and Value is a replacement variable Value;
step 703, obtaining template information from the generation configuration of the service interface, and finding out the corresponding service interface generation template. The format of the service interface generated template is similar to the actual code, but variable substitution in the content can be performed in the template through a special character string in a "{ $=substitution variable name= $ }" mode. Each set of generating templates comprises two types of class generating templates and function generating templates, which are respectively used for generating the whole class source codes and the source codes of a certain function;
And step 704, replacing the template with the replacement variable value to generate a service interface source code file (service interface source code).
Firstly, traversing all functions of a service object, obtaining source codes of each function through variable replacement of a function template, putting the source codes into a replacement variable intfList of a class template, and obtaining a source code file of a service interface through variable replacement of the class template.
Step 705, dynamically compiling the source code file of the service interface in the application, and dynamically loading the source code file into the micro-service application to be released as the service interface.
Therefore, according to the scheme processing flow, service interfaces of the micro service application are dynamically generated through templates. As shown in fig. 8, if the interface standard needs to be changed, only the generation template implementation of the service interface needs to be modified; if the interface communication protocol needs to be replaced, the method can also be directly realized by replacing the template. The interface code and the rewrite compilation are not required to be rewritten for the adjustment of the interface.
Corresponding to the service interface generating method provided by the embodiments of fig. 1 to 8, the present disclosure further provides a service interface generating device, and since the service interface generating device provided by the embodiments of the present disclosure corresponds to the service interface generating method provided by the embodiments of fig. 1 to 8, implementation of the service interface generating method is also applicable to the service interface generating device provided by the embodiments of the present disclosure, and will not be described in detail in the embodiments of the present disclosure.
Fig. 9 is a schematic structural diagram of a service interface generating device shown in a seventh embodiment of the present disclosure. As shown in fig. 9, the service interface generating apparatus 900 includes: a first acquisition module 910, a query module 920, a second acquisition module 930, an update module 940, and a generation module 950.
The first obtaining module 910 is configured to obtain configuration information for generating a target service interface, where the configuration information includes template identification information for generating the target service interface, service release information of the target service interface, and identification information of at least one instance object associated with the target service interface; a query module 920, configured to query, according to each identification information, instance object information that matches each instance object; a second obtaining module 930, configured to obtain a template code for generating a target service interface according to the template identification information in the configuration information; an updating module 940, configured to update the template code according to the object information of each instance to obtain a service interface source code; the generating module 950 is configured to generate a target service interface according to the service interface source code and the service release information.
As one possible implementation of the embodiment of the present disclosure, the instance object information includes at least one first key value pair, where a key in the first key value pair is used to indicate a first variable name associated with each function of the instance object, and a value in the first key value pair is used to indicate a first variable value, and the update module 940 is specifically configured to: determining functions of the instance objects corresponding to the instance object information according to any instance object information in the instance object information, and traversing the functions of the instance objects corresponding to the instance object information in turn; for the currently traversed function, a function template matched with the currently traversed function is called, and a second variable name to be updated in the function template is determined according to a first variable name associated with the currently traversed function; determining a second variable value matched with the second variable name to be updated according to the first variable value indicated by the value in each first key value pair; updating a second variable name to be updated in the function template by adopting a second variable value to obtain a function source code; and updating the template codes according to the function source codes matched with the functions to obtain service interface source codes.
As one possible implementation manner of the embodiment of the present disclosure, the instance object information further includes at least one second key value pair, a key in the second key value pair is used to indicate a third variable name associated with a class to which the instance object belongs, and a value in the second key value pair is used to indicate a third variable value; the update module 940 is further configured to: determining a function list variable to be updated from the template code, wherein the function list variable is used for indicating each function to be called by the target service interface; updating the function list variable by adopting function source codes matched with the functions to obtain an intermediate template code; and updating the middle template code according to the third variable name associated with the class to which the instance object belongs and indicated by the key in each second key value pair and the third variable value indicated by the value in the corresponding second key value pair so as to obtain the service interface source code.
As one possible implementation of the embodiments of the present disclosure, the update module 940 is further configured to: acquiring a fourth variable name to be updated from the intermediate template code according to the third variable name associated with the class to which the instance object belongs and indicated by the key in each second key value pair; determining a fourth variable value matched with the fourth variable name to be updated according to the third variable value indicated by the value in each second key value pair; and updating the fourth variable name to be updated in the intermediate code by adopting the fourth variable value to obtain the service interface source code.
As one possible implementation of the embodiments of the present disclosure, the generating module 950 is specifically configured to: compiling the service interface source code to obtain a compiled code; and according to the service release information, releasing the compiled code to obtain a target service interface.
As one possible implementation of the embodiments of the present disclosure, the service release information includes at least one of the following information: the method comprises the steps of identifying information of a service application, wherein a target service interface is used for providing services for the service application; and the access address of the target service interface is used for the service application to access the target service interface.
As a possible implementation manner of the embodiment of the present disclosure, the first obtaining module 910 is specifically configured to: acquiring a configuration file, wherein the configuration file comprises configuration information of at least one candidate service interface; and determining the configuration information for generating the target service interface from the configuration information of each candidate service interface of the configuration file according to the identification information of the target service interface to be generated.
As one possible implementation of the embodiments of the present disclosure, the query module 920 is specifically configured to: and according to the identification information, inquiring the set class code library to acquire the instance object information matched with each instance object from the class code library.
The service interface generating device of the embodiment of the disclosure obtains configuration information for generating a target service interface, wherein the configuration information comprises template identification information for generating the target service interface, service release information of the target service interface and identification information of at least one instance object associated with the target service interface; inquiring the instance object information matched with each instance object according to each piece of identification information; inquiring the instance object information matched with each instance object according to each piece of identification information; acquiring a template code for generating a target service interface according to the template identification information in the configuration information; updating the template code according to the object information of each instance to obtain service interface source codes; according to the service interface source code and the service release information, a target service interface is generated, therefore, according to the template identification information in the configuration information, a template code for generating the target service interface is obtained, and according to the example object information matched with each example object, the template code is updated to dynamically generate the target service interface, so that the template code can be replaced to realize the adjustment of the service interface under the conditions of adjustment of a communication protocol, a message format and a processing logic, the service interface code does not need to be rewritten, and the workload of writing the service interface code is reduced.
In an exemplary embodiment, an electronic device is also presented.
Wherein, electronic equipment includes:
a processor;
a memory for storing processor-executable instructions;
wherein the processor is configured to execute instructions to implement a service interface generation method as set forth in any of the foregoing embodiments.
As an example, fig. 10 is a schematic structural diagram of an electronic device 1000 according to an exemplary embodiment of the present disclosure, and as shown in fig. 10, the electronic device 1000 may further include:
the memory 1010 and the processor 1020, the bus 1030 connecting the different components (including the memory 1010 and the processor 1020), the memory 1010 stores a computer program, and the processor 1020 executes the program to implement the service interface generating method according to the embodiments of the present disclosure.
Bus 1030 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor, or a local bus using any of a variety of bus architectures. By way of example, and not limitation, such architectures include Industry Standard Architecture (ISA) bus, micro channel architecture (MAC) bus, enhanced ISA bus, video Electronics Standards Association (VESA) local bus, and Peripheral Component Interconnect (PCI) bus.
Electronic device 1000 typically includes many types of electronic device readable media. Such media can be any available media that is accessible by the electronic device 1000 and includes both volatile and nonvolatile media, removable and non-removable media.
Memory 1010 may also include computer system readable media in the form of volatile memory, such as Random Access Memory (RAM) 1040 and/or cache memory 1050. The server 1000 may further include other removable/non-removable, volatile/nonvolatile computer system storage media. By way of example only, storage system 1060 may be used to read from or write to a non-removable, non-volatile magnetic media (not shown in FIG. 10, commonly referred to as a "hard disk drive"). Although not shown in fig. 10, a magnetic disk drive for reading from and writing to a removable non-volatile magnetic disk (e.g., a "floppy disk"), and an optical disk drive for reading from or writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical media) may be provided. In such cases, each drive may be coupled to bus 1030 through one or more data medium interfaces. Memory 1010 may include at least one program product having a set (e.g., at least one) of program modules configured to carry out the functions of the various embodiments of the disclosure.
A program/utility 1080 having a set (at least one) of program modules 1070 may be stored, for example, in memory 1010, such program modules 1070 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each or some combination of which may include an implementation of a network environment. Program modules 1070 typically perform the functions and/or methods in the embodiments described in this disclosure.
The electronic device 1000 can also communicate with one or more external devices 1090 (e.g., keyboard, pointing device, display 1091, etc.), with one or more devices that enable a user to interact with the electronic device 1000, and/or with any device (e.g., network card, modem, etc.) that enables the electronic device 1000 to communicate with one or more other computing devices. Such communication may occur through an input/output (I/O) interface 1092. Also, the electronic device 1000 may communicate with one or more networks such as a Local Area Network (LAN), a Wide Area Network (WAN) and/or a public network, such as the Internet, through a network adapter 1093. As shown, the network adapter 1093 communicates with other modules of the electronic device 1000 via the bus 1030. It should be appreciated that although not shown, other hardware and/or software modules may be used in connection with the electronic device 1000, including, but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, data backup storage systems, and the like.
The processor 1020 executes various functional applications and data processing by running programs stored in the memory 1010.
It should be noted that, the implementation process and the technical principle of the electronic device in this embodiment refer to the foregoing explanation of the service interface generating method in the embodiment of the disclosure, and are not repeated herein.
In an exemplary embodiment, a computer readable storage medium is also provided, e.g. a memory, comprising instructions executable by a processor of an electronic device to perform the service interface generation method set forth in any of the embodiments above. Alternatively, the computer readable storage medium may be ROM, random Access Memory (RAM), CD-ROM, magnetic tape, floppy disk, optical data storage device, etc.
In an exemplary embodiment, a computer program product is also provided, comprising a computer program/instruction, characterized in that the computer program/instruction, when executed by a processor, implements the service interface generation method set forth in any of the above embodiments.
Other embodiments of the disclosure will be apparent to those skilled in the art from consideration of the specification and practice of the disclosure disclosed herein. This disclosure is intended to cover any adaptations, uses, or adaptations of the disclosure following the general principles of the disclosure and including such departures from the present disclosure as come within known or customary practice within the art to which the disclosure pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the disclosure being indicated by the following claims.
It is to be understood that the present disclosure is not limited to the precise arrangements and instrumentalities shown in the drawings, and that various modifications and changes may be effected without departing from the scope thereof. The scope of the present disclosure is limited only by the appended claims.

Claims (10)

1. A service interface generation method, comprising:
acquiring configuration information for generating a target service interface, wherein the configuration information comprises template identification information for generating the target service interface, service release information of the target service interface and identification information of at least one instance object associated with the target service interface;
inquiring instance object information matched with each instance object according to each piece of identification information;
acquiring a template code for generating the target service interface according to the template identification information in the configuration information;
updating the template code according to the object information of each instance to obtain service interface source codes;
and generating the target service interface according to the service interface source code and the service release information.
2. The method of claim 1, wherein the instance object information includes at least one first key value pair, a key in the first key value pair being used to indicate a first variable name associated with each function of the instance object, a value in the first key value pair being used to indicate a first variable value,
Updating the template code according to the object information of each instance to obtain service interface source code, including:
determining each function of an instance object corresponding to any instance object information according to any instance object information in the instance object information, and traversing each function of the instance object corresponding to any instance object information in turn;
for a currently traversed function, calling a function template matched with the currently traversed function, and determining a second variable name to be updated in the function template according to a first variable name associated with the currently traversed function;
determining a second variable value matched with the second variable name to be updated according to the first variable value indicated by the value of each first key value pair;
updating a second variable name to be updated in the function template by adopting the second variable value to obtain a function source code;
and updating the template codes according to the function source codes matched with the functions to obtain service interface source codes.
3. The method of claim 2, wherein the instance object information further comprises at least one second key value pair, a key in the second key value pair being used to indicate a third variable name associated with a class to which the instance object belongs, a value in the second key value pair being used to indicate a third variable value,
Updating the template code according to the function source code matched with each function to obtain service interface source code, including:
determining a function list variable to be updated from the template code, wherein the function list variable is used for indicating each function to be called by the target service interface;
updating the function list variable by adopting a function source code matched with each function to obtain an intermediate template code;
and updating the intermediate template code according to a third variable name associated with the class to which the instance object belongs and indicated by the key in each second key value pair and a third variable value indicated by the value in the corresponding second key value pair, so as to obtain service interface source codes.
4. A method according to claim 3, wherein updating the intermediate template code to obtain service interface source code according to a third variable name associated with the class to which the instance object belongs indicated by the key in each of the second key value pairs and a third variable value indicated by the value in the corresponding second key value pair comprises:
acquiring a fourth variable name to be updated from the intermediate template code according to a third variable name associated with the class to which the instance object belongs and indicated by the key in each second key value pair;
Determining a fourth variable value matched with the fourth variable name to be updated according to the third variable value indicated by the value in each second key value pair;
and updating the fourth variable name to be updated in the intermediate code by adopting the fourth variable value to obtain service interface source codes.
5. The method of claim 1, wherein generating the target service interface based on the service interface source code and the service release information comprises:
compiling the service interface source code to obtain a compiled code;
and according to the service release information, releasing the compiled code to obtain the target service interface.
6. The method of claim 1, wherein the service release information comprises at least one of:
the target service interface is used for providing services for the service application;
and the access address of the target service interface is used for the service application to access the target service interface.
7. The method according to any one of claims 1-6, wherein the obtaining configuration information for generating a target service interface comprises:
Acquiring a configuration file, wherein the configuration file comprises configuration information of at least one candidate service interface;
and determining configuration information for generating the target service interface from the configuration information of each candidate service interface of the configuration file according to the identification information of the target service interface to be generated.
8. The method according to any one of claims 1-7, wherein querying instance object information matching each of the instance objects based on each of the identification information comprises:
and according to the identification information, inquiring a set class code library to acquire instance object information matched with each instance object from the class code library.
9. A service interface generation apparatus, comprising:
the system comprises a first acquisition module, a second acquisition module and a third acquisition module, wherein the first acquisition module is used for acquiring configuration information for generating a target service interface, and the configuration information comprises template identification information for generating the target service interface, service release information of the target service interface and identification information of at least one instance object associated with the target service interface;
the query module is used for querying the instance object information matched with each instance object according to each piece of identification information;
The second acquisition module is used for acquiring a template code for generating the target service interface according to the template identification information in the configuration information;
the updating module is used for updating the template codes according to the object information of each instance to obtain service interface source codes;
and the generating module is used for generating the target service interface according to the service interface source code and the service release information.
10. An electronic device, comprising:
a processor;
a memory for storing the processor-executable instructions;
wherein the processor is configured to execute the instructions to implement the service interface generation method of any one of claims 1 to 8.
CN202310416195.7A 2023-04-18 2023-04-18 Service interface generation method and device and electronic equipment Pending CN116755754A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310416195.7A CN116755754A (en) 2023-04-18 2023-04-18 Service interface generation method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310416195.7A CN116755754A (en) 2023-04-18 2023-04-18 Service interface generation method and device and electronic equipment

Publications (1)

Publication Number Publication Date
CN116755754A true CN116755754A (en) 2023-09-15

Family

ID=87957787

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310416195.7A Pending CN116755754A (en) 2023-04-18 2023-04-18 Service interface generation method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN116755754A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117076007A (en) * 2023-10-17 2023-11-17 苏州元脑智能科技有限公司 Method and device for reducing intrusion of middle platform architecture codes and middle platform system
CN117369784A (en) * 2023-12-06 2024-01-09 之江实验室 Processing system and method of service interface

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117076007A (en) * 2023-10-17 2023-11-17 苏州元脑智能科技有限公司 Method and device for reducing intrusion of middle platform architecture codes and middle platform system
CN117076007B (en) * 2023-10-17 2024-02-02 苏州元脑智能科技有限公司 Method and device for reducing intrusion of middle platform architecture codes and middle platform system
CN117369784A (en) * 2023-12-06 2024-01-09 之江实验室 Processing system and method of service interface
CN117369784B (en) * 2023-12-06 2024-03-05 之江实验室 Processing system and method of service interface

Similar Documents

Publication Publication Date Title
CN109976761B (en) Software development kit generation method and device and terminal equipment
US20210318897A1 (en) Methods, blockchain nodes, and node devices for executing smart contract
CN116755754A (en) Service interface generation method and device and electronic equipment
JP7090657B2 (en) Methods, devices, devices and storage media for upgrading applications
US8635595B2 (en) Method and system for managing non-compliant objects
JP5475979B2 (en) Method and apparatus for providing project development environment and project development system (method and apparatus for providing project development environment and project development system)
JPH0827769B2 (en) Communication interface generation system and method
US20160154673A1 (en) Methods, systems, and computer program products for providing a minimally complete operating environment
US10254986B2 (en) Implicit coordination for deployment of computing systems using a data sharing service
US20070198705A1 (en) System and method for integrating resources in a network
EP3504617B1 (en) Hybrid deoptimization mechanism for class hierarchy analysis
CN107203535B (en) Information query method and device
CN109634591B (en) File processing method and device
US20090150859A1 (en) Dynamic validation of models using constraint targets
US8347278B2 (en) Instrumenting a compiled software routine for augmentation
CN112306881A (en) Simulation data generation method, device, equipment and storage medium
US11537367B1 (en) Source code conversion from application program interface to policy document
US7987457B2 (en) Targeted patching for native generation images
CN112769706A (en) Componentized routing method and system
CN111240772A (en) Data processing method and device based on block chain and storage medium
US11567738B2 (en) Code generator for creating a unified data model for multiple language specifications
US11182272B2 (en) Application state monitoring
CN107817972B (en) Cache code processing method and device, storage medium and electronic equipment
Lyu et al. A procedure-based dynamic software update
CN112925523A (en) Object comparison method, device, equipment and computer readable 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