github.com/gogf/gf/v2@v2.7.4/errors/gcode/gcode_local.go (about)

     1  // Copyright GoFrame gf Author(https://goframe.org). All Rights Reserved.
     2  //
     3  // This Source Code Form is subject to the terms of the MIT License.
     4  // If a copy of the MIT was not distributed with this file,
     5  // You can obtain one at https://github.com/gogf/gf.
     6  
     7  package gcode
     8  
     9  import "fmt"
    10  
    11  // localCode is an implementer for interface Code for internal usage only.
    12  type localCode struct {
    13  	code    int         // Error code, usually an integer.
    14  	message string      // Brief message for this error code.
    15  	detail  interface{} // As type of interface, it is mainly designed as an extension field for error code.
    16  }
    17  
    18  // Code returns the integer number of current error code.
    19  func (c localCode) Code() int {
    20  	return c.code
    21  }
    22  
    23  // Message returns the brief message for current error code.
    24  func (c localCode) Message() string {
    25  	return c.message
    26  }
    27  
    28  // Detail returns the detailed information of current error code,
    29  // which is mainly designed as an extension field for error code.
    30  func (c localCode) Detail() interface{} {
    31  	return c.detail
    32  }
    33  
    34  // String returns current error code as a string.
    35  func (c localCode) String() string {
    36  	if c.detail != nil {
    37  		return fmt.Sprintf(`%d:%s %v`, c.code, c.message, c.detail)
    38  	}
    39  	if c.message != "" {
    40  		return fmt.Sprintf(`%d:%s`, c.code, c.message)
    41  	}
    42  	return fmt.Sprintf(`%d`, c.code)
    43  }