mirror of
https://github.com/talgo-cloud/talgo-libwebp.git
synced 2026-03-07 21:48:16 -08:00
Try to find example files in multiple directories which contains $GOPATH.
Bacause $GOPATH supports multiple directories splitted by ":" like $PATH.
This commit is contained in:
parent
8628328a9e
commit
0b88ea9dc7
1 changed files with 16 additions and 2 deletions
|
|
@ -3,22 +3,36 @@ package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"image/png"
|
"image/png"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetExFilePath returns the path of specified example file.
|
// GetExFilePath returns the path of specified example file.
|
||||||
func GetExFilePath(name string) string {
|
func GetExFilePath(name string) string {
|
||||||
return filepath.Join(os.Getenv("GOPATH"), "src/github.com/harukasan/go-libwebp/examples/images", name)
|
for _, gopath := range strings.Split(os.Getenv("GOPATH"), ":") {
|
||||||
|
path := filepath.Join(gopath, "src/github.com/harukasan/go-libwebp/examples/images", name)
|
||||||
|
if _, err := os.Stat(path); err == nil {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic(fmt.Errorf("%v does not exist in any directory which contains in $GOPATH", name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOutFilePath returns the path of specified out file.
|
// GetOutFilePath returns the path of specified out file.
|
||||||
func GetOutFilePath(name string) string {
|
func GetOutFilePath(name string) string {
|
||||||
return filepath.Join(os.Getenv("GOPATH"), "src/github.com/harukasan/go-libwebp/examples/out", name)
|
for _, gopath := range strings.Split(os.Getenv("GOPATH"), ":") {
|
||||||
|
path := filepath.Join(gopath, "src/github.com/harukasan/go-libwebp/examples/out")
|
||||||
|
if _, err := os.Stat(path); err == nil {
|
||||||
|
return filepath.Join(path, name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
panic(fmt.Errorf("out directory does not exist in any directory which contains in $GOPATH"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenFile opens specified example file
|
// OpenFile opens specified example file
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue