Skip to content

Commit 42d986e

Browse files
committed
refine for go doc
1 parent 6748299 commit 42d986e

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
coverage.txt
2+
coverage/

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
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

debug/assert.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

debug/debug.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
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
120
package debug
221

322
import (
@@ -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
930
type Debug func(format string, v ...interface{})
1031

1132
var 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
1941
func Init(flag string) Debug {
2042
enable := false
2143

debug/debug_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff 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

3234
func 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
}

0 commit comments

Comments
 (0)