aboutsummaryrefslogtreecommitdiff
path: root/lib/debug/debug.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2018-09-14 00:42:28 +0700
committerShulhan <ms@kilabit.info>2018-09-14 04:09:00 +0700
commitbe746238c08dc36991657c987d9d1d2bef9c954a (patch)
treeba147bf169a1db3faa7df3d39ded6e72a236342e /lib/debug/debug.go
parent29654838d11ae11f82f4609acdc38b2427cae5a7 (diff)
downloadpakakeh.go-be746238c08dc36991657c987d9d1d2bef9c954a.tar.xz
lib/debug: new package for debugging
The debug package provide global Value that is initialized from environment variable "DEBUG". User only need to include the package, and all initialization will be handled by init().
Diffstat (limited to 'lib/debug/debug.go')
-rw-r--r--lib/debug/debug.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/debug/debug.go b/lib/debug/debug.go
new file mode 100644
index 00000000..5c88c4d2
--- /dev/null
+++ b/lib/debug/debug.go
@@ -0,0 +1,33 @@
+// Copyright 2018, Shulhan <ms@kilabit.info>. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Package debug provide global debug variable, initialized through
+// environment variable "DEBUG" or directly.
+package debug
+
+import (
+ "os"
+ "strconv"
+ "sync"
+)
+
+var (
+ // Value contains DEBUG value from environment.
+ Value = 0
+ once sync.Once
+)
+
+func loadEnvironment() {
+ v := os.Getenv("DEBUG")
+ if len(v) > 0 {
+ Value, _ = strconv.Atoi(v)
+ }
+}
+
+//
+// init initialize debug from system environment.
+//
+func init() {
+ once.Do(loadEnvironment)
+}