restructure code an bit
This commit is contained in:
parent
f8687082c3
commit
4628fc7519
6 changed files with 54 additions and 17 deletions
5
README.md
Normal file
5
README.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
# Merith's Personal collection of utilies and commands
|
||||
|
||||
This is my personal collection of golang packages
|
||||
|
||||
`main.go` is my jank way of making tests since I have zero clue how to use go tests
|
27
debug/debugPrint.go
Normal file
27
debug/debugPrint.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package debug
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"log"
|
||||
)
|
||||
|
||||
var (
|
||||
Enabled bool = false
|
||||
DebugTitle string = "DEBUG"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// register debug flag
|
||||
flag.BoolVar(&Enabled, "debug", false, "Enable Debug Mode")
|
||||
}
|
||||
|
||||
// Usage:
|
||||
// utils.Debug.Enabled = true
|
||||
// utils.Debug.Print("Hello World")
|
||||
// Output: DEBUG Hello World
|
||||
|
||||
func Print(message ...any) {
|
||||
if Enabled {
|
||||
log.Println(DebugTitle, message)
|
||||
}
|
||||
}
|
2
go.mod
2
go.mod
|
@ -1,3 +1,3 @@
|
|||
module git.merith.xyz/packages/go
|
||||
module git.merith.xyz/packages/utils
|
||||
|
||||
go 1.18
|
||||
|
|
19
main.go
Normal file
19
main.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
|
||||
"git.merith.xyz/packages/utils/debug"
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
// this will be expanded as more and more tests are added
|
||||
if !debug.Enabled {
|
||||
flag.Usage()
|
||||
}
|
||||
|
||||
// Test debug.Print()
|
||||
debug.Print("Hello World")
|
||||
}
|
2
makefile
Normal file
2
makefile
Normal file
|
@ -0,0 +1,2 @@
|
|||
default:
|
||||
go run ./
|
|
@ -1,16 +0,0 @@
|
|||
package utils
|
||||
|
||||
import "log"
|
||||
|
||||
var (
|
||||
DebugMode bool = false
|
||||
DebugTitle string = "DEBUG"
|
||||
)
|
||||
|
||||
// DebugPrint prints the given message to the log if the debug flag is set.
|
||||
func DebugPrint(message ...any) {
|
||||
if DebugMode {
|
||||
// add DebugTitle to the message
|
||||
log.Println(DebugTitle, message)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue