Skip to content

Commit

Permalink
add example "main.go" + update example code in README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
C0DE8 committed May 9, 2020
1 parent 3d6aa49 commit ac0b6c9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ go get -u -v github.com/c0de8/bmfmt
package main

import (
"fmt"
bmfmt "github.com/c0de8/bmfmt"
)

Expand All @@ -28,26 +29,28 @@ func main() {
}

func example() {

m := map[string][]string{
"some-key": { "response" },
"Another-Hash-Key": { "first value", "second value" },
}

fmt.Println(m) // fmt the default formatting
/*
map[some-key:[response] Another-Hash-Key:[first value second value]]
map[some-key:[response] Another-Hash-Key:[first value second value]]
*/

bmfmt.Beautify(m) // significant more friendly formatting
err := bmfmt.Beautify(m) // significant more friendly formatting
if err != nil {
fmt.Println("ERROR (bmfmt.Beautify): " + err.Error())
}
/*
[ "some-key" string( 8) ]: "response" string( 8)
[ "Another-Hash-Key" string( 16) ]: "first value", "second value" string( 20)
[ "some-key" string( 8) ]: "response" string( 8)
[ "Another-Hash-Key" string( 16) ]: "first value", "second value" string( 23)
*/

}


```

## License
Expand Down
33 changes: 33 additions & 0 deletions examples/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main

import (
"fmt"
bmfmt "github.com/c0de8/bmfmt"
)

func main() {
example()
}

func example() {

m := map[string][]string{
"some-key": {"response"},
"Another-Hash-Key": {"first value", "second value"},
}

fmt.Println(m) // fmt the default formatting
/*
map[some-key:[response] Another-Hash-Key:[first value second value]]
*/

err := bmfmt.Beautify(m) // significant more friendly formatting
if err != nil {
fmt.Println("ERROR (bmfmt.Beautify): " + err.Error())
}
/*
[ "some-key" string( 8) ]: "response" string( 8)
[ "Another-Hash-Key" string( 16) ]: "first value", "second value" string( 23)
*/

}

0 comments on commit ac0b6c9

Please sign in to comment.