mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2024-12-05 10:02:47 +00:00
6c0d93c6cb
* [chore]: Bump github.com/prometheus/client_golang from 1.18.0 to 1.19.1 Bumps [github.com/prometheus/client_golang](https://github.com/prometheus/client_golang) from 1.18.0 to 1.19.1. - [Release notes](https://github.com/prometheus/client_golang/releases) - [Changelog](https://github.com/prometheus/client_golang/blob/main/CHANGELOG.md) - [Commits](https://github.com/prometheus/client_golang/compare/v1.18.0...v1.19.1) --- updated-dependencies: - dependency-name: github.com/prometheus/client_golang dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * [chore]: Bump github.com/KimMachineGun/automemlimit from 0.6.0 to 0.6.1 Bumps [github.com/KimMachineGun/automemlimit](https://github.com/KimMachineGun/automemlimit) from 0.6.0 to 0.6.1. - [Release notes](https://github.com/KimMachineGun/automemlimit/releases) - [Commits](https://github.com/KimMachineGun/automemlimit/compare/v0.6.0...v0.6.1) --- updated-dependencies: - dependency-name: github.com/KimMachineGun/automemlimit dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * [chore]: Bump github.com/tdewolff/minify/v2 from 2.20.20 to 2.20.24 Bumps [github.com/tdewolff/minify/v2](https://github.com/tdewolff/minify) from 2.20.20 to 2.20.24. - [Release notes](https://github.com/tdewolff/minify/releases) - [Commits](https://github.com/tdewolff/minify/compare/v2.20.20...v2.20.24) --- updated-dependencies: - dependency-name: github.com/tdewolff/minify/v2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * [chore]: Bump github.com/go-swagger/go-swagger Bumps [github.com/go-swagger/go-swagger](https://github.com/go-swagger/go-swagger) from 0.30.6-0.20240418033037-c46c303aaa02 to 0.31.0. - [Release notes](https://github.com/go-swagger/go-swagger/releases) - [Changelog](https://github.com/go-swagger/go-swagger/blob/master/.goreleaser.yml) - [Commits](https://github.com/go-swagger/go-swagger/commits/v0.31.0) --- updated-dependencies: - dependency-name: github.com/go-swagger/go-swagger dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> * [chore]: Bump github.com/gin-gonic/gin from 1.9.1 to 1.10.0 Bumps [github.com/gin-gonic/gin](https://github.com/gin-gonic/gin) from 1.9.1 to 1.10.0. - [Release notes](https://github.com/gin-gonic/gin/releases) - [Changelog](https://github.com/gin-gonic/gin/blob/master/CHANGELOG.md) - [Commits](https://github.com/gin-gonic/gin/compare/v1.9.1...v1.10.0) --- updated-dependencies: - dependency-name: github.com/gin-gonic/gin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
112 lines
2.9 KiB
Go
112 lines
2.9 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 = 18
|
|
|
|
// 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)
|
|
|
|
// DebugPrintFunc indicates debug log output format.
|
|
var DebugPrintFunc func(format string, values ...interface{})
|
|
|
|
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() {
|
|
return
|
|
}
|
|
|
|
if DebugPrintFunc != nil {
|
|
DebugPrintFunc(format, values...)
|
|
return
|
|
}
|
|
|
|
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.18+.
|
|
|
|
`)
|
|
}
|
|
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)
|
|
}
|
|
}
|