go>> ffmt>> 返回
项目作者: go-ffmt

项目描述 :
Golang beautify data display for Humans
高级语言: Go
项目地址: git://github.com/go-ffmt/ffmt.git
创建时间: 2015-02-14T15:19:45Z
项目社区:https://github.com/go-ffmt/ffmt

开源协议:MIT License

下载


Golang beautify data display for Humans

Go Report Card
GoDoc
GitHub license
gocover.io

Usage

Examples

  1. package main
  2. import (
  3. ffmt "gopkg.in/ffmt.v1"
  4. )
  5. func main() {
  6. example()
  7. }
  8. type mt struct {
  9. String string
  10. Int int
  11. Slice []int
  12. Map map[string]interface{}
  13. }
  14. func example() {
  15. m := mt{
  16. "hello world",
  17. 100,
  18. []int{1, 2, 3, 4, 5, 6},
  19. map[string]interface{}{
  20. "A": 123,
  21. "BB": 456,
  22. },
  23. }
  24. fmt.Println(m) // fmt the default formatting.
  25. /*
  26. {hello world 100 [1 2 3 4 5 6] map[BB:456 A:123]}
  27. */
  28. ffmt.Puts(m) // More friendly formatting.
  29. /*
  30. {
  31. String: "hello world"
  32. Int: 100
  33. Slice: [
  34. 1 2 3
  35. 4 5 6
  36. ]
  37. Map: {
  38. "A": 123
  39. "BB": 456
  40. }
  41. }
  42. */
  43. ffmt.Print(m) // Same "Puts" but String unadded '"'.
  44. /*
  45. {
  46. String: hello world
  47. Int: 100
  48. Slice: [
  49. 1 2 3
  50. 4 5 6
  51. ]
  52. Map: {
  53. A: 123
  54. BB: 456
  55. }
  56. }
  57. */
  58. ffmt.P(m) // Format data and types.
  59. /*
  60. main.mt{
  61. String: string("hello world")
  62. Int: int(100)
  63. Slice: []int[
  64. int(1) int(2) int(3)
  65. int(4) int(5) int(6)
  66. ]
  67. Map: map[string]interface {}{
  68. string("A"): int(123)
  69. string("BB"): int(456)
  70. }
  71. }
  72. */
  73. ffmt.Pjson(m) // Format it in json style.
  74. /*
  75. {
  76. "Int": 100
  77. ,"Map": {
  78. "A": 123
  79. ,"BB": 456
  80. }
  81. ,"Slice": [
  82. 1,2,3
  83. ,4,5,6
  84. ]
  85. ,"String": "hello world"
  86. }
  87. */
  88. m0 := ffmt.ToTable(m, m) // Break the fields into tables.
  89. ffmt.Puts(m0)
  90. /*
  91. [
  92. [
  93. "String" "Int"
  94. "Slice" "Map"
  95. ]
  96. [
  97. "hello world" "100"
  98. "[1 2 3 4 5 6]" "map[A:123 BB:456]"
  99. ]
  100. ]
  101. */
  102. m1 := ffmt.FmtTable(m0) // [][]string Table format.
  103. ffmt.Puts(m1)
  104. /*
  105. [
  106. "String Int Slice Map "
  107. "hello world 100 [1 2 3 4 5 6] map[A:123 BB:456] "
  108. ]
  109. */
  110. ffmt.Mark("hello") // Mark position.
  111. /*
  112. main.go:124 hello
  113. */
  114. ffmt.Print(ffmt.BytesViewer("Hello world! Hello All!"))
  115. /*
  116. | Address | Hex | Text |
  117. | -------: | :---------------------------------------------- | :--------------- |
  118. | 00000000 | 48 65 6c 6c 6f 20 77 6f 72 6c 64 21 20 48 65 6c | Hello world! Hel |
  119. | 00000010 | 6c 6f 20 41 6c 6c 21 | lo All! |
  120. */
  121. }

Sponsors

jetbrains

License

Licensed under the MIT License. See LICENSE for the full license text.