text/internal/gen: generalized Open (needed for w3c data).

Change-Id: I6fe6e9983921a593eb706f829184b5f39b8246fe
Reviewed-on: https://go-review.googlesource.com/7671
Reviewed-by: Nigel Tao <nigeltao@golang.org>
This commit is contained in:
Marcel van Lohuizen 2015-03-17 12:40:29 +09:00
Родитель 313fa8d603
Коммит 26df76be81
1 изменённых файлов: 9 добавлений и 2 удалений

Просмотреть файл

@ -110,13 +110,20 @@ func OpenUnicodeFile(category, version, file string) io.ReadCloser {
// iana directory in the local mirror. It will call log.Fatal if there are any // iana directory in the local mirror. It will call log.Fatal if there are any
// errors. // errors.
func OpenIANAFile(path string) io.ReadCloser { func OpenIANAFile(path string) io.ReadCloser {
return Open(*iana, "iana", path)
}
// Open opens subdir/path if a local directory is specified and the file exists,
// where subdir is a directory relative to the local root, or fetches it from
// urlRoot/path otherwise. It will call log.Fatal if there are any errors.
func Open(urlRoot, subdir, path string) io.ReadCloser {
if *localDir != "" { if *localDir != "" {
path = filepath.FromSlash(path) path = filepath.FromSlash(path)
if f, err := os.Open(filepath.Join(*localDir, "iana", path)); err == nil { if f, err := os.Open(filepath.Join(*localDir, subdir, path)); err == nil {
return f return f
} }
} }
return get(*iana, path) return get(urlRoot, path)
} }
func openUnicode(path string) io.ReadCloser { func openUnicode(path string) io.ReadCloser {