...
1 package exifcommon
2
3 import (
4 "os"
5 "path"
6
7 "encoding/binary"
8 "io/ioutil"
9
10 "github.com/dsoprea/go-logging"
11 )
12
13 var (
14 moduleRootPath = ""
15
16 testExifData []byte = nil
17
18
19 EncodeDefaultByteOrder = binary.BigEndian
20
21
22 TestDefaultByteOrder = binary.BigEndian
23 )
24
25 func GetModuleRootPath() string {
26 if moduleRootPath == "" {
27 moduleRootPath = os.Getenv("EXIF_MODULE_ROOT_PATH")
28 if moduleRootPath != "" {
29 return moduleRootPath
30 }
31
32 currentWd, err := os.Getwd()
33 log.PanicIf(err)
34
35 currentPath := currentWd
36
37 visited := make([]string, 0)
38
39 for {
40 tryStampFilepath := path.Join(currentPath, ".MODULE_ROOT")
41
42 _, err := os.Stat(tryStampFilepath)
43 if err != nil && os.IsNotExist(err) != true {
44 log.Panic(err)
45 } else if err == nil {
46 break
47 }
48
49 visited = append(visited, tryStampFilepath)
50
51 currentPath = path.Dir(currentPath)
52 if currentPath == "/" {
53 log.Panicf("could not find module-root: %v", visited)
54 }
55 }
56
57 moduleRootPath = currentPath
58 }
59
60 return moduleRootPath
61 }
62
63 func GetTestAssetsPath() string {
64 moduleRootPath := GetModuleRootPath()
65 assetsPath := path.Join(moduleRootPath, "assets")
66
67 return assetsPath
68 }
69
70 func getTestImageFilepath() string {
71 assetsPath := GetTestAssetsPath()
72 testImageFilepath := path.Join(assetsPath, "NDM_8901.jpg")
73 return testImageFilepath
74 }
75
76 func getTestExifData() []byte {
77 if testExifData == nil {
78 assetsPath := GetTestAssetsPath()
79 filepath := path.Join(assetsPath, "NDM_8901.jpg.exif")
80
81 var err error
82
83 testExifData, err = ioutil.ReadFile(filepath)
84 log.PanicIf(err)
85 }
86
87 return testExifData
88 }
89
View as plain text