mirror of
https://github.com/zu1k/nali.git
synced 2025-01-22 13:19:02 +08:00
Add the source field to the json output.
This commit is contained in:
parent
05d918528f
commit
3819ae6808
@ -13,6 +13,11 @@ import (
|
|||||||
"github.com/zu1k/nali/pkg/zxipv6wry"
|
"github.com/zu1k/nali/pkg/zxipv6wry"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Result struct {
|
||||||
|
Source string `json:"source"`
|
||||||
|
common.Result
|
||||||
|
}
|
||||||
|
|
||||||
func GetDB(typ dbif.QueryType) (db dbif.DB) {
|
func GetDB(typ dbif.QueryType) (db dbif.DB) {
|
||||||
if db, found := dbTypeCache[typ]; found {
|
if db, found := dbTypeCache[typ]; found {
|
||||||
return db
|
return db
|
||||||
@ -69,15 +74,16 @@ func GetDB(typ dbif.QueryType) (db dbif.DB) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func Find(typ dbif.QueryType, query string) common.Result {
|
func Find(typ dbif.QueryType, query string) *Result {
|
||||||
if result, found := queryCache.Load(query); found {
|
if result, found := queryCache.Load(query); found {
|
||||||
return result.(common.Result)
|
return result.(*Result)
|
||||||
}
|
}
|
||||||
result, err := GetDB(typ).Find(query)
|
db := GetDB(typ)
|
||||||
|
result, err := db.Find(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
res := result
|
res := &Result{db.Name(), result}
|
||||||
queryCache.Store(query, res)
|
queryCache.Store(query, res)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,10 @@ func (db CDN) Find(query string, params ...string) (result fmt.Stringer, err err
|
|||||||
return nil, errors.New("not found")
|
return nil, errors.New("not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db CDN) Name() string {
|
||||||
|
return "cdn"
|
||||||
|
}
|
||||||
|
|
||||||
func parseBaseCname(domain string) (result []string) {
|
func parseBaseCname(domain string) (result []string) {
|
||||||
parts := strings.Split(domain, ".")
|
parts := strings.Split(domain, ".")
|
||||||
size := len(parts)
|
size := len(parts)
|
||||||
|
@ -22,6 +22,7 @@ const (
|
|||||||
|
|
||||||
type DB interface {
|
type DB interface {
|
||||||
Find(query string, params ...string) (result fmt.Stringer, err error)
|
Find(query string, params ...string) (result fmt.Stringer, err error)
|
||||||
|
Name() string
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -54,6 +54,10 @@ func (g GeoIP) Find(query string, params ...string) (result fmt.Stringer, err er
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db GeoIP) Name() string {
|
||||||
|
return "geoip"
|
||||||
|
}
|
||||||
|
|
||||||
type Result struct {
|
type Result struct {
|
||||||
Country string `json:"country"`
|
Country string `json:"country"`
|
||||||
Area string `json:"area"`
|
Area string `json:"area"`
|
||||||
|
@ -31,12 +31,12 @@ func NewIP2Location(filePath string) (*IP2Location, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x IP2Location) Find(query string, params ...string) (result fmt.Stringer, err error) {
|
func (db IP2Location) Find(query string, params ...string) (result fmt.Stringer, err error) {
|
||||||
ip := net.ParseIP(query)
|
ip := net.ParseIP(query)
|
||||||
if ip == nil {
|
if ip == nil {
|
||||||
return nil, errors.New("Query should be valid IP")
|
return nil, errors.New("Query should be valid IP")
|
||||||
}
|
}
|
||||||
record, err := x.db.Get_all(ip.String())
|
record, err := db.db.Get_all(ip.String())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
@ -50,6 +50,10 @@ func (x IP2Location) Find(query string, params ...string) (result fmt.Stringer,
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db IP2Location) Name() string {
|
||||||
|
return "ip2location"
|
||||||
|
}
|
||||||
|
|
||||||
type Result struct {
|
type Result struct {
|
||||||
Country string `json:"country"`
|
Country string `json:"country"`
|
||||||
Region string `json:"region"`
|
Region string `json:"region"`
|
||||||
|
@ -67,3 +67,7 @@ func (db Ip2Region) Find(query string, params ...string) (result fmt.Stringer, e
|
|||||||
|
|
||||||
return nil, errors.New("ip2region 未初始化")
|
return nil, errors.New("ip2region 未初始化")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db Ip2Region) Name() string {
|
||||||
|
return "ip2region"
|
||||||
|
}
|
||||||
|
@ -54,3 +54,7 @@ func (db IPIPFree) Find(query string, params ...string) (result fmt.Stringer, er
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db IPIPFree) Name() string {
|
||||||
|
return "ipip"
|
||||||
|
}
|
||||||
|
@ -90,6 +90,10 @@ func (db QQwry) Find(query string, params ...string) (result fmt.Stringer, err e
|
|||||||
return reader.Result.DecodeGBK(), nil
|
return reader.Result.DecodeGBK(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db QQwry) Name() string {
|
||||||
|
return "qqwry"
|
||||||
|
}
|
||||||
|
|
||||||
func CheckFile(data []byte) bool {
|
func CheckFile(data []byte) bool {
|
||||||
if len(data) < 8 {
|
if len(data) < 8 {
|
||||||
return false
|
return false
|
||||||
|
@ -82,6 +82,10 @@ func (db *ZXwry) Find(query string, _ ...string) (result fmt.Stringer, err error
|
|||||||
return reader.Result, nil
|
return reader.Result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (db *ZXwry) Name() string {
|
||||||
|
return "xzwry"
|
||||||
|
}
|
||||||
|
|
||||||
func CheckFile(data []byte) bool {
|
func CheckFile(data []byte) bool {
|
||||||
if len(data) < 4 {
|
if len(data) < 4 {
|
||||||
return false
|
return false
|
||||||
|
Loading…
Reference in New Issue
Block a user