geoip.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. // Code generated for package bingeoip by go-bindata DO NOT EDIT. (@generated)
  2. // sources:
  3. // assets/GeoLite2-City.mmdb
  4. // assets/flags.json
  5. package bingeoip
  6. import (
  7. "fmt"
  8. "io/ioutil"
  9. "os"
  10. "path/filepath"
  11. "strings"
  12. )
  13. // bindataRead reads the given file from disk. It returns an error on failure.
  14. func bindataRead(path, name string) ([]byte, error) {
  15. buf, err := ioutil.ReadFile(path)
  16. if err != nil {
  17. err = fmt.Errorf("Error reading asset %s at %s: %v", name, path, err)
  18. }
  19. return buf, err
  20. }
  21. type asset struct {
  22. bytes []byte
  23. info os.FileInfo
  24. }
  25. // assetsGeolite2CityMmdb reads file data from disk. It returns an error on failure.
  26. func assetsGeolite2CityMmdb() (*asset, error) {
  27. path := "assets/GeoLite2-City.mmdb"
  28. name := "assets/GeoLite2-City.mmdb"
  29. bytes, err := bindataRead(path, name)
  30. if err != nil {
  31. return nil, err
  32. }
  33. fi, err := os.Stat(path)
  34. if err != nil {
  35. err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
  36. }
  37. a := &asset{bytes: bytes, info: fi}
  38. return a, err
  39. }
  40. // assetsFlagsJson reads file data from disk. It returns an error on failure.
  41. func assetsFlagsJson() (*asset, error) {
  42. path := "assets/flags.json"
  43. name := "assets/flags.json"
  44. bytes, err := bindataRead(path, name)
  45. if err != nil {
  46. return nil, err
  47. }
  48. fi, err := os.Stat(path)
  49. if err != nil {
  50. err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
  51. }
  52. a := &asset{bytes: bytes, info: fi}
  53. return a, err
  54. }
  55. // Asset loads and returns the asset for the given name.
  56. // It returns an error if the asset could not be found or
  57. // could not be loaded.
  58. func Asset(name string) ([]byte, error) {
  59. cannonicalName := strings.Replace(name, "\\", "/", -1)
  60. if f, ok := _bindata[cannonicalName]; ok {
  61. a, err := f()
  62. if err != nil {
  63. return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
  64. }
  65. return a.bytes, nil
  66. }
  67. return nil, fmt.Errorf("Asset %s not found", name)
  68. }
  69. // MustAsset is like Asset but panics when Asset would return an error.
  70. // It simplifies safe initialization of global variables.
  71. func MustAsset(name string) []byte {
  72. a, err := Asset(name)
  73. if err != nil {
  74. panic("asset: Asset(" + name + "): " + err.Error())
  75. }
  76. return a
  77. }
  78. // AssetInfo loads and returns the asset info for the given name.
  79. // It returns an error if the asset could not be found or
  80. // could not be loaded.
  81. func AssetInfo(name string) (os.FileInfo, error) {
  82. cannonicalName := strings.Replace(name, "\\", "/", -1)
  83. if f, ok := _bindata[cannonicalName]; ok {
  84. a, err := f()
  85. if err != nil {
  86. return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
  87. }
  88. return a.info, nil
  89. }
  90. return nil, fmt.Errorf("AssetInfo %s not found", name)
  91. }
  92. // AssetNames returns the names of the assets.
  93. func AssetNames() []string {
  94. names := make([]string, 0, len(_bindata))
  95. for name := range _bindata {
  96. names = append(names, name)
  97. }
  98. return names
  99. }
  100. // _bindata is a table, holding each asset generator, mapped to its name.
  101. var _bindata = map[string]func() (*asset, error){
  102. "assets/GeoLite2-City.mmdb": assetsGeolite2CityMmdb,
  103. "assets/flags.json": assetsFlagsJson,
  104. }
  105. // AssetDir returns the file names below a certain
  106. // directory embedded in the file by go-bindata.
  107. // For example if you run go-bindata on data/... and data contains the
  108. // following hierarchy:
  109. // data/
  110. // foo.txt
  111. // img/
  112. // a.png
  113. // b.png
  114. // then AssetDir("data") would return []string{"foo.txt", "img"}
  115. // AssetDir("data/img") would return []string{"a.png", "b.png"}
  116. // AssetDir("foo.txt") and AssetDir("notexist") would return an error
  117. // AssetDir("") will return []string{"data"}.
  118. func AssetDir(name string) ([]string, error) {
  119. node := _bintree
  120. if len(name) != 0 {
  121. cannonicalName := strings.Replace(name, "\\", "/", -1)
  122. pathList := strings.Split(cannonicalName, "/")
  123. for _, p := range pathList {
  124. node = node.Children[p]
  125. if node == nil {
  126. return nil, fmt.Errorf("Asset %s not found", name)
  127. }
  128. }
  129. }
  130. if node.Func != nil {
  131. return nil, fmt.Errorf("Asset %s not found", name)
  132. }
  133. rv := make([]string, 0, len(node.Children))
  134. for childName := range node.Children {
  135. rv = append(rv, childName)
  136. }
  137. return rv, nil
  138. }
  139. type bintree struct {
  140. Func func() (*asset, error)
  141. Children map[string]*bintree
  142. }
  143. var _bintree = &bintree{nil, map[string]*bintree{
  144. "assets": &bintree{nil, map[string]*bintree{
  145. "GeoLite2-City.mmdb": &bintree{assetsGeolite2CityMmdb, map[string]*bintree{}},
  146. "flags.json": &bintree{assetsFlagsJson, map[string]*bintree{}},
  147. }},
  148. }}
  149. // RestoreAsset restores an asset under the given directory
  150. func RestoreAsset(dir, name string) error {
  151. data, err := Asset(name)
  152. if err != nil {
  153. return err
  154. }
  155. info, err := AssetInfo(name)
  156. if err != nil {
  157. return err
  158. }
  159. err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
  160. if err != nil {
  161. return err
  162. }
  163. err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
  164. if err != nil {
  165. return err
  166. }
  167. err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
  168. if err != nil {
  169. return err
  170. }
  171. return nil
  172. }
  173. // RestoreAssets restores an asset under the given directory recursively
  174. func RestoreAssets(dir, name string) error {
  175. children, err := AssetDir(name)
  176. // File
  177. if err != nil {
  178. return RestoreAsset(dir, name)
  179. }
  180. // Dir
  181. for _, child := range children {
  182. err = RestoreAssets(dir, filepath.Join(name, child))
  183. if err != nil {
  184. return err
  185. }
  186. }
  187. return nil
  188. }
  189. func _filePath(dir, name string) string {
  190. cannonicalName := strings.Replace(name, "\\", "/", -1)
  191. return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
  192. }