NE
Neaj-Morshad-101/go-debug-watch
A lightweight, colorful debugging library for Go that provides pretty-printed variable inspection during development.
Go Debug Watch
A lightweight, colorful debugging library for Go that provides pretty-printed variable inspection during development.
Features
- ๐จ Colorized output for better readability
- ๐ Automatic variable name detection
- โฐ Timestamp for each watch call
- ๐ File and line number tracking
- ๐ฏ Function name context
- ๐ญ Pretty printing for complex types
- ๐ช Type-safe with Go generics
- ๐ Zero external dependencies
Installation
go get github.com/Neaj-Morshad-101/go-debug-watch/pkg/watchUsage
import "github.com/Neaj-Morshad-101/go-debug-watch/pkg/watch"
func main() {
// Watch primitive types
name := "John Doe"
watch.Watch(name)
// Output: [12:34:56.789] (main) name = "John Doe" // at main.go:6
// Watch slices
numbers := []int{1, 2, 3}
watch.Watch(numbers)
// Output: [12:34:56.789] (main) numbers = Slice [
// 1 2 3
// ] // at main.go:10
// Watch maps
scores := map[string]int{"math": 95, "science": 88}
watch.Watch(scores)
// Output: [12:34:56.789] (main) scores = Map {
// math: 95,
// science: 88
// } // at main.go:14
// Watch structs
type Person struct {
Name string
Age int
}
person := Person{Name: "Alice", Age: 30}
watch.Watch(person)
// Output: [12:34:56.789] (main) person = Struct {
// Name: "Alice",
// Age: 30
// } // at main.go:23
}Output Format
Each watch call produces a line of output with the following components:
- Timestamp:
[HH:MM:SS.mmm] - Function name:
(functionName) - Variable name: Automatically detected from source
- Value: Pretty-printed with type information
- Location: File and line number
Color Scheme
- ๐ต Blue: Timestamps
- ๐ก Yellow: Function names
- ๐ข Green: Variable names
- ๐ด Red: Nil values
- ๐ฃ Purple: Type information
- ๐ฆ Cyan: Values
- โฌ Gray: File locations
Supported Types
- All primitive types
- Strings
- Slices and Arrays
- Maps
- Structs
- Pointers
- Complex types (nested structures)
- nil values
Development
Running Tests
go test ./pkg/watchBenchmarks
go test -bench=. ./pkg/watchContributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Acknowledgments
- Inspired by the debug patterns in various programming languages
- Built with โค๏ธ for the Go community