Go by Example 中文版 文档版 打包

Go by Example 中文版

这个网站的教程不错,但是放到网站上可视化之后不好做笔记,而且要一页一页翻,不如搞一个打包的文档版。

预览:

先从这里:gobyexample-cn/gobyexample: Go by Example 通过例子学 Golang下载源代码

然后运行如下打包代码:

import os

# 根目录路径
base_path = "D:/A_projects/gobyexample-master/examples/"

# 目录顺序
sections = [
    "hello-world", "values", "variables", "constants", "for", "if-else", "switch", "arrays", "slices", "maps",
    "functions", "multiple-return-values", "variadic-functions", "closures", "recursion", "range", "pointers",
    "strings-and-runes", "structs", "methods", "interfaces", "enums", "embedding", "generics", "range-over-channels",
    "errors", "custom-errors", "goroutines", "channels", "channel-buffering", "channel-synchronization",
    "channel-directions", "select", "timeouts", "non-blocking-channel-operations", "closing-channels",
    "range-over-channels", "timers", "tickers", "worker-pools", "waitgroups", "rate-limiting", "atomic-counters",
    "mutexes", "stateful-goroutines", "sorting", "sorting-by-functions", "panic", "defer", "recover",
    "string-functions",
    "string-formatting", "text-templates", "regular-expressions", "json", "xml", "time", "epoch",
    "time-formatting-parsing", "random-numbers", "number-parsing", "url-parsing", "sha256-hashes", "base64-encoding",
    "reading-files", "writing-files", "line-filters", "file-paths", "directories", "temporary-files-and-directories",
    "embed-directive", "testing-and-benchmarking", "command-line-arguments", "command-line-flags",
    "command-line-subcommands",
    "environment-variables", "logging", "http-clients", "http-servers", "context", "spawning-processes",
    "execing-processes", "signals", "exit"
]

# 生成Markdown内容
markdown_content = ""
index = 1  # 用于生成有序列表编号

for section in sections:
    section_path = os.path.join(base_path, section)
    if os.path.isdir(section_path):
        # 加入小节标题和描述
        markdown_content += f"{index}. {section.replace('-', ' ').title()}\n\n"

        # 查找.go文件
        go_file = os.path.join(section_path, f"{section}.go")
        if os.path.isfile(go_file):
            go_content = open(go_file, 'r', encoding="utf-8").read()
            markdown_content += "    ```go\n    " + go_content.replace('\n', '\n    ') + "\n    ```\n\n"

        # 查找.sh文件
        sh_file = os.path.join(section_path, f"{section}.sh")
        if os.path.isfile(sh_file):
            sh_content = open(sh_file, 'r', encoding="utf-8").read()
            markdown_content += "    ```sh\n    " + sh_content.replace('\n', '\n    ') + "\n    ```\n\n"

        index += 1  # 更新列表编号

# 将内容写入Markdown文件
with open("gobyexample_tutorial.md", "w", encoding="utf-8") as f:
    f.write(markdown_content)

print("Markdown文档已生成!")
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值