Unexport filepath/path bridge types

They are of no use outside the helpers package.

See #1160
This commit is contained in:
bep 2015-05-25 13:10:26 +02:00
parent be79c35bda
commit beee679dfb
3 changed files with 26 additions and 26 deletions

View file

@ -27,8 +27,8 @@ import (
"unicode"
)
// FilepathPathBridge is a bridge for common functionality in filepath vs path
type FilepathPathBridge interface {
// filepathPathBridge is a bridge for common functionality in filepath vs path
type filepathPathBridge interface {
Base(in string) string
Clean(in string) string
Dir(in string) string
@ -37,34 +37,34 @@ type FilepathPathBridge interface {
Separator() string
}
type FilepathBridge struct {
type filepathBridge struct {
}
func (FilepathBridge) Base(in string) string {
func (filepathBridge) Base(in string) string {
return filepath.Base(in)
}
func (FilepathBridge) Clean(in string) string {
func (filepathBridge) Clean(in string) string {
return filepath.Clean(in)
}
func (FilepathBridge) Dir(in string) string {
func (filepathBridge) Dir(in string) string {
return filepath.Dir(in)
}
func (FilepathBridge) Ext(in string) string {
func (filepathBridge) Ext(in string) string {
return filepath.Ext(in)
}
func (FilepathBridge) Join(elem ...string) string {
func (filepathBridge) Join(elem ...string) string {
return filepath.Join(elem...)
}
func (FilepathBridge) Separator() string {
func (filepathBridge) Separator() string {
return FilePathSeparator
}
var filepathBridge FilepathBridge
var fpb filepathBridge
var sanitizeRegexp = regexp.MustCompile("[^a-zA-Z0-9./_-]")
// MakePath takes a string with any characters and replace it
@ -103,7 +103,7 @@ func UnicodeSanitize(s string) string {
// ReplaceExtension takes a path and an extension, strips the old extension
// and returns the path with the new extension.
func ReplaceExtension(path string, newExt string) string {
f, _ := FileAndExt(path, filepathBridge)
f, _ := FileAndExt(path, fpb)
return f + "." + newExt
}
@ -270,7 +270,7 @@ func GetDottedRelativePath(inPath string) string {
// Filename takes a path, strips out the extension,
// and returns the name of the file.
func Filename(in string) (name string) {
name, _ = FileAndExt(in, filepathBridge)
name, _ = FileAndExt(in, fpb)
return
}
@ -290,7 +290,7 @@ func Filename(in string) (name string) {
// If the path, in, represents a filename with an extension,
// then name will be the filename minus any extension - including the dot
// and ext will contain the extension - minus the dot.
func FileAndExt(in string, b FilepathPathBridge) (name string, ext string) {
func FileAndExt(in string, b filepathPathBridge) (name string, ext string) {
ext = b.Ext(in)
base := b.Base(in)
@ -396,10 +396,10 @@ func PathPrep(ugly bool, in string) string {
// /section/name/ becomes /section/name/index.html
// /section/name/index.html becomes /section/name/index.html
func PrettifyPath(in string) string {
return PrettiyPath(in, filepathBridge)
return PrettiyPath(in, fpb)
}
func PrettiyPath(in string, b FilepathPathBridge) string {
func PrettiyPath(in string, b filepathPathBridge) string {
if filepath.Ext(in) == "" {
// /section/name/ -> /section/name/index.html
if len(in) < 2 {

View file

@ -535,7 +535,7 @@ func TestFileAndExt(t *testing.T) {
}
for i, d := range data {
file, ext := FileAndExt(filepath.FromSlash(d.input), filepathBridge)
file, ext := FileAndExt(filepath.FromSlash(d.input), fpb)
if d.expectedFile != file {
t.Errorf("Test %d failed. Expected filename %q got %q.", i, d.expectedFile, file)
}

View file

@ -23,34 +23,34 @@ import (
"github.com/spf13/viper"
)
type PathBridge struct {
type pathBridge struct {
}
func (PathBridge) Base(in string) string {
func (pathBridge) Base(in string) string {
return path.Base(in)
}
func (PathBridge) Clean(in string) string {
func (pathBridge) Clean(in string) string {
return path.Clean(in)
}
func (PathBridge) Dir(in string) string {
func (pathBridge) Dir(in string) string {
return path.Dir(in)
}
func (PathBridge) Ext(in string) string {
func (pathBridge) Ext(in string) string {
return path.Ext(in)
}
func (PathBridge) Join(elem ...string) string {
func (pathBridge) Join(elem ...string) string {
return path.Join(elem...)
}
func (PathBridge) Separator() string {
func (pathBridge) Separator() string {
return "/"
}
var pathBridge PathBridge
var pb pathBridge
func sanitizeURLWithFlags(in string, f purell.NormalizationFlags) string {
s, err := purell.NormalizeURLString(in, f)
@ -244,7 +244,7 @@ func PrettifyURL(in string) string {
// /section/name/ becomes /section/name/index.html
// /section/name/index.html becomes /section/name/index.html
func PrettifyURLPath(in string) string {
return PrettiyPath(in, pathBridge)
return PrettiyPath(in, pb)
}
// Uglify does the opposite of PrettifyURLPath().
@ -260,7 +260,7 @@ func Uglify(in string) string {
return path.Clean(in) + ".html"
}
name, ext := FileAndExt(in, pathBridge)
name, ext := FileAndExt(in, pb)
if name == "index" {
// /section/name/index.html -> /section/name.html
d := path.Dir(in)