CN115509513A - GRPC service layer code generation method, device, equipment and storage medium - Google Patents

GRPC service layer code generation method, device, equipment and storage medium Download PDF

Info

Publication number
CN115509513A
CN115509513A CN202211461382.9A CN202211461382A CN115509513A CN 115509513 A CN115509513 A CN 115509513A CN 202211461382 A CN202211461382 A CN 202211461382A CN 115509513 A CN115509513 A CN 115509513A
Authority
CN
China
Prior art keywords
grpc
service layer
code
layer code
determining
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
CN202211461382.9A
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.)
Shenzhen Mingyuanyun Procurement Technology Co ltd
Original Assignee
Shenzhen Mingyuanyun Procurement 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 Shenzhen Mingyuanyun Procurement Technology Co ltd filed Critical Shenzhen Mingyuanyun Procurement Technology Co ltd
Priority to CN202211461382.9A priority Critical patent/CN115509513A/en
Publication of CN115509513A publication Critical patent/CN115509513A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/35Creation or generation of source code model driven

Abstract

The invention discloses a method, a device, equipment and a storage medium for generating GRPC service layer codes, and belongs to the technical field of code conversion. The method comprises the following steps: determining a protobuf file and a micro service code warehouse of a current service project; determining a first target parameter in the protobuf file and determining a second target parameter in the micro service code repository; and filling the first target parameter and the second target parameter into a preset GRPC service layer code template to obtain a GRPC service layer code corresponding to the protobuf file. The invention greatly improves the generation efficiency of GRPC service layer codes, avoids various errors caused by manually compiling the codes, unifies the code compiling style specification and greatly reduces the maintenance cost of various GRPC service layer codes in the later period.

Description

