godev

package module
Version: v1.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2020 License: Apache-2.0 Imports: 12 Imported by: 11

README

godev

😄 a collection of debugging functions I often use during development

CircleCI GoDoc License GitHub release Go Report Card CodeFactor codecov Sourcegraph Made by Manfred Touron

Usage

fmt.Println(godev.JSON(something))
fmt.Println(godev.PrettyJSON(something))

Install

Using go
$ go get -u moul.io/godev

License

© 2019 Manfred Touron - Apache-2.0 License

Documentation

Overview

message from the author:

+--------------------------------------------------------------+
| * * * ░░░░░░░░░░░░░░░░░░░░  Hello  ░░░░░░░░░░░░░░░░░░░░░░░░░░|
+--------------------------------------------------------------+
|                                                              |
|     ++              ______________________________________   |
|     ++++           /                                      \  |
|      ++++          |                                      |  |
|    ++++++++++      |   Feel free to contribute to this    |  |
|   +++       |      |       project or contact me on       |  |
|   ++         |     |    manfred.life if you like this     |  |
|   +  -==   ==|     |               project!               |  |
|  (   <*>   <*>     |                                      |  |
|   |          |    /|                  :)                  |  |
|   |         _)   / |                                      |  |
|   |      +++    /  \______________________________________/  |
|    \      =+   /                                             |
|     \      +                                                 |
|     |\++++++                                                 |
|     |  ++++      ||//                                        |
|  ___|   |___    _||/__                                     __|
| /    ---    \   \|  |||                   __ _  ___  __ __/ /|
|/  |       |  \    \ /                    /  ' \/ _ \/ // / / |
||  |       |  |    | |                   /_/_/_/\___/\_,_/_/  |
+--------------------------------------------------------------+

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug added in v1.2.0

func Debug()
Example
package main

import (
	"os"

	"moul.io/godev"
)

func main() {
	godev.SetDebugOutput(os.Stdout)
	godev.Debug()
	godev.Debug()
}
Output:

[godev:debug] printfdebugging_test.go:12
[godev:debug] printfdebugging_test.go:13

func Debugf added in v1.2.0

func Debugf(format string, args ...interface{})
Example
package main

import (
	"os"

	"moul.io/godev"
)

func main() {
	godev.SetDebugOutput(os.Stdout)
	godev.Debugf("hello: %d", 42)
	godev.Debugf("world")
}
Output:

[godev:debug] printfdebugging_test.go:21 hello: 42
[godev:debug] printfdebugging_test.go:22 world

func JSON

func JSON(input interface{}) string
Example
package main

import (
	"fmt"

	"moul.io/godev"
)

func main() {
	fmt.Println(godev.JSON([]string{"hello", "world"}))
	fmt.Println(godev.JSON(42))
	fmt.Println(godev.JSON(nil))
}
Output:

["hello","world"]
42
null

func JSONPB added in v1.5.0

func JSONPB(input proto.Message) string
Example
package main

import (
	"fmt"

	pb "github.com/gogo/protobuf/jsonpb/jsonpb_test_proto"
	"moul.io/godev"
)

func main() {
	msg := pb.Mappy{Enumy: map[string]pb.Numeral{"XIV": pb.Numeral_ROMAN}}
	fmt.Println(godev.JSONPB(&msg))
}
Output:

{"enumy":{"XIV":"ROMAN"}}

func PrettyJSON

func PrettyJSON(input interface{}) string
Example
package main

import (
	"fmt"

	"moul.io/godev"
)

func main() {
	fmt.Println(godev.PrettyJSON([]string{"hello", "world"}))
	fmt.Println(godev.PrettyJSON(42))
	fmt.Println(godev.PrettyJSON(nil))
}
Output:

[
  "hello",
  "world"
]
42
null

func PrettyJSONPB added in v1.5.0

func PrettyJSONPB(input proto.Message) string
Example
package main

import (
	"fmt"

	pb "github.com/gogo/protobuf/jsonpb/jsonpb_test_proto"
	"moul.io/godev"
)

func main() {
	msg := pb.Mappy{Enumy: map[string]pb.Numeral{"XIV": pb.Numeral_ROMAN}}
	fmt.Println(godev.PrettyJSONPB(&msg))
}
Output:

{
  "enumy": {
    "XIV": "ROMAN"
  }
}

func Sdebug added in v1.6.0

func Sdebug() string
Example
package main

import (
	"fmt"

	"moul.io/godev"
)

func main() {
	fmt.Println(godev.Sdebug())
	fmt.Println(godev.Sdebug())
}
Output:

[godev:debug] printfdebugging_test.go:29
[godev:debug] printfdebugging_test.go:30

func Sdebugf added in v1.6.0

func Sdebugf(format string, args ...interface{}) string
Example
package main

import (
	"fmt"

	"moul.io/godev"
)

func main() {
	fmt.Println(godev.Sdebugf("hello: %d", 42))
	fmt.Println(godev.Sdebugf("world"))
}
Output:

[godev:debug] printfdebugging_test.go:37 hello: 42
[godev:debug] printfdebugging_test.go:38 world

func SetDebugOutput added in v1.2.0

func SetDebugOutput(writer io.Writer)

func Stacktrace added in v1.7.0

func Stacktrace() string
Example
package main

import (
	"fmt"

	"moul.io/godev"
)

func main() {
	fmt.Println(godev.Stacktrace())
}
Output:

func Uptime added in v1.1.0

func Uptime() time.Duration
Example
package main

import (
	"fmt"
	"time"

	"moul.io/godev"
)

func main() {
	uptime := godev.Uptime()
	if uptime > 1*time.Nanosecond && uptime < 1*time.Minute {
		fmt.Println("uptime is less than a minute")
	}
}
Output:

uptime is less than a minute

func YAML added in v1.1.0

func YAML(input interface{}) string
Example
package main

import (
	"fmt"

	"moul.io/godev"
)

func main() {
	fmt.Println(godev.YAML([]string{"hello", "world"}))
	fmt.Println(godev.YAML(42))
	fmt.Println(godev.YAML(nil))
}
Output:

- hello
- world
42
null

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL