代码拉取完成,页面将自动刷新
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
// The update-readmes.go tool creates or updates README.md files in
// the golang.org/x/build tree. It only updates files if they are
// missing or were previously generated by this tool.
//
// The auto-generated Markdown contains the package doc synopsis
// and a link to godoc.org for the API reference.
package main
import (
"bytes"
"fmt"
"go/build"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
)
func main() {
root, err := build.Import("golang.org/x/build", "", build.FindOnly)
if err != nil {
log.Fatalf("failed to find golang.org/x/build root: %v", err)
}
err = filepath.Walk(root.Dir, func(path string, fi os.FileInfo, err error) error {
if err != nil {
return err
}
if !fi.IsDir() {
return nil
}
rest := strings.TrimPrefix(strings.TrimPrefix(path, root.Dir), "/")
switch rest {
case "env", "version", "vendor":
return filepath.SkipDir
}
pkgName := "golang.org/x/build/" + filepath.ToSlash(rest)
pkg, err := build.Import(pkgName, "", 0)
if err != nil {
// Skip.
return nil
}
if _, err := os.Stat(filepath.Join(pkg.Dir, "README")); err == nil {
// Directory has exiting README; don't touch.
return nil
}
readmePath := filepath.Join(pkg.Dir, "README.md")
exist, err := ioutil.ReadFile(readmePath)
if err != nil && !os.IsNotExist(err) {
// A real error.
return err
}
const header = "Auto-generated by x/build/update-readmes.go"
if len(exist) > 0 && !bytes.Contains(exist, []byte(header)) {
return nil
}
newContents := []byte(fmt.Sprintf(`<!-- %s -->
[![GoDoc](https://godoc.org/%s?status.svg)](https://godoc.org/%s)
# %s
%s
`, header, pkgName, pkgName, pkgName, pkg.Doc))
if bytes.Equal(exist, newContents) {
return nil
}
if err := ioutil.WriteFile(readmePath, newContents, 0644); err != nil {
return err
}
log.Printf("Wrote %s", readmePath)
return nil
})
if err != nil {
log.Fatal(err)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。