github.com/gogf/gf@v1.16.9/net/ghttp/ghttp_func.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 ghttp 8 9 import ( 10 "github.com/gogf/gf/errors/gcode" 11 "github.com/gogf/gf/errors/gerror" 12 "github.com/gogf/gf/net/ghttp/internal/httputil" 13 ) 14 15 // BuildParams builds the request string for the http client. The <params> can be type of: 16 // string/[]byte/map/struct/*struct. 17 // 18 // The optional parameter <noUrlEncode> specifies whether ignore the url encoding for the data. 19 func BuildParams(params interface{}, noUrlEncode ...bool) (encodedParamStr string) { 20 return httputil.BuildParams(params, noUrlEncode...) 21 } 22 23 // niceCallFunc calls function <f> with exception capture logic. 24 func niceCallFunc(f func()) { 25 defer func() { 26 if exception := recover(); exception != nil { 27 switch exception { 28 case exceptionExit, exceptionExitAll: 29 return 30 31 default: 32 if _, ok := exception.(errorStack); ok { 33 // It's already an error that has stack info. 34 panic(exception) 35 } else { 36 // Create a new error with stack info. 37 // Note that there's a skip pointing the start stacktrace 38 // of the real error point. 39 if err, ok := exception.(error); ok { 40 if gerror.Code(err) != gcode.CodeNil { 41 panic(err) 42 } else { 43 panic(gerror.WrapCodeSkip(gcode.CodeInternalError, 1, err, "")) 44 } 45 } else { 46 panic(gerror.NewCodeSkipf(gcode.CodeInternalError, 1, "%+v", exception)) 47 } 48 } 49 } 50 } 51 }() 52 f() 53 }