Source File
apigodoc.go
Belonging Package
golang.org/x/pkgsite/internal/symbol
package symbol
import (
)
func (, string) ([]string, error) {
var string
if stdlib.Contains() {
= filepath.Join(filepath.Clean(runtime.GOROOT()), "api", "go*.txt")
} else {
= filepath.Join(, , "v*.txt")
}
, := filepath.Glob()
if != nil {
return nil,
}
if len() == 0 {
return nil, fmt.Errorf("no files matching %q", )
}
return , nil
}
type apiVersions map[string]pkgAPIVersions // keyed by Go package ("net/http")
type pkgAPIVersions struct {
constSince map[string]string
varSince map[string]string
typeSince map[string]string // "Server" -> "1.7"
methodSince map[string]map[string]string // "*Server" ->"Shutdown"->1.8
funcSince map[string]string // "NewServer" -> "1.7"
fieldSince map[string]map[string]string // "ClientTrace" -> "Got1xxResponse" -> "1.11"
}
type versionedRow struct {
pkg string // "net/http"
kind string // "type", "func", "method", "field" TODO: "const", "var"
recv string // for methods, the receiver type ("Server", "*Server")
name string // name of type, (struct) field, func, method
structName string // for struct fields, the outer struct name
}
type versionParser struct {
res apiVersions // initialized lazily
}
func ( *versionParser) ( string) error {
, := os.Open()
if != nil {
return
}
defer .Close()
:= filepath.Base()
:= strings.TrimSuffix(, ".txt")
:= bufio.NewScanner()
for .Scan() {
, := parseRow(.Text())
if ! {
continue
}
if .res == nil {
.res = make(apiVersions)
}
, := .res[.pkg]
if ! {
= pkgAPIVersions{
constSince: make(map[string]string),
varSince: make(map[string]string),
typeSince: make(map[string]string),
methodSince: make(map[string]map[string]string),
funcSince: make(map[string]string),
fieldSince: make(map[string]map[string]string),
}
.res[.pkg] =
}
switch .kind {
case "const":
.constSince[.name] =
case "var":
.varSince[.name] =
case "func":
.funcSince[.name] =
case "type":
.typeSince[.name] =
case "method":
if , := .methodSince[.recv]; ! {
.methodSince[.recv] = make(map[string]string)
}
.methodSince[.recv][.name] =
case "field":
if , := .fieldSince[.structName]; ! {
.fieldSince[.structName] = make(map[string]string)
}
.fieldSince[.structName][.name] =
}
}
return .Err()
}
func ( string) ( versionedRow, bool) {
return
}
= [len(", "):]
switch {
case strings.HasPrefix(, "type "):
= [len("type "):]
:= strings.IndexByte(, ' ')
if == -1 {
return
}
.name, = [:], [+1:]
switch {
case strings.HasPrefix(, "struct, "):
= [len("struct, "):]
if := strings.IndexByte(, ' '); != -1 {
.kind = "field"
.structName = .name
.name = [:]
return , true
}
case strings.HasPrefix(, "interface, "):
= [len("interface, "):]
if := strings.IndexByte(, '('); != -1 {
.kind = "method"
.recv = .name
.name = [:]
return , true
}
default:
.kind = "type"
return , true
}
case strings.HasPrefix(, "const "):
.kind = "const"
= [len("const "):]
if := strings.IndexByte(, ' '); != -1 {
.name = [:]
return , true
}
case strings.HasPrefix(, "var "):
.kind = "var"
= [len("var "):]
if := strings.IndexByte(, ' '); != -1 {
.name = [:]
return , true
}
case strings.HasPrefix(, "func "):
.kind = "func"
= [len("func "):]
if := strings.IndexByte(, '('); != -1 {
.name = [:]
return , true
}
case strings.HasPrefix(, "method "): // "method (*File) SetModTime(time.Time)"
.kind = "method"
= [len("method "):] // "(*File) SetModTime(time.Time)"
:= strings.IndexByte(, ' ')
if == -1 {
return
}
.recv = strings.Trim([:], "()") // "*File"
.recv = strings.TrimPrefix(.recv, "*") // "File"
= [+1:] // SetMode(os.FileMode)
:= strings.IndexByte(, '(')
if == -1 {
return
}
.name = [:]
return , true
}
return // TODO: handle more cases
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |