mirror of
				https://github.com/TeaOSLab/EdgeCommon.git
				synced 2025-11-04 05:00:24 +08:00 
			
		
		
		
	优化IP库内存
This commit is contained in:
		@@ -5,16 +5,22 @@ package iplibrary
 | 
			
		||||
import (
 | 
			
		||||
	"bytes"
 | 
			
		||||
	"encoding/binary"
 | 
			
		||||
	"github.com/iwind/TeaGo/types"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type ipItem struct {
 | 
			
		||||
	IPFrom uint64
 | 
			
		||||
	IPTo   uint64
 | 
			
		||||
 | 
			
		||||
	Region *ipRegion
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type ipRegion struct {
 | 
			
		||||
	CountryId  uint32
 | 
			
		||||
	ProvinceId uint32
 | 
			
		||||
	CityId     uint32
 | 
			
		||||
	TownId     uint32
 | 
			
		||||
	ProviderId uint32
 | 
			
		||||
	IPFrom     uint64
 | 
			
		||||
	IPTo       uint64
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (this *ipItem) AsBinary() ([]byte, error) {
 | 
			
		||||
@@ -25,3 +31,21 @@ func (this *ipItem) AsBinary() ([]byte, error) {
 | 
			
		||||
	}
 | 
			
		||||
	return buf.Bytes(), nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func HashRegion(countryId uint32, provinceId uint32, cityId uint32, townId uint32, providerId uint32) string {
 | 
			
		||||
	var providerHash = ""
 | 
			
		||||
	if providerId > 0 {
 | 
			
		||||
		providerHash = "_" + types.String(providerId)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if townId > 0 {
 | 
			
		||||
		return "t" + types.String(townId) + providerHash
 | 
			
		||||
	}
 | 
			
		||||
	if cityId > 0 {
 | 
			
		||||
		return "c" + types.String(cityId) + providerHash
 | 
			
		||||
	}
 | 
			
		||||
	if provinceId > 0 {
 | 
			
		||||
		return "p" + types.String(provinceId) + providerHash
 | 
			
		||||
	}
 | 
			
		||||
	return "a" + types.String(countryId) + providerHash
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user