Detailed Description
Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. It should be understood that the description is only exemplary and is not intended to limit the scope of the present disclosure. In the following detailed description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the present disclosure. It may be evident, however, that one or more embodiments may be practiced without these specific details. In addition, in the following description, descriptions of well-known structures and techniques are omitted so as not to unnecessarily obscure the concepts of the present disclosure.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The terms "comprises," "comprising," and/or the like, as used herein, specify the presence of stated features, steps, operations, and/or components, but do not preclude the presence or addition of one or more other features, steps, operations, or components.
All terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art unless otherwise defined. It should be noted that the terms used herein should be construed to have meanings consistent with the context of the present specification and should not be construed in an idealized or overly formal manner.
Where a convention analogous to "at least one of A, B and C, etc." is used, in general such a convention should be interpreted in accordance with the meaning of one of skill in the art having generally understood the convention (e.g., "a system having at least one of A, B and C" would include, but not be limited to, systems having a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.).
In the process of developing software by using the Go language, error processing is often required, call stack information for error processing is not provided in a standard library of the Go language, and other languages (such as java and php) generally have error processing schemes for providing the call stack information, so that bug tracking and checking become very convenient. The error processing scheme of the Go language standard library is that no call stack information is used, so that the bug is very inconvenient to track and check, and the time cost is high.
The embodiment of the disclosure provides an error processing method based on a Go language, which is applied to a development environment of the Go language, and comprises the steps of defining a first type to store call stack information, wherein the call stack information is obtained based on calling a first related function, defining a second type to store call stack information error information, the second type comprises the first type and the error information and is used for simultaneously outputting the call stack information and the error information, declaring a second related function, and returning the second type to complete instantiation of the error type after execution of the second related function is finished, and completing output of the call stack information and the error information based on the instantiated error type.
According to the embodiment of the disclosure, the package and the output of the call stack information are performed, so that the simultaneous output of the error information and the call stack information is completed, the problem that the call stack information cannot be directly acquired and the error processing cannot be performed by a standard library based on the Go language in the prior art is solved, and the efficiency and the processing speed of the error processing in the actual development test are improved.
Fig. 1 schematically illustrates an application scenario diagram of Go language-based error handling according to an embodiment of the present disclosure.
As shown in fig. 1, an application scenario 100 according to this embodiment may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 is used as a medium to provide communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
The user may interact with the server 105 via the network 104 using the terminal devices 101, 102, 103 to receive or send messages or the like. Various communication client applications, such as shopping class applications, web browser applications, search class applications, instant messaging tools, mailbox clients, social platform software, etc. (by way of example only) may be installed on the terminal devices 101, 102, 103.
The terminal devices 101, 102, 103 may be a variety of electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablets, laptop and desktop computers, and the like.
The server 105 may be a server providing various services, such as a background management server (by way of example only) providing support for websites browsed by users using the terminal devices 101, 102, 103. The background management server may analyze and process the received data such as the user request, and feed back the processing result (e.g., the web page, information, or data obtained or generated according to the user request) to the terminal device.
It should be noted that, the error processing method based on Go language provided in the embodiments of the present disclosure may be generally executed by the server 105. Accordingly, the Go language-based error handling apparatus provided by the embodiments of the present disclosure may be generally provided in the server 105. The Go language-based error handling method provided by the embodiments of the present disclosure may also be performed by a server or server cluster that is different from the server 105 and is capable of communicating with the terminal devices 101, 102, 103 and/or the server 105. Accordingly, the error handling apparatus based on Go language provided by the embodiments of the present disclosure may also be provided in a server or a server cluster different from the server 105 and capable of communicating with the terminal devices 101, 102, 103 and/or the server 105.
It should be understood that the number of terminal devices, networks and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
The error processing method based on Go language of the disclosed embodiment will be described in detail with reference to fig. 2 to 3 based on the scenario described in fig. 1.
Fig. 2 schematically illustrates a flowchart of an error handling method based on Go language according to an embodiment of the present disclosure.
As shown in fig. 2, the error processing method based on Go language of this embodiment includes operations S210 to S240, and the transaction processing method may be executed by the server 105.
In operation S210, a first type is defined to store call stack information, wherein the call stack information includes a result based on calling a first related function.
The Go language has rich data types, and besides basic integer, floating point, boolean, character strings, arrays, slices, structures, functions, maps, channels, etc. In the Go language, data types are used to declare functions and variables. The data type is to divide the data into data with different memory sizes, and the large memory is applied when the large data is needed for storage, so that the memory is fully utilized.
According to an embodiment of the present disclosure, the first type includes a slice type. Slice type in Go language is an abstraction built on array type paper. Compared with the array, the slice only stores the information of the pointer, the length, the capacity and the like of the original array, the length of the slice is not fixed, and a part of the slice can be cut out from the array to be used as the slice, so that the dynamic expansion can be realized by adopting the slice type.
According to an embodiment of the present disclosure, the slice type includes a plurality of elements to hold a plurality of unsigned pointers, for each of which point to a memory address holding each of the call stack information.
For example, the first type defined is slice type stack, using unsigned pointer uintptr to call stack information. The call stack information is collected by Callers functions in runtime environments, callers functions are the first related functions, and run.callers functions in Go language are mainly used for returning the function call stack information. Wherein runtime environment package is a library function in Go language, runtime is responsible for interacting with the underlying operating system, callers functions in runtime environment get call stack information. Finally, a type st is defined for saving call stack information and returning the address of the st.
It should be noted that, the slice type in the Go language includes a plurality of elements, the unsigned pointers are stored in the slice type, the position of each element stores one unsigned pointer, and the address of the call stack information is accessed through the unsigned pointer, so that the memory space required for storing the call stack information is saved, and the utilization rate of the call stack is improved.
In operation S220, a second type is defined to store call stack information error information, the second type including the first type and the error information for simultaneously outputting the call stack information and the error information.
According to an embodiment of the present disclosure, the second type comprises a structural type. In the Go language, the structure is a type that is user-defined, is an aggregated data type, and is an entity that is aggregated from zero or more arbitrary types of values. Each value becomes a member of the structure.
For example, a structure is defined for storing error information and call stack information, and the structure is named fund, including a string msg of error information and call stack information stack.
In operation S230, a second correlation function is declared such that after the second correlation function execution ends, the second type is returned to complete the instantiation of the error type.
According to the embodiment of the disclosure, the second correlation function comprises a function name, a parameter type and a return type of a third correlation function to be consistent so as to improve compatibility, wherein the third correlation function comprises a function capable of realizing the error type in a standard library.
Most of the time, instantiating an object opens up memory space for the object.
For example, the second correlation function of the present statement may include a New function and a Errorf function. The New function is used for returning a fund structural body pointer which is taken as error and contains character string information and a call stack, and the Errorf function is used for returning a fund structural body pointer which is taken as error and contains character string information and a call stack. The New function and Errorf functions are applied to different application scenarios.
Specifically, the function names, parameter types, and return types in the New and Errorf functions are kept consistent with the third related functions New and Errorf in the standard library. It should be noted that, the third correlation function in the standard library. The error is the error type, and needs to be instantiated by returning a function to the second type (i.e. the structure fund), and memory space is allocated, and mainly call information and other parameters are returned, where the other parameters may be error information. The New function and Errorf function of the second correlation function are different due to the different parameters, so that different functions are adopted in different implementation environments.
Embodiments of the present disclosure maintain function names, parameter types, and return types consistent with a third correlation function in a standard library by declaring the second correlation function. The function stated by the user has the same strong generalization capability as the function in the standard library, so that the Go language-based error processing method disclosed by the invention is rich in application scenes.
In operation S240, outputting the call stack information and the error information is completed based on the instantiated error type.
According to the embodiment of the disclosure, the package and the output of the call stack information are performed, so that the simultaneous output of the error information and the call stack information is completed, the problem that the call stack information cannot be directly acquired and the error processing cannot be performed by a standard library based on the Go language in the prior art is solved, and the efficiency and the processing speed of the error processing in the actual development test are improved.
Fig. 3 schematically illustrates a flowchart of a call stack information output method according to an embodiment of the present disclosure.
As shown in fig. 3, the call stack information output method of this embodiment includes operations S310 to S330, and the transaction processing method may be executed by the server 105.
In operation S310, call stack information of the second type and the error information are acquired based on the instantiated error type, the call information including first character information.
In operation S320, the first character information in the call stack is formatted to obtain second character information.
In operation S330, the error information and the second character information are output.
For example, an Error function is used to output Error information in a scenario where only Error information needs to be output. And using a Format function to Format call stack information, and printing the call stack information, namely the first character information, into identifiable second character information.
In the embodiment of the disclosure, after the unrecognizable first character information is formatted and converted into the recognizable second character information, the recognizable second character information is output for the user to check.
Based on the error processing method based on the Go language, the disclosure also provides an error processing device based on the Go language. The device will be described in detail below in connection with fig. 4.
Fig. 4 schematically shows a block diagram of an error handling apparatus based on Go language according to an embodiment of the present disclosure.
As shown in fig. 4, the Go language-based error processing apparatus 400 of this embodiment includes a first type definition module 410, a second type first module 420, a function declaration module 430, and an output module 440.
The first type definition module 410 is configured to define a first type to store call stack information, where the call stack information is obtained based on calling a first related function. In an embodiment, the first type definition module 410 may be configured to perform the operation S210 described above, which is not described herein.
The second type definition module 420 is configured to define a second type for storing call stack information error information, where the second type includes the first type and the error information, and is configured to output the call stack information and the error information at the same time. In an embodiment, the second type definition module 420 may be configured to perform the operation S220 described above, which is not described herein.
The function declaration module 430 is configured to declare a second correlation function, so that after execution of the second correlation function ends, the second type is returned to complete instantiation of the error type. In an embodiment, the function declaration module 430 may be configured to perform the operation S230 described above, which is not described herein.
The output module 440 is configured to complete outputting the call stack information and the error information based on the instantiated error type. In an embodiment, the output module 440 may be configured to perform the operation S240 described above, which is not described herein.
According to an embodiment of the disclosure, the first type includes a slice type and the second type includes a structure type, wherein the slice type includes a plurality of elements to hold a plurality of unsigned pointers, each of the unsigned pointers pointing to a memory address holding each of the call stack information.
According to the embodiment of the disclosure, the second correlation function is declared, so that after the execution of the second correlation function is finished, the second type is returned to instantiate the error type, wherein the second correlation function comprises a function name, a parameter type and a return type which are consistent with a third correlation function to improve compatibility, and the third correlation function comprises a function capable of realizing the error type in a standard library.
The output module comprises an acquisition unit, a formatting unit and an output unit, wherein the acquisition unit is used for acquiring call stack information of the second type and the error information based on the instantiated error type, the call information comprises first character information, the formatting unit is used for carrying out formatting processing on the first character information in the call stack to obtain second character information, and the output unit is used for outputting the error information and the second character information.
According to an embodiment of the present disclosure, any of the first type definition module 410, the second type first module 420, the function declaration module 430, and the output module 440 may be combined in one module to be implemented, or any of the modules may be split into a plurality of modules. Or at least some of the functionality of one or more of the modules may be combined with, and implemented in, at least some of the functionality of other modules. According to embodiments of the present disclosure, at least one of the first type definition module 410, the second type first module 420, the function declaration module 430, and the output module 440 may be implemented at least in part as a hardware circuit, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system-on-chip, a system-on-substrate, a system-on-package, an Application Specific Integrated Circuit (ASIC), or in hardware or firmware, such as any other reasonable manner of integrating or packaging the circuits, or in any one of or a suitable combination of three of software, hardware, and firmware. Or at least one of the first type definition module 410, the second type first module 420, the function declaration module 430, and the output module 440 may be at least partially implemented as a computer program module that, when executed, performs the corresponding function.
Fig. 5 schematically illustrates a block diagram of an electronic device adapted to implement an error handling method based on the Go language, according to an embodiment of the disclosure.
As shown in fig. 5, an electronic device 500 according to an embodiment of the present disclosure includes a processor 501 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM) 502 or a program loaded from a storage section 508 into a Random Access Memory (RAM) 503. The processor 501 may include, for example, a general purpose microprocessor (e.g., a CPU), an instruction set processor and/or an associated chipset and/or a special purpose microprocessor (e.g., an Application Specific Integrated Circuit (ASIC)), or the like. The processor 501 may also include on-board memory for caching purposes. The processor 501 may comprise a single processing unit or a plurality of processing units for performing different actions of the method flows according to embodiments of the disclosure.
In the RAM 503, various programs and data required for the operation of the electronic apparatus 500 are stored. The processor 501, ROM 502, and RAM 503 are connected to each other by a bus 504. The processor 501 performs various operations of the method flow according to the embodiments of the present disclosure by executing programs in the ROM 502 and/or the RAM 503. Note that the program may be stored in one or more memories other than the ROM 502 and the RAM 503. The processor 501 may also perform various operations of the method flow according to embodiments of the present disclosure by executing programs stored in the one or more memories.
According to an embodiment of the present disclosure, the electronic device 500 may also include an input/output (I/O) interface 505, the input/output (I/O) interface 505 also being connected to the bus 504. The electronic device 500 may also include one or more of an input section 506 including a keyboard, mouse, etc., an output section 507 including a Cathode Ray Tube (CRT), liquid Crystal Display (LCD), etc., and speaker, etc., a storage section 508 including a hard disk, etc., and a communication section 509 including a network interface card such as a LAN card, modem, etc., connected to the I/O interface 505. The communication section 509 performs communication processing via a network such as the internet. The drive 510 is also connected to the I/O interface 505 as needed. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as needed so that a computer program read therefrom is mounted into the storage section 508 as needed.
The present disclosure also provides a computer-readable storage medium that may be included in the apparatus/device/system described in the above embodiments, or may exist alone without being assembled into the apparatus/device/system. The computer-readable storage medium carries one or more programs which, when executed, implement methods in accordance with embodiments of the present disclosure.
According to embodiments of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium, which may include, for example, but is not limited to, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the context of this disclosure, a computer-readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device. For example, according to embodiments of the present disclosure, the computer-readable storage medium may include ROM 502 and/or RAM 503 and/or one or more memories other than ROM 502 and RAM 503 described above.
Embodiments of the present disclosure also include a computer program product comprising a computer program containing program code for performing the methods shown in the flowcharts. The program code, when executed in a computer system, causes the computer system to implement the item recommendation method provided by embodiments of the present disclosure.
The above-described functions defined in the system/apparatus of the embodiments of the present disclosure are performed when the computer program is executed by the processor 501. The systems, apparatus, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the disclosure.
In one embodiment, the computer program may be based on a tangible storage medium such as an optical storage device, a magnetic storage device, or the like. In another embodiment, the computer program may also be transmitted, distributed, and downloaded and installed in the form of a signal on a network medium, and/or installed from a removable medium 511 via the communication portion 509. The computer program may comprise program code that is transmitted using any appropriate network medium, including but not limited to wireless, wireline, etc., or any suitable combination of the preceding.
In such an embodiment, the computer program may be downloaded and installed from a network via the communication portion 509, and/or installed from the removable media 511. The above-described functions defined in the system of the embodiments of the present disclosure are performed when the computer program is executed by the processor 501. The systems, devices, apparatus, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the disclosure.
According to embodiments of the present disclosure, program code for performing computer programs provided by embodiments of the present disclosure may be written in any combination of one or more programming languages, and in particular, such computer programs may be implemented in high-level procedural and/or object-oriented programming languages, and/or assembly/machine languages. Programming languages include, but are not limited to, such as Java, c++, python, "C" or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, partly on a remote computing device, or entirely on the remote computing device or server. In the case of remote computing devices, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., connected via the Internet using an Internet service provider).
The flowcharts and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Those skilled in the art will appreciate that the features recited in the various embodiments of the disclosure and/or in the claims may be provided in a variety of combinations and/or combinations, even if such combinations or combinations are not explicitly recited in the disclosure. In particular, the features recited in the various embodiments of the present disclosure and/or the claims may be variously combined and/or combined without departing from the spirit and teachings of the present disclosure. All such combinations and/or combinations fall within the scope of the present disclosure.
The embodiments of the present disclosure are described above. These examples are for illustrative purposes only and are not intended to limit the scope of the present disclosure. Although the embodiments are described above separately, this does not mean that the measures in the embodiments cannot be used advantageously in combination. The scope of the disclosure is defined by the appended claims and equivalents thereof. Various alternatives and modifications can be made by those skilled in the art without departing from the scope of the disclosure, and such alternatives and modifications are intended to fall within the scope of the disclosure.