summaryrefslogtreecommitdiff
path: root/vendor/codeberg.org
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/codeberg.org')
-rw-r--r--vendor/codeberg.org/gruf/go-debug/LICENSE9
-rw-r--r--vendor/codeberg.org/gruf/go-debug/README.md37
-rw-r--r--vendor/codeberg.org/gruf/go-debug/debug.go13
-rw-r--r--vendor/codeberg.org/gruf/go-debug/debug_env.go9
-rw-r--r--vendor/codeberg.org/gruf/go-debug/debug_off.go7
-rw-r--r--vendor/codeberg.org/gruf/go-debug/debug_on.go7
-rw-r--r--vendor/codeberg.org/gruf/go-debug/pprof_off.go16
-rw-r--r--vendor/codeberg.org/gruf/go-debug/pprof_on.go63
-rw-r--r--vendor/codeberg.org/gruf/go-debug/run_tests.sh17
9 files changed, 178 insertions, 0 deletions
diff --git a/vendor/codeberg.org/gruf/go-debug/LICENSE b/vendor/codeberg.org/gruf/go-debug/LICENSE
new file mode 100644
index 000000000..e4163ae35
--- /dev/null
+++ b/vendor/codeberg.org/gruf/go-debug/LICENSE
@@ -0,0 +1,9 @@
+MIT License
+
+Copyright (c) 2022 gruf
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/vendor/codeberg.org/gruf/go-debug/README.md b/vendor/codeberg.org/gruf/go-debug/README.md
new file mode 100644
index 000000000..44cbc9d5f
--- /dev/null
+++ b/vendor/codeberg.org/gruf/go-debug/README.md
@@ -0,0 +1,37 @@
+# go-debug
+
+This library provides a very simple method for compile-time or runtime determined debug checks, set using build tags.
+
+The compile-time checks use Go constants, so when disabled your debug code will not be compiled.
+
+The possible build tags are:
+
+- "debug" || "" = debug determined at compile-time
+
+- "debugenv" = debug determined at runtime using the $DEBUG environment variable
+
+An example for how this works in practice can be seen by the following code:
+
+```
+func main() {
+ println("debug.DEBUG() =", debug.DEBUG())
+}
+```
+
+```
+# Debug determined at compile-time, it is disabled
+$ go run .
+debug.DEBUG() = false
+
+# Debug determined at compile-time, it is enabled
+$ go run -tags=debug .
+debug.DEBUG() = true
+
+# Debug determined at runtime, $DEBUG is not set
+$ go run -tags=debugenv .
+debug.DEBUG() = false
+
+# Debug determined at runtime, $DEBUG is set
+$ DEBUG=y go run -tags=debugenv .
+debug.DEBUG() = true
+``` \ No newline at end of file
diff --git a/vendor/codeberg.org/gruf/go-debug/debug.go b/vendor/codeberg.org/gruf/go-debug/debug.go
new file mode 100644
index 000000000..61e4eda41
--- /dev/null
+++ b/vendor/codeberg.org/gruf/go-debug/debug.go
@@ -0,0 +1,13 @@
+package debug
+
+// DEBUG returns whether debugging is enabled.
+func DEBUG() bool {
+ return debug
+}
+
+// Run will only call fn if DEBUG is enabled.
+func Run(fn func()) {
+ if debug {
+ fn()
+ }
+}
diff --git a/vendor/codeberg.org/gruf/go-debug/debug_env.go b/vendor/codeberg.org/gruf/go-debug/debug_env.go
new file mode 100644
index 000000000..7ab231b08
--- /dev/null
+++ b/vendor/codeberg.org/gruf/go-debug/debug_env.go
@@ -0,0 +1,9 @@
+//go:build debugenv
+// +build debugenv
+
+package debug
+
+import "os"
+
+// check if debug env variable is set
+var debug = (os.Getenv("DEBUG") != "")
diff --git a/vendor/codeberg.org/gruf/go-debug/debug_off.go b/vendor/codeberg.org/gruf/go-debug/debug_off.go
new file mode 100644
index 000000000..a7eb9daac
--- /dev/null
+++ b/vendor/codeberg.org/gruf/go-debug/debug_off.go
@@ -0,0 +1,7 @@
+//go:build !debug && !debugenv
+// +build !debug,!debugenv
+
+package debug
+
+// debug always off.
+const debug = false
diff --git a/vendor/codeberg.org/gruf/go-debug/debug_on.go b/vendor/codeberg.org/gruf/go-debug/debug_on.go
new file mode 100644
index 000000000..744d70178
--- /dev/null
+++ b/vendor/codeberg.org/gruf/go-debug/debug_on.go
@@ -0,0 +1,7 @@
+//go:build debug && !debugenv
+// +build debug,!debugenv
+
+package debug
+
+// debug always on.
+const debug = true
diff --git a/vendor/codeberg.org/gruf/go-debug/pprof_off.go b/vendor/codeberg.org/gruf/go-debug/pprof_off.go
new file mode 100644
index 000000000..5ad77ce0d
--- /dev/null
+++ b/vendor/codeberg.org/gruf/go-debug/pprof_off.go
@@ -0,0 +1,16 @@
+//go:build !debug && !debugenv
+// +build !debug,!debugenv
+
+package debug
+
+import "net/http"
+
+// ServePprof will start an HTTP server serving /debug/pprof only if debug enabled.
+func ServePprof(addr string) error {
+ return nil
+}
+
+// WithPprof will add /debug/pprof handling (provided by "net/http/pprof") only if debug enabled.
+func WithPprof(handler http.Handler) http.Handler {
+ return handler
+}
diff --git a/vendor/codeberg.org/gruf/go-debug/pprof_on.go b/vendor/codeberg.org/gruf/go-debug/pprof_on.go
new file mode 100644
index 000000000..a569ab823
--- /dev/null
+++ b/vendor/codeberg.org/gruf/go-debug/pprof_on.go
@@ -0,0 +1,63 @@
+//go:build debug || debugenv
+// +build debug debugenv
+
+package debug
+
+import (
+ "net/http"
+ "net/http/pprof"
+ "strings"
+)
+
+// ServePprof will start an HTTP server serving /debug/pprof only if debug enabled.
+func ServePprof(addr string) error {
+ if !debug {
+ // debug disabled in env
+ return nil
+ }
+ handler := WithPprof(nil)
+ return http.ListenAndServe(addr, handler)
+}
+
+// WithPprof will add /debug/pprof handling (provided by "net/http/pprof") only if debug enabled.
+func WithPprof(handler http.Handler) http.Handler {
+ if !debug {
+ // debug disabled in env
+ return handler
+ }
+
+ // Default serve mux is setup with pprof
+ pprofmux := http.DefaultServeMux
+
+ if pprofmux == nil {
+ // Someone nil'ed the default mux
+ pprofmux = &http.ServeMux{}
+ pprofmux.HandleFunc("/debug/pprof/", pprof.Index)
+ pprofmux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
+ pprofmux.HandleFunc("/debug/pprof/profile", pprof.Profile)
+ pprofmux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
+ pprofmux.HandleFunc("/debug/pprof/trace", pprof.Trace)
+ }
+
+ if handler == nil {
+ // Ensure handler is non-nil
+ handler = http.NotFoundHandler()
+ }
+
+ // Debug enabled, return wrapped handler func
+ return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) {
+ const prefix = "/debug/pprof"
+
+ // /debug/pprof(/.*)? -> pass to pprofmux
+ if strings.HasPrefix(r.URL.Path, prefix) {
+ path := r.URL.Path[len(prefix):]
+ if path == "" || path[0] == '/' {
+ pprofmux.ServeHTTP(rw, r)
+ return
+ }
+ }
+
+ // .* -> pass to handler
+ handler.ServeHTTP(rw, r)
+ })
+}
diff --git a/vendor/codeberg.org/gruf/go-debug/run_tests.sh b/vendor/codeberg.org/gruf/go-debug/run_tests.sh
new file mode 100644
index 000000000..f7ef1d60d
--- /dev/null
+++ b/vendor/codeberg.org/gruf/go-debug/run_tests.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+(
+ # Run in subshell with cmd echo
+ set -ex
+
+ # Run debug tests
+ DEBUG= go test -tags= -v
+ DEBUG= go test -tags=debug -v
+ DEBUG= go test -tags=debugenv -v
+ DEBUG=y go test -tags=debugenv -v
+ DEBUG=1 go test -tags=debugenv -v
+ DEBUG=y go test -tags=debugenv,debug -v
+ DEBUG=y go test -tags= -v
+)
+
+echo 'success!' \ No newline at end of file