GitHunt
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/watch

Usage

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/watch

Benchmarks

go test -bench=. ./pkg/watch

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Acknowledgments

  • Inspired by the debug patterns in various programming languages
  • Built with โค๏ธ for the Go community