navigator/mapping/map.go

45 lines
810 B
Go
Raw Normal View History

package mapping
import (
"flag"
"git.eve.moe/jackyyf/navigator/mapping/elf"
2020-02-01 15:06:00 +08:00
"git.eve.moe/jackyyf/navigator/mapping/firefly"
)
var (
defaultServer = flag.String("fallback-node",
"xe-mci1-us", "Default CDN node in case of any script error")
defaultSuffix = flag.String("fallback-suffix",
".edge.eve.network",
"Default CDN suffix in case of any script error")
)
func Initialize() {
elf.Initialize()
2020-02-01 15:06:00 +08:00
firefly.Initialize()
}
func Get(ip string) string {
node := elf.GetMapping(ip)
if node == "" {
node = *defaultServer
}
suffix := elf.GetSuffix(ip)
if suffix == "" {
suffix = *defaultSuffix
}
return node + suffix
}
func GetSuffix(ip string) string {
ret := elf.GetSuffix(ip)
if ret == "" {
return *defaultSuffix
}
return ret
}
func GetNodes() []string {
return elf.GetNodes()
}