GRPC service layer code generation method, device, equipment and storage medium
Technical Field
The present invention relates to the field of code conversion technologies, and in particular, to a method, an apparatus, a device, and a computer-readable storage medium for generating GRPC service layer codes.
Background
The microservice is to divide the whole application program which needs to be completely developed into small services which are respectively and relatively independent, and after a protobuf file is defined and completed in the microservice development process based on protobuf (Google Protocol Buffer, mixed language data standard in Google corporation) Protocol communication, a corresponding GRPC (Google Remote Procedure Call) service code needs to be compiled according to the protobuf Protocol file, so that the calling of a relevant method of a client to a server is realized, and various requirements of a user for using the application are met.
The GRPC service codes corresponding to the protobuf protocol file are basically written by developers manually, and after the developers determine the relevant information in the protobuf protocol file, the developers knock out all the codes required by the GRPC service.
Disclosure of Invention
The invention mainly aims to provide a method, a device and equipment for generating GRPC service layer codes and a computer readable storage medium, and aims to solve the technical problems that the manual writing mode of the GRPC service layer codes is not only low in efficiency but also easy to make mistakes.
In order to achieve the above object, the present invention provides a GRPC service layer code generating method, which includes the following steps:
determining a protobuf file and a micro service code warehouse of a current service project;
determining a first target parameter in the protobuf file and determining a second target parameter in the micro service code repository;
and filling the first target parameter and the second target parameter into a preset GRPC service layer code template to obtain a GRPC service layer code corresponding to the protobuf file.
Optionally, the step of determining a first target parameter in the protobuf file includes:
analyzing the protobuf file to determine a GRPC service name, a GRPC method name, a request parameter corresponding to the GRPC method name and a return parameter corresponding to the GRPC method name in the protobuf file, and taking the GRPC service name, the GRPC method name, the request parameter and the return parameter as the first target parameter.
Optionally, the step of determining a second target parameter in the micro service code repository includes:
determining a current code warehouse address corresponding to the micro-service code warehouse;
determining a code repository domain name, a code repository group name and an application name in the current code repository address;
and taking the code warehouse domain name, the code warehouse group name and the application name as second target parameters.
Optionally, the step of determining a protobuf file of the current service item includes:
determining command parameters of the current service item;
determining a protobuf file directory and a protobuf file name in the command parameters;
and determining the protobuf file according to the protobuf file directory and the protobuf file name.
Optionally, the step of filling the first target parameter and the second target parameter into a preset GRPC service layer code template to obtain a GRPC service layer code corresponding to the protobuf file includes:
determining a first placeholder corresponding to the first target parameter in the preset GRPC service layer code, and determining a second placeholder corresponding to the second target parameter in the preset GRPC service layer code;
and filling the first target parameter into the first placeholder, filling the second target parameter into the second placeholder, and deleting the first placeholder and the second placeholder.
Optionally, after the step of filling the first target parameter and the second target parameter into a preset GRPC service layer code template to obtain a GRPC service layer code corresponding to the protobuf file, the method further includes:
based on a preset directory specification, storing the GRPC service layer code into a corresponding target directory;
and when a calling instruction corresponding to the GRPC service layer code is received, executing the GRPC service layer code in the target directory to return a calling result corresponding to the calling instruction.
Optionally, the GRPC service layer code template includes a GRPC service layer template and at least one GRPC method template, the GRPC service layer template represents GRPC service layer data, the GRPC method template represents GRPC method data, and placeholders between the GRPC service layer template and the GRPC method template are different.
In addition, to achieve the above object, the present invention provides a GRPC service layer code generating apparatus, including:
the parameter extraction module is used for determining a protobuf file and a micro service code warehouse of the current service project; determining a first target parameter in the protobuf file and determining a second target parameter in the micro service code repository;
a parameter replacement module for replacing the parameters of the target, and the GRPC service layer code template is used for filling the first target parameter and the second target parameter to a preset GRPC service layer code template to obtain a GRPC service layer code corresponding to the protobuf file.
In addition, in order to achieve the above object, the present invention also provides a GRPC service layer code generating device, including a processor, a memory, and a GRPC service layer code generating program stored in the memory and executable by the processor, where the GRPC service layer code generating program implements the steps of the GRPC service layer code generating method as described above when executed by the processor.
The present invention also provides a computer readable storage medium, which stores a GRPC service layer code generation program, wherein the GRPC service layer code generation program, when executed by a processor, implements the steps of the GRPC service layer code generation method as described above.
The GRPC service layer code generation method in the technical scheme of the invention comprises the following steps: determining a protobuf file and a micro service code warehouse of a current service project; determining a first target parameter in the protobuf file and determining a second target parameter in the micro service code repository; and filling the first target parameter and the second target parameter into a preset GRPC service layer code template to obtain a GRPC service layer code corresponding to the protobuf file. The invention solves the technical problems that the manual writing mode of the GRPC service code has low efficiency and is easy to make mistakes.
It is to be noted that, the present invention mainly finds out key feature parameters in a protobuf file and in a micro-service code repository corresponding to a current service project by automatically determining and extracting a plurality of first target parameters therein and simultaneously determining and extracting a plurality of second target parameters in the micro-service code repository based on a protobuf file, and automatically fills and replaces placeholders corresponding to a preset GRPC service layer code template with the first target parameters and the second target parameters distinguished from other service projects, and other basic codes in the GRPC service layer code template are kept unchanged, so that a GRPC service layer code corresponding to a protobuf file, that is, a GRPC service layer code corresponding to a current service project, can be automatically generated quickly and efficiently, and the basic GRPC service layer code can respond to various remote invocation operations of a user on a client. According to the method, the mode of automatically generating the GRPC service layer codes is realized by filling the GRPC service layer code template with the key characteristic parameters respectively corresponding to the protobuf file and the micro-service code warehouse, so that the generation efficiency of the GRPC service layer codes is greatly improved, meanwhile, the manual operation is liberated, various errors caused by manually writing the codes are avoided, the code writing style specification is unified, and the later maintenance cost of various GRPC service layer codes is greatly reduced.
Drawings
Fig. 1 is a schematic structural diagram of a hardware operating environment of a GRPC service layer code generation device according to an embodiment of the present invention;
FIG. 2 is a flowchart illustrating a GRPC service layer code generation method according to a first embodiment of the present invention;
FIG. 3 is a detailed flowchart of step S10 of a GRPC service layer code generation method according to a first embodiment of the present invention;
fig. 4 is a detailed flowchart of step S20 of the GRPC service layer code generation method according to the first embodiment of the present invention;
fig. 5 is a detailed flowchart of step S30 of the GRPC service layer code generation method according to the first embodiment of the present invention;
FIG. 6 is a flowchart of an embodiment of a GRPC service layer code generation method according to the present invention;
fig. 7 is a schematic diagram of a framework structure of a GRPC service layer code generation apparatus according to the present invention.
The implementation, functional features and advantages of the objects of the present invention will be further explained with reference to the accompanying drawings.
Detailed Description
It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.
The technical scheme of the invention is summarized as follows:
based on the discovery and consideration that under an MVC (Model-view-controller) framework, the logic of each GRPC service code is very similar, and the method comprises the steps of compiling a GRPC method corresponding to protobuf, obtaining request parameters, calling service logic service codes, finally returning data and the like.
The embodiment of the invention provides a GRPC service layer code generation device.
As shown in fig. 1, fig. 1 is a schematic structural diagram of a hardware operating environment of a GRPC service layer code generation device according to an embodiment of the present invention.
As shown in fig. 1, the GRPC service layer code generating apparatus may include: a processor 1001, such as a CPU, a network interface 1004, a user interface 1003, a memory 1005, a communication bus 1002. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may comprise a Display (Display), an input unit such as a control panel, and the optional user interface 1003 may also comprise a standard wired interface, a wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WIFI interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory (e.g., a magnetic disk memory). The memory 1005 may alternatively be a storage device separate from the processor 1001. A GRPC service layer code generation program may be included in the memory 1005, which is a type of computer storage medium.
Those skilled in the art will appreciate that the hardware configuration shown in fig. 1 does not constitute a limitation of the apparatus, and may include more or fewer components than those shown, or some components may be combined, or a different arrangement of components.
With continued reference to fig. 1, the memory 1005 of fig. 1, which is one type of computer-readable storage medium, may include an operating system, a user interface module, a network communication module, and a GRPC service layer code generation program.
In fig. 1, the network communication module is mainly used for connecting a server and performing data communication with the server; and the processor 1001 may call the GRPC service layer code generation program stored in the memory 1005 and perform the steps in the following embodiments.
Based on the hardware structure of the controller, the embodiments of the GRPC service layer code generation method of the present invention are proposed.
The embodiment of the invention provides a GRPC service layer code generation method.
Referring to fig. 2, fig. 2 is a schematic flow chart of a GRPC service layer code generation method according to a first embodiment of the present invention; in the first embodiment of the present invention, the GRPC service layer code generation method is applied to a GRPC service layer code generation device; the method comprises the following steps:
step S10, determining a protobuf file and a micro service code warehouse of a current service project;
in this embodiment, the implementation may be performed by a GRPC service layer code generation device, where the GRPC service layer code generation device may be a personal computer, a server, a workstation, or other intelligent terminals that can be programmed.
The current service item refers to a micro service item, and may be a micro service item based on an MVC (Model-view-controller) framework, and a GRPC service layer code generated corresponding to the current service item may be assembled based on the GO language.
The protobuf file is also called protobuf protocol file, is a mixed language data standard in google, is a light and efficient structured data storage format, and can be used for structured data serialization or serialization. It is well suited for data storage or RPC (Remote Procedure Call) data exchange formats. The method can be used for language-independent, platform-independent and extensible serialization structure data formats in the fields of communication protocols, data storage and the like.
The micro service code warehouse refers to a code warehouse required and pointed by the micro service project and is used for storing source codes required by various micro service projects.
Referring to fig. 3, in an embodiment, the step S10 of determining a protobuf file of the current service item includes:
step S11, determining command parameters of the current service item;
step S12, determining a protobuf file directory and a protobuf file name in the command parameters;
and S13, determining the protobuf file according to the protobuf file directory and the protobuf file name.
In this embodiment, the command parameter refers to a command (instruction) for generating a corresponding GRPC service layer code according to a protobuf file in a current service project, and is generally indispensable, and the command parameter may be generated by a developer by simply encoding according to different protobuf files or service projects, or may be directly generated by an automation tool. The command parameters include a path of the protobuf file, that is, a protobuf file directory and a protobuf file name. After the protobuf file directory and the protobuf file name in the command parameter are determined, the position of the protobuf file in the current service item is further determined, specifically, a protobuf file set composed of various protobuf files where the protobuf file is located may be determined through the protobuf file directory, and the location of the protobuf file is determined from the protobuf file directory, that is, the protobuf file set according to the protobuf file name. The mode of searching and determining the protobuf file can replace developers to manually inquire the protobuf file, and efficiency of searching and determining the protobuf file is improved.
Step S20, determining a first target parameter in the protobuf file and determining a second target parameter in the micro-service code warehouse;
in this embodiment, the first target parameter in the protobuf file may be a key feature parameter different from other protobuf files, and in general, each protobuf file has a standard frame, and the difference often lies in some specific parameters. Similarly, for the micro service code repository, due to the characteristics of the current service item, some key characteristic parameters different from other service items, that is, second target parameters, may also be determined from the micro service code repository.
In an embodiment, in the step S20, the step of determining the first target parameter in the protobuf file includes:
analyzing the protobuf file to determine a GRPC service name, a GRPC method name, a request parameter corresponding to the GRPC method name and a return parameter corresponding to the GRPC method name in the protobuf file, and taking the GRPC service name, the GRPC method name, the request parameter and the return parameter as the first target parameter.
In this embodiment, the user may be provided with a third party tool that is open source: in this embodiment, the first target parameter may include a GRPC service name, a GRPC method name, a request parameter corresponding to the GRPC method name, and a return parameter corresponding to the GRPC method name in the protobuf file, where the GRPC service name corresponds to a name of a current service item and a related micro-service code, and the GRPC method name corresponds to GRPC method content, that is, what logic manner and manner are used to implement a remote procedure call function. The first target parameters are key characteristic parameters of the protobuf file, which are different from other protobuf files in the micro service project, and are also key characteristic parameters of the current service project, which are different from other service projects. By the embodiment, the relevant key characteristic parameters in the protobuf file can be efficiently and accurately determined and extracted, manual verification is not needed, and manual encoding is carried out from zero according to the relevant parameters.
Referring to fig. 4, in another embodiment, in the step S20, the step of determining the second target parameter in the micro service code repository includes:
step S21, determining the current code warehouse address corresponding to the micro service code warehouse;
step S22, determining a code warehouse domain name, a code warehouse group name and an application name in the current code warehouse address;
and step S23, taking the code warehouse domain name, the code warehouse group name and the application name as second target parameters.
In this embodiment, each micro service item has a corresponding micro service code repository, and multiple micro service items may also use the same micro service code repository, and as for how to determine a second target parameter corresponding to a current service item in the micro service code repository, a current code repository address associated with the current service item may be obtained first, and the current code repository address is resolved, where the current code repository address already includes related information including parameters such as a code repository domain name, a code repository group name, and an application name, so that resolving the current code repository address determines a second target parameter including a code repository domain name, a code repository group name, and an application name corresponding to the current service item. For example, in an example, a third-party tool obtains that the current code warehouse is git@git.mycaigou.com: ycg/golang/micro-ddd-demo.git, and after parsing, the domain name of the code warehouse is git.mycaigiou.com, the group name of the code warehouse is ycg/golang, and the application name is micro-ddd-demo. By the embodiment, the current code warehouse address corresponding to the micro-service code warehouse can be efficiently and accurately determined and extracted, and manual verification and manual encoding from zero according to the current code warehouse address are not needed.
And step S30, filling the first target parameter and the second target parameter into a preset GRPC service layer code template to obtain a GRPC service layer code corresponding to the protobuf file.
In the preset GRPC service layer code template, a plurality of placeholders are arranged, and each placeholder has no substantial content. Determining placeholders corresponding to the first target parameters and placeholders corresponding to the second target parameters, respectively filling each first target parameter and each second target parameter to the position of the corresponding placeholder, and deleting original contents (which may have parameters expressing the meaning of each placeholder) in the original placeholder, so that GRPC service layer codes corresponding to the protobuf file, namely GRPC service layer codes corresponding to the current service items, are automatically generated based on the first target parameters, the second target parameters and a preset GRPC service layer code template. In addition, for a preset GRPC service layer code template, reference may be made to an intra-industry general specification in combination with a specific service actual condition and a coding habit, for example, a directory and a file name specification may be named by lower case english letters, connected by underlining, a specific file name suffix may be set, and a service layer may correspond to a service item, and a rule for arranging services is not performed in the service layer, which is not limited herein.
Referring to fig. 5, in an embodiment, the step S30 includes:
step S31, determining a first placeholder corresponding to the first target parameter in the preset GRPC service layer code, and determining a second placeholder corresponding to the second target parameter in the preset GRPC service layer code;
step S32, filling the first target parameter into the first placeholder, filling the second target parameter into the second placeholder, and deleting the first placeholder and the second placeholder.
In this embodiment, the first target parameters include a GRPC service name, a GRPC method name, a request parameter, and a return parameter, and their corresponding first placeholders may include: the method comprises {. ServerName } corresponding to a GRPC service name, or $ { ServerName }, $ { RpcName } corresponding to a GRPC method name, $ { RequestName } corresponding to a request parameter, and $ { ReturnName } corresponding to a return parameter.
The second target parameters include a code repository domain name, a code repository group name, and an application name, and their corresponding second placeholders may include: the method comprises the steps of { {. GitAddr } corresponding to a code warehouse domain name, {. GroupName } corresponding to a code warehouse group name and {. AppName } corresponding to an application name.
After determining first placeholders corresponding to the first target parameters respectively and second placeholders corresponding to the second target parameters respectively, filling the first target parameters to the corresponding first placeholders respectively, filling the second target parameters to the corresponding second placeholders respectively, and deleting original descriptive placeholders in the first placeholders and the second placeholders, such as GroupName in {. GroupName }. By the embodiment, the related parameters (placeholders) in the GRPC service layer code template can be replaced accurately and efficiently in a targeted manner, and automatic generation of the GRPC service layer code is realized.
To further understand the above embodiments, in an embodiment, the GRPC service layer code template includes a GRPC service layer template and at least one GRPC method template, the GRPC service layer template characterizes GRPC service layer data, the GRPC method template characterizes GRPC method data, and placeholders between the GRPC service layer template and the GRPC method template are different.
In addition to some fixed codes, various placeholders are included in the GRPC service layer code template, as described in table 1 below:
Figure 986776DEST_PATH_IMAGE001
TABLE 1
In the GRPC method template, in addition to some fixed code, various placeholders are included, as described in table 2 below:
Figure 709881DEST_PATH_IMAGE002
TABLE 2
By the embodiment, the GRPC service layer code template is divided into the GRPC service layer template with different functions and different placeholders and the at least one GRPC method template, so that each acquired target parameter can be accurately filled and replaced in the placeholder corresponding to the corresponding template, errors in the process of generating the GRPC service layer code by filling and replacing the placeholder through the parameter are avoided, and the stability and reliability of generating the GRPC service layer code are improved.
In an embodiment, after the step S30, the method further includes:
step a, based on a preset directory specification, storing the GRPC service layer code into a corresponding target directory;
and b, when receiving a calling instruction corresponding to the GRPC service layer code, executing the GRPC service layer code in the target directory to return a calling result corresponding to the calling instruction.
In this embodiment, the preset directory specification may be set according to actual needs, so as to sequentially store different GRPC service layer codes into corresponding target directories, so that when a call instruction corresponding to the GRPC service layer code is received, the location of the corresponding GRPC service layer code may be quickly located, and further, various call instructions of a user on a client are quickly responded to return a result required by the user, thereby implementing efficient remote call.
The invention mainly finds out key characteristic parameters in a protobuf file corresponding to a current service project and a micro-service code warehouse respectively by automatically determining and extracting a plurality of first target parameters and simultaneously determining and extracting a plurality of second target parameters in the micro-service code warehouse based on the protobuf file, automatically fills and replaces corresponding placeholders in a preset GRPC service layer code template with the first target parameters and the second target parameters which are different from other service projects, keeps other basic codes in the GRPC service layer code template unchanged, can quickly and efficiently automatically generate GRPC service layer codes corresponding to the protobuf file, namely the GRPC service layer codes corresponding to the current service project, and can respond to various remote calling operations of a user on a client based on the GRPC service layer codes. According to the method, the mode of automatically generating the GRPC service layer codes is realized by filling the GRPC service layer code template with the key characteristic parameters respectively corresponding to the protobuf file and the micro-service code warehouse, so that the generation efficiency of the GRPC service layer codes is greatly improved, meanwhile, the manual operation is liberated, various errors caused by manually writing the codes are avoided, the code writing style specification is unified, and the later maintenance cost of various GRPC service layer codes is greatly reduced.
For further understanding of the above embodiments, please refer to fig. 6, fig. 6 is a flowchart illustrating an overall process of an embodiment of a GRPC service layer code generation method according to the present invention; as shown in fig. 6:
1. acquiring service information (a second target parameter in the micro-service code warehouse);
2. acquiring a PBservice name (GRPC service name), a rpc method name (which can be the GRPC method name), a request and a response parameter (a request parameter and a return parameter);
3. pulling a preset GRPC service layer code template;
4. replacing parameters, namely replacing the parameters into corresponding placeholders in a GRPC service layer code template;
5. after parameter replacement, a GRPC service layer code file and corresponding save directory are generated.
In addition, the present invention further provides a GRPC service layer code generating apparatus, referring to fig. 7, the GRPC service layer code generating apparatus includes:
the parameter extraction module A10 is used for determining a protobuf file and a micro service code warehouse of a current service project; determining a first target parameter in the protobuf file and determining a second target parameter in the micro service code repository;
a parameter replacement module a20, configured to fill the first target parameter and the second target parameter into a preset GRPC service layer code template to obtain a GRPC service layer code corresponding to the protobuf file.
Optionally, the parameter extraction module a10 is further configured to:
analyzing the protobuf file to determine a GRPC service name, a GRPC method name, a request parameter corresponding to the GRPC method name and a return parameter corresponding to the GRPC method name in the protobuf file, and taking the GRPC service name, the GRPC method name, the request parameter and the return parameter as the first target parameter.
Optionally, the parameter extracting module a10 is further configured to:
determining a current code warehouse address corresponding to the micro-service code warehouse;
determining a code repository domain name, a code repository group name and an application name in the current code repository address;
and taking the code warehouse domain name, the code warehouse group name and the application name as second target parameters.
Optionally, the parameter extraction module a10 is further configured to:
determining command parameters of the current service item;
determining a protobuf file directory and a protobuf file name in the command parameters;
and determining the protobuf file according to the protobuf file directory and the protobuf file name.
Optionally, the parameter replacement module a20 is further configured to:
determining a first place holder corresponding to the first target parameter in a preset GRPC service layer code, and determining a second place holder corresponding to the second target parameter in the preset GRPC service layer code;
and filling the first target parameter into the first placeholder, filling the second target parameter into the second placeholder, and deleting the first placeholder and the second placeholder.
Optionally, the parameter replacement module a20 is further configured to:
based on a preset directory specification, storing the GRPC service layer code into a corresponding target directory;
and when a calling instruction corresponding to the GRPC service layer code is received, executing the GRPC service layer code in the target directory to return a calling result corresponding to the calling instruction.
Optionally, the parameter extraction module a10 is further configured to:
the GRPC service layer code template comprises a GRPC service layer template and at least one GRPC method template, wherein the GRPC service layer template represents GRPC service layer data, the GRPC method template represents GRPC method data, and placeholders between the GRPC service layer template and the GRPC method template are different.
The specific implementation of the GRPC service layer code generation apparatus of the present invention is basically the same as the embodiments of the GRPC service layer code generation method described above, and is not described herein again.
In addition, the invention also provides a computer readable storage medium. The computer readable storage medium of the present invention stores a GRPC service layer code generation program, wherein the GRPC service layer code generation program, when executed by a processor, implements the steps of the above-mentioned GRPC service layer code generation method.
The method implemented when the GRPC service layer code generation program is executed may refer to each embodiment of the GRPC service layer code generation method of the present invention, and details are not described here.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It should be noted that in the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention can be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In the unit claims enumerating several means, several of these means may be embodied by one and the same item of hardware. The usage of the words first, second and third, etcetera do not indicate any ordering. These words may be interpreted as names.
While preferred embodiments of the present invention have been described, additional variations and modifications in those embodiments may occur to those skilled in the art once they learn of the basic inventive concepts. Therefore, it is intended that the appended claims be interpreted as including preferred embodiments and all such alterations and modifications as fall within the scope of the invention.
The above description is only a preferred embodiment of the present invention, and is not intended to limit the scope of the present invention, and all modifications and equivalents of the present invention, which are made by the contents of the present specification and the accompanying drawings, or directly/indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (10)

1. A GRPC service layer code generation method is characterized by comprising the following steps:
determining a protobuf file and a micro service code warehouse of a current service project;
determining a first target parameter in the protobuf file and determining a second target parameter in the micro service code warehouse;
and filling the first target parameter and the second target parameter into a preset GRPC service layer code template to obtain a GRPC service layer code corresponding to the protobuf file.
2. The GRPC service layer code generation method of claim 1, wherein the step of determining the first target parameter in the protobuf file comprises:
analyzing the protobuf file to determine a GRPC service name, a GRPC method name, a request parameter corresponding to the GRPC method name and a return parameter corresponding to the GRPC method name in the protobuf file, and taking the GRPC service name, the GRPC method name, the request parameter and the return parameter as the first target parameter.
3. The GRPC service layer code generation method of claim 1, wherein the step of determining a second target parameter in the microservice code repository comprises:
determining a current code warehouse address corresponding to the micro service code warehouse;
determining a code repository domain name, a code repository group name and an application name in the current code repository address;
and taking the code warehouse domain name, the code warehouse group name and the application name as second target parameters.
4. The GRPC service layer code generation method of claim 1, wherein the step of determining a protobuf file for a current service item includes:
determining command parameters of the current service item;
determining a protobuf file directory and a protobuf file name in the command parameters;
and determining the protobuf file according to the protobuf file directory and the protobuf file name.
5. The GRPC service layer code generation method of claim 1, wherein the step of populating the first target parameter and the second target parameter into a preset GRPC service layer code template to obtain a GRPC service layer code corresponding to the protobuf file includes:
determining a first placeholder corresponding to the first target parameter in the preset GRPC service layer code, and determining a second placeholder corresponding to the second target parameter in the preset GRPC service layer code;
and filling the first target parameter into the first placeholder, filling the second target parameter into the second placeholder, and deleting the first placeholder and the second placeholder.
6. The GRPC service layer code generation method of claim 1, wherein after the step of populating the first target parameter and the second target parameter into a preset GRPC service layer code template to obtain a GRPC service layer code corresponding to the protobuf file, the method further comprises:
based on a preset directory specification, storing the GRPC service layer code into a corresponding target directory;
and when a calling instruction corresponding to the GRPC service layer code is received, executing the GRPC service layer code in the target directory to return a calling result corresponding to the calling instruction.
7. The GRPC service layer code generation method of claim 1, wherein the GRPC service layer code templates include one GRPC service layer template and at least one GRPC method template, the GRPC service layer template characterizing GRPC service layer data, the GRPC method template characterizing GRPC method data, placeholders between the GRPC service layer template and the GRPC method template being different.
8. A GRPC service layer code generation apparatus, characterized by comprising:
the parameter extraction module is used for determining a protobuf file and a micro service code warehouse of the current service project; determining a first target parameter in the protobuf file and determining a second target parameter in the micro service code repository;
and the parameter replacement module is used for filling the first target parameter and the second target parameter into a preset GRPC service layer code template so as to obtain a GRPC service layer code corresponding to the protobuf file.
9. A GRPC service layer code generating device comprising a processor, a memory, and a GRPC service layer code generating program stored on the memory that is executable by the processor, wherein the GRPC service layer code generating program when executed by the processor implements the steps of the GRPC service layer code generating method of any of claims 1 to 7.
10. A computer readable storage medium having stored thereon a GRPC service layer code generation program, wherein the GRPC service layer code generation program when executed by a processor implements the steps of the GRPC service layer code generation method of any of claims 1-7.
CN202211461382.9A 2022-11-16 2022-11-16 GRPC service layer code generation method, device, equipment and storage medium Pending CN115509513A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211461382.9A CN115509513A (en) 2022-11-16 2022-11-16 GRPC service layer code generation method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211461382.9A CN115509513A (en) 2022-11-16 2022-11-16 GRPC service layer code generation method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN115509513A true CN115509513A (en) 2022-12-23

Family

ID=84514400

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211461382.9A Pending CN115509513A (en) 2022-11-16 2022-11-16 GRPC service layer code generation method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN115509513A (en)

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111831318A (en) * 2020-06-30 2020-10-27 山东大学 Micro-service management system capable of automatically generating codes and code generation method
CN111930541A (en) * 2020-08-17 2020-11-13 湖南快乐阳光互动娱乐传媒有限公司 Dynamic calling method and system for GRPC (Global positioning System) service
CN112631569A (en) * 2020-12-30 2021-04-09 上海中通吉网络技术有限公司 gPRC-based method, device and equipment for automatically generating and completing front-end and back-end codes
CN112965832A (en) * 2021-02-18 2021-06-15 腾讯科技(深圳)有限公司 Remote Procedure Call (RPC) service calling method and related device
WO2021233103A1 (en) * 2020-05-21 2021-11-25 Guangdong Oppo Mobile Telecommunications Corp., Ltd. Method and apparatus of cross-ipc access
CN114035803A (en) * 2022-01-10 2022-02-11 深圳市明源云科技有限公司 Code automatic generation method, device, equipment and computer readable storage medium
CN115202663A (en) * 2021-04-14 2022-10-18 腾讯科技(深圳)有限公司 Data processing method, device and storage medium

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2021233103A1 (en) * 2020-05-21 2021-11-25 Guangdong Oppo Mobile Telecommunications Corp., Ltd. Method and apparatus of cross-ipc access
CN111831318A (en) * 2020-06-30 2020-10-27 山东大学 Micro-service management system capable of automatically generating codes and code generation method
CN111930541A (en) * 2020-08-17 2020-11-13 湖南快乐阳光互动娱乐传媒有限公司 Dynamic calling method and system for GRPC (Global positioning System) service
CN112631569A (en) * 2020-12-30 2021-04-09 上海中通吉网络技术有限公司 gPRC-based method, device and equipment for automatically generating and completing front-end and back-end codes
CN112965832A (en) * 2021-02-18 2021-06-15 腾讯科技(深圳)有限公司 Remote Procedure Call (RPC) service calling method and related device
CN115202663A (en) * 2021-04-14 2022-10-18 腾讯科技(深圳)有限公司 Data processing method, device and storage medium
CN114035803A (en) * 2022-01-10 2022-02-11 深圳市明源云科技有限公司 Code automatic generation method, device, equipment and computer readable storage medium

Similar Documents

Publication Publication Date Title
CN108279932B (en) Method and device for dynamically configuring user interface of mobile terminal
CN106874388B (en) Relational database-based heterogeneous system data cascade operation automatic construction method
US7814404B2 (en) System and method for applying workflow of generic services to component based applications for devices
US20060200749A1 (en) System and method for conversion of generic services' applications into component based applications for devices
CN104731589A (en) Automatic generation method and device of user interface (UI)
CN108762743B (en) Data table operation code generation method and device
CN104133772A (en) Automatic test data generation method
CN110705237B (en) Automatic document generation method, data processing device and storage medium
CN113076096B (en) Desktop application program development method, device, equipment and storage medium
CN110727429B (en) Front-end page generation method, device and equipment
CN111784108B (en) Modeling method and device of main data management platform
CN111068328A (en) Game advertisement configuration table generation method, terminal device and medium
CN112769706B (en) Componentized routing method and system
CN113971110A (en) Interface testing method, device, equipment and computer readable storage medium
CN113656005B (en) Application component library construction method, application component configuration method and related devices
KR101552914B1 (en) Web server application framework web application processing method using the framework and computer readable medium processing the method
CN112000334A (en) Page development method, device, server and storage medium
CN112235132A (en) Method, device, medium and server for dynamically configuring service
CN111488144A (en) Data processing method and equipment
CN110941471A (en) Method and device for internationalizing basic data of software system
CN110825622A (en) Software testing method, device, equipment and computer readable medium
CN116400914A (en) Method for quickly constructing web application based on data model
US20190121681A1 (en) Framework for integrating a user device and a mainframe system
CN115509513A (en) GRPC service layer code generation method, device, equipment and storage medium
CN115469849A (en) Service processing system, method, electronic device and 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
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20221223