2019-10-27 16:54:23 +08:00
|
|
|
package mapping
|
|
|
|
|
|
|
|
import (
|
2019-11-07 15:18:44 +08:00
|
|
|
"flag"
|
2019-11-17 03:51:15 +08:00
|
|
|
"git.eve.moe/jackyyf/navigator/mapping/elf"
|
2019-10-27 16:54:23 +08:00
|
|
|
)
|
|
|
|
|
2019-11-07 15:18:44 +08:00
|
|
|
var (
|
2019-11-17 03:51:15 +08:00
|
|
|
defaultServer = flag.String("fallback-node",
|
2019-12-26 01:10:26 +08:00
|
|
|
"xe-mci1-us", "Default CDN node in case of any script error")
|
2019-11-29 16:16:18 +08:00
|
|
|
defaultSuffix = flag.String("fallback-suffix",
|
|
|
|
".edge.eve.network",
|
|
|
|
"Default CDN suffix in case of any script error")
|
2019-11-07 15:18:44 +08:00
|
|
|
)
|
|
|
|
|
2019-11-17 03:51:15 +08:00
|
|
|
func Initialize() {
|
|
|
|
elf.Initialize()
|
|
|
|
}
|
|
|
|
|
2019-10-27 16:54:23 +08:00
|
|
|
func Get(ip string) string {
|
2019-12-26 01:10:26 +08:00
|
|
|
node := elf.GetMapping(ip)
|
|
|
|
if node == "" {
|
|
|
|
node = *defaultServer
|
2019-10-27 16:54:23 +08:00
|
|
|
}
|
2019-12-26 01:10:26 +08:00
|
|
|
suffix := elf.GetSuffix(ip)
|
|
|
|
if suffix == "" {
|
|
|
|
suffix = *defaultSuffix
|
|
|
|
}
|
|
|
|
return node + suffix
|
2019-10-27 16:54:23 +08:00
|
|
|
}
|
2019-11-29 16:16:18 +08:00
|
|
|
|
|
|
|
func GetSuffix(ip string) string {
|
|
|
|
ret := elf.GetSuffix(ip)
|
|
|
|
if ret == "" {
|
|
|
|
return *defaultSuffix
|
|
|
|
}
|
|
|
|
return ret
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetNodes() []string {
|
|
|
|
return elf.GetNodes()
|
|
|
|
}
|