Go 姣忔棩涓€搴撲箣 termtables

Posted darjun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Go 姣忔棩涓€搴撲箣 termtables相关的知识,希望对你有一定的参考价值。

绠€浠?/h2>

浠婂ぉ瀛︿釜绠€鍗曠偣鐨勷煒€锛?a>termtables澶勭悊琛ㄦ牸褰㈠紡鏁版嵁鐨勮緭鍑恒€傞€傜敤浜庨殢鏃堕殢鍦扮殑杈撳嚭涓€浜涚姸鎬佹垨缁熻鏁版嵁锛屼究浜庤瀵熷拰璋冭瘯銆傛槸涓€涓緢灏忓阀鐨勫伐鍏峰簱銆傛垜鍦ㄥ涔?a href="https://link.segmentfault.com/?url=https%3A%2F%2Fdarjun.github.io%2F2021%2F06%2F24%2Fgodailylib%2Fdateparse%2F" rel="nofollow">dateparse搴撴椂鍋跺皵瑙侀亣鍒颁簡杩欎釜搴撱€?/p>

蹇€熶娇鐢?/h2>

鏈枃浠g爜浣跨敤 Go Modules銆?/p>

鍒涘缓鐩綍骞跺垵濮嬪寲锛?/p>

$ mkdir termtables && cd termtables
$ go mod init github.com/darjun/go-daily-lib/termtables

瀹夎termtables搴擄細

$ go get -u github.com/scylladb/termtables

鏈€鍘熷鐨?code>termtables搴撲负github.com/apcera/termtables锛岀劧鍚庡師濮嬩粨搴撳凡缁忚鍒犻櫎浜嗐€傜洰鍓嶄娇鐢ㄧ殑閮芥槸鍏朵粬浜?fork 鐨勪粨搴撱€?/p>

浣跨敤锛?/p>

package main

import (
  "fmt"
  "github.com/scylladb/termtables"
)

func main() {
  t := termtables.CreateTable()
  t.AddHeaders("User", "Age")
  t.AddRow("dj", 18)
  t.AddRow("darjun", 30)
  fmt.Println(t.Render())
}

杩愯锛?/p>

$ go run main.go
+--------+-----+
| User   | Age |
+--------+-----+
| dj     | 18  |
| darjun | 30  |
+--------+-----+

浣跨敤寰堟柟渚匡紝棣栧厛璋冪敤termtables.CreateTable()鍒涘缓涓€涓〃鏍煎璞★紝璋冪敤璇ュ璞$殑AddHeader()鏂规硶娣诲姞澶撮儴淇℃伅锛岀劧鍚庤皟鐢?code>AddRow()閫愯娣诲姞鏁版嵁銆傛渶鍚庤皟鐢?code>Render()杩斿洖娓叉煋鍚庣殑琛ㄦ牸瀛楃涓层€?/p>

妯″紡

澶勭悊鏅€氱殑鏂囨湰琛ㄦ牸锛?code>termtables杩樻敮鎸佽緭鍑?html 鍜?Markdown 鏍煎紡鐨勮〃鏍笺€傚彧闇€瑕佽皟鐢ㄨ〃鏍煎璞$殑SetModeHTML()/SetModeMarkdown()鏂规硶璁剧疆涓€浜涙ā寮忓嵆鍙?銆?/p>

func main() {
  t := termtables.CreateTable()
  t.AddHeaders("User", "Age")
  t.AddRow("dj", 18)
  t.AddRow("darjun", 30)
  fmt.Println("HTML:")
  t.SetModeHTML()
  fmt.Println(t.Render())

  fmt.Println("Markdown:")
  t.SetModeMarkdown()
  fmt.Println(t.Render())
}

杩愯锛?/p>

$ go run main.go
HTML:
<table class="termtable">
<thead>
<tr><th>User</th><th>Age</th></tr>
</thead>
<tbody>
<tr><td>dj</td><td>18</td></tr>
<tr><td>darjun</td><td>30</td></tr>
</tbody>
</table>

Markdown:
| User   | Age |
| ------ | --- |
| dj     | 18  |
| darjun | 30  |

杈撳嚭鐨勬牸寮忓彲浠ョ洿鎺ョ敤鍦?Markdown/HTML 鏂囦欢涓€?/p>

鎬荤粨

浠婂ぉ杞绘澗涓€涓嬶紝浜嗚В浜嗕竴涓皬宸х殑宸ュ叿搴?code>termtables銆傝櫧鐒惰嚜宸卞疄鐜颁竴涓被浼肩殑涔熶笉澶嶆潅锛?code>termtables搴撻澶栧府鎴戜滑澶勭悊浜嗙紪鐮併€佸瓧瀹界瓑姣旇緝绻佺悙鐨勭粏鑺傘€傛湁闇€瑕佸湪鍐欑ず渚嬬▼搴忎腑鎵撳嵃绫讳技琛ㄦ牸涔嬬被鐨勬暟鎹笉濡ㄨ瘯涓€璇?code>termtables銆?/p>

澶у濡傛灉鍙戠幇濂界帺銆佸ソ鐢ㄧ殑 Go 璇█搴擄紝娆㈣繋鍒?Go 姣忔棩涓€搴?GitHub 涓婃彁浜?issue馃槃

鍙傝€?/h2>
  1. Go 姣忔棩涓€搴?GitHub锛?a href="https://link.segmentfault.com/?url=https%3A%2F%2Fgithub.com%2Fdarjun%2Fgo-daily-lib" rel="nofollow">https://github.com/darjun/go-daily-lib
  2. termtables GitHub锛?a>github.com/scylladb/termtables

鎴?/h2>

鎴戠殑鍗氬锛?a href="https://link.segmentfault.com/?url=https%3A%2F%2Fdarjun.github.io" rel="nofollow">https://darjun.github.io

娆㈣繋鍏虫敞鎴戠殑寰俊鍏紬鍙枫€怗oUpUp銆戯紝鍏卞悓瀛︿範锛屼竴璧疯繘姝

以上是关于Go 姣忔棩涓€搴撲箣 termtables的主要内容,如果未能解决你的问题,请参考以下文章

姣忔棩涓€鍙ヤ辅銆屾槬鏅氥€嶇殑鑻辨枃鏄?spring festival party 鍚楋紵涓嶅锛佸氨宸竴涓瘝锛?/h1>