// 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 // TODO(adg): why are some exported and some aren't? -brad type Metadata struct { Title string Subtitle string Template bool // execute as template Path string // canonical path for this page 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