mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2024-12-20 17:53:22 +00:00
a156188b3e
* update dependencies, bump Go version to 1.19 * bump test image Go version * update golangci-lint * update gotosocial-drone-build * sign * linting, go fmt * update swagger docs * update swagger docs * whitespace * update contributing.md * fuckin whoopsie doopsie * linterino, linteroni * fix followrequest test not starting processor * fix other api/client tests not starting processor * fix remaining tests where processor not started * bump go-runners version * don't check last-webfingered-at, processor may have updated this * update swagger command * update bun to latest version * fix embed to work the same as before with new bun Signed-off-by: kim <grufwub@gmail.com> Co-authored-by: tsmethurst <tobi.smethurst@protonmail.com>
101 lines
2.7 KiB
Go
101 lines
2.7 KiB
Go
// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
|
|
// Use of this source code is governed by a MIT style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package gin
|
|
|
|
import (
|
|
"fmt"
|
|
"html/template"
|
|
"runtime"
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
const ginSupportMinGoVer = 14
|
|
|
|
// IsDebugging returns true if the framework is running in debug mode.
|
|
// Use SetMode(gin.ReleaseMode) to disable debug mode.
|
|
func IsDebugging() bool {
|
|
return ginMode == debugCode
|
|
}
|
|
|
|
// DebugPrintRouteFunc indicates debug log output format.
|
|
var DebugPrintRouteFunc func(httpMethod, absolutePath, handlerName string, nuHandlers int)
|
|
|
|
func debugPrintRoute(httpMethod, absolutePath string, handlers HandlersChain) {
|
|
if IsDebugging() {
|
|
nuHandlers := len(handlers)
|
|
handlerName := nameOfFunction(handlers.Last())
|
|
if DebugPrintRouteFunc == nil {
|
|
debugPrint("%-6s %-25s --> %s (%d handlers)\n", httpMethod, absolutePath, handlerName, nuHandlers)
|
|
} else {
|
|
DebugPrintRouteFunc(httpMethod, absolutePath, handlerName, nuHandlers)
|
|
}
|
|
}
|
|
}
|
|
|
|
func debugPrintLoadTemplate(tmpl *template.Template) {
|
|
if IsDebugging() {
|
|
var buf strings.Builder
|
|
for _, tmpl := range tmpl.Templates() {
|
|
buf.WriteString("\t- ")
|
|
buf.WriteString(tmpl.Name())
|
|
buf.WriteString("\n")
|
|
}
|
|
debugPrint("Loaded HTML Templates (%d): \n%s\n", len(tmpl.Templates()), buf.String())
|
|
}
|
|
}
|
|
|
|
func debugPrint(format string, values ...any) {
|
|
if IsDebugging() {
|
|
if !strings.HasSuffix(format, "\n") {
|
|
format += "\n"
|
|
}
|
|
fmt.Fprintf(DefaultWriter, "[GIN-debug] "+format, values...)
|
|
}
|
|
}
|
|
|
|
func getMinVer(v string) (uint64, error) {
|
|
first := strings.IndexByte(v, '.')
|
|
last := strings.LastIndexByte(v, '.')
|
|
if first == last {
|
|
return strconv.ParseUint(v[first+1:], 10, 64)
|
|
}
|
|
return strconv.ParseUint(v[first+1:last], 10, 64)
|
|
}
|
|
|
|
func debugPrintWARNINGDefault() {
|
|
if v, e := getMinVer(runtime.Version()); e == nil && v <= ginSupportMinGoVer {
|
|
debugPrint(`[WARNING] Now Gin requires Go 1.14+.
|
|
|
|
`)
|
|
}
|
|
debugPrint(`[WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.
|
|
|
|
`)
|
|
}
|
|
|
|
func debugPrintWARNINGNew() {
|
|
debugPrint(`[WARNING] Running in "debug" mode. Switch to "release" mode in production.
|
|
- using env: export GIN_MODE=release
|
|
- using code: gin.SetMode(gin.ReleaseMode)
|
|
|
|
`)
|
|
}
|
|
|
|
func debugPrintWARNINGSetHTMLTemplate() {
|
|
debugPrint(`[WARNING] Since SetHTMLTemplate() is NOT thread-safe. It should only be called
|
|
at initialization. ie. before any route is registered or the router is listening in a socket:
|
|
|
|
router := gin.Default()
|
|
router.SetHTMLTemplate(template) // << good place
|
|
|
|
`)
|
|
}
|
|
|
|
func debugPrintError(err error) {
|
|
if err != nil && IsDebugging() {
|
|
fmt.Fprintf(DefaultErrorWriter, "[GIN-debug] [ERROR] %v\n", err)
|
|
}
|
|
}
|