File tree Expand file tree Collapse file tree 5 files changed +32
-16
lines changed
Expand file tree Collapse file tree 5 files changed +32
-16
lines changed Original file line number Diff line number Diff line change 11coverage.txt
2+ coverage /
Original file line number Diff line number Diff line change 11# Debug for Golang
22
3- - [ ![ Go CI] ( https://github.com/alibabacloud-go/debug/actions/workflows/go.yml/badge.svg )] ( https://github.com/alibabacloud-go/debug/actions/workflows/go.yml )
4- - [ ![ codecov] ( https://codecov.io/gh/alibabacloud-go/debug/branch/master/graph/badge.svg )] ( https://codecov.io/gh/alibabacloud-go/debug )
3+ [ ![ Go CI] ( https://github.com/alibabacloud-go/debug/actions/workflows/go.yml/badge.svg )] ( https://github.com/alibabacloud-go/debug/actions/workflows/go.yml )
4+ [ ![ codecov] ( https://codecov.io/gh/alibabacloud-go/debug/branch/master/graph/badge.svg )] ( https://codecov.io/gh/alibabacloud-go/debug )
5+ [ ![ Go Reference] ( https://pkg.go.dev/badge/github.com/alibabacloud-go/debug.svg )] ( https://pkg.go.dev/github.com/alibabacloud-go/debug )
56
67## Usage
78
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1+ // Package debug is a library to display debug info that control by enviroment variable DEBUG
2+ //
3+ // # Example
4+ //
5+ // package main
6+ // // import the package
7+ // import "github.com/alibabacloud-go/debug/debug"
8+ //
9+ // // init a debug method
10+ // var d = debug.Init("sdk")
11+ //
12+ // func main() {
13+ // // try `go run demo.go`
14+ // // and `DEBUG=sdk go run demo.go`
15+ // d("this debug information just print when DEBUG environment variable was set")
16+ // }
17+ //
18+ // When you run application with `DEBUG=sdk go run main.go`, it will display logs. Otherwise
19+ // it do nothing
120package debug
221
322import (
@@ -6,6 +25,8 @@ import (
625 "strings"
726)
827
28+ // Debug is a method that display logs, it is useful for developer to trace program running
29+ // details when troubleshooting
930type Debug func (format string , v ... interface {})
1031
1132var hookGetEnv = func () string {
@@ -16,6 +37,7 @@ var hookPrint = func(input string) {
1637 fmt .Println (input )
1738}
1839
40+ // Init returns a debug method that based the enviroment variable DEBUG value
1941func Init (flag string ) Debug {
2042 enable := false
2143
Original file line number Diff line number Diff line change @@ -26,7 +26,9 @@ func TestMain_Matched(t *testing.T) {
2626 }
2727 debug := Init ("sdk" )
2828 debug ("%s" , "testing" )
29- assertEqual (t , "testing" , output )
29+ if output != "testing" {
30+ t .Errorf ("%v != %v" , output , "testing" )
31+ }
3032}
3133
3234func TestMain_UnMatched (t * testing.T ) {
@@ -46,5 +48,7 @@ func TestMain_UnMatched(t *testing.T) {
4648 }
4749 debug := Init ("sdk" )
4850 debug ("%s" , "testing" )
49- assertEqual (t , "" , output )
51+ if output != "" {
52+ t .Errorf ("output failed" )
53+ }
5054}
You can’t perform that action at this time.
0 commit comments