internal/godoc/util: merge into internal/godoc
Only used by godoc, so just move the utility code into the main package.
Down to a single directory.
Change-Id: I1bef28ce932372d748dd062eb6597d8979a26b08
Reviewed-on: https://go-review.googlesource.com/c/website/+/293491
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
diff --git a/internal/godoc/corpus.go b/internal/godoc/corpus.go
index ddfd2e9..fff776e 100644
--- a/internal/godoc/corpus.go
+++ b/internal/godoc/corpus.go
@@ -12,8 +12,6 @@
"io/fs"
"sync"
"time"
-
- "golang.org/x/website/internal/godoc/util"
)
// A Corpus holds all the state related to serving and indexing a
@@ -45,9 +43,9 @@
refreshMetadataSignal chan bool
// file system information
- fsTree util.RWValue // *Directory tree of packages, updated with each sync (but sync code is removed now)
- fsModified util.RWValue // timestamp of last call to invalidateIndex
- docMetadata util.RWValue // mapping from paths to *Metadata
+ fsTree rwValue // *Directory tree of packages, updated with each sync (but sync code is removed now)
+ fsModified rwValue // timestamp of last call to invalidateIndex
+ docMetadata rwValue // mapping from paths to *Metadata
// flag to check whether a corpus is initialized or not
initMu sync.RWMutex
diff --git a/internal/godoc/server.go b/internal/godoc/server.go
index 3360048..c127769 100644
--- a/internal/godoc/server.go
+++ b/internal/godoc/server.go
@@ -29,8 +29,6 @@
"strings"
"text/template"
"time"
-
- "golang.org/x/website/internal/godoc/util"
)
// handlerServer is a migration from an old godoc http Handler type.
@@ -791,7 +789,7 @@
return
}
index := pathpkg.Join(fsPath, "index.html")
- if util.IsTextFile(p.Corpus.fs, index) || util.IsTextFile(p.Corpus.fs, pathpkg.Join(fsPath, "index.md")) {
+ if isTextFile(p.Corpus.fs, index) || isTextFile(p.Corpus.fs, pathpkg.Join(fsPath, "index.md")) {
p.ServeHTMLDoc(w, r, index, index)
return
}
@@ -799,7 +797,7 @@
return
}
- if util.IsTextFile(p.Corpus.fs, fsPath) {
+ if isTextFile(p.Corpus.fs, fsPath) {
if redirectFile(w, r) {
return
}
diff --git a/internal/godoc/util/util.go b/internal/godoc/util.go
similarity index 82%
rename from internal/godoc/util/util.go
rename to internal/godoc/util.go
index 2397241..940cdc2 100644
--- a/internal/godoc/util/util.go
+++ b/internal/godoc/util.go
@@ -5,8 +5,7 @@
//go:build go1.16
// +build go1.16
-// Package util contains utility types and functions for godoc.
-package util // import "golang.org/x/website/internal/godoc/util"
+package godoc
import (
"io/fs"
@@ -16,22 +15,22 @@
"unicode/utf8"
)
-// An RWValue wraps a value and permits mutually exclusive
+// An rwValue wraps a value and permits mutually exclusive
// access to it and records the time the value was last set.
-type RWValue struct {
+type rwValue struct {
mutex sync.RWMutex
value interface{}
timestamp time.Time // time of last set()
}
-func (v *RWValue) Set(value interface{}) {
+func (v *rwValue) Set(value interface{}) {
v.mutex.Lock()
v.value = value
v.timestamp = time.Now()
v.mutex.Unlock()
}
-func (v *RWValue) Get() (interface{}, time.Time) {
+func (v *rwValue) Get() (interface{}, time.Time) {
v.mutex.RLock()
defer v.mutex.RUnlock()
return v.value, v.timestamp
@@ -64,11 +63,11 @@
".svg": false, // must be served raw
}
-// IsTextFile reports whether the file has a known extension indicating
+// isTextFile reports whether the file has a known extension indicating
// a text file, or if a significant chunk of the specified file looks like
// correct UTF-8; that is, if it is likely that the file contains human-
// readable text.
-func IsTextFile(fsys fs.FS, filename string) bool {
+func isTextFile(fsys fs.FS, filename string) bool {
// if the extension is known, use it for decision making
if isText, found := textExt[pathpkg.Ext(filename)]; found {
return isText