// Copyright 2009 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. package godoc import ( "bytes" "encoding/json" "errors" "log" "os" pathpkg "path" "strings" "time" "golang.org/x/tools/godoc/vfs" ) var ( doctype = []byte("") ) // ---------------------------------------------------------------------------- // Documentation Metadata type Metadata struct { // These fields can be set in the JSON header at the top of a doc. Title string Subtitle string Template bool // execute as template Path string // canonical path for this page AltPaths []string // redirect these other paths to this page // These are internal to the implementation. filePath string // filesystem path relative to goroot } func (m *Metadata) FilePath() string { return m.filePath } // extractMetadata extracts the Metadata from a byte slice. // It returns the Metadata value and the remaining data. // If no metadata is present the original byte slice is returned. func extractMetadata(b []byte) (meta Metadata, tail []byte, err error) { tail = b if !bytes.HasPrefix(b, jsonStart) { return } end := bytes.Index(b, jsonEnd) if end < 0 { return } b = b[len(jsonStart)-1 : end+1] // drop leading