github.com/gogf/gf@v1.16.9/errors/gerror/gerror_option.go (about) 1 // Copyright GoFrame 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 gerror 8 9 import "github.com/gogf/gf/errors/gcode" 10 11 // Option is option for creating error. 12 type Option struct { 13 Error error // Wrapped error if any. 14 Stack bool // Whether recording stack information into error. 15 Text string // Error text, which is created by New* functions. 16 Code gcode.Code // Error code if necessary. 17 } 18 19 // NewOption creates and returns an error with Option. 20 // It is the senior usage for creating error, which is often used internally in framework. 21 func NewOption(option Option) error { 22 err := &Error{ 23 error: option.Error, 24 text: option.Text, 25 code: option.Code, 26 } 27 if option.Stack { 28 err.stack = callers() 29 } 30 return err 31 }