Add string method

This commit is contained in:
lionsoul2014 2025-12-04 13:13:49 +08:00
parent 540831e6a9
commit 4c9ef35a9a
2 changed files with 28 additions and 0 deletions

View File

@ -111,6 +111,23 @@ func newConfig(cachePolicy int, ipVersion *xdb.Version, xdbPath string, searcher
}, nil
}
func (c *Config) String() string {
vIndex := "null"
if c.vIndex != nil {
vIndex = fmt.Sprintf("{bytes:%d}", len(c.vIndex))
}
cBuffer := "null"
if c.cBuffer != nil {
cBuffer = fmt.Sprintf("{bytes:%d}", len(c.cBuffer))
}
return fmt.Sprintf(
"{cache_policy:%d, version:%s, xdb_path:%s, header:%s, v_index:%s, c_buffer:%s}",
c.cachePolicy, c.ipVersion.String(), c.xdbPath, c.header.String(), vIndex, cBuffer,
)
}
func (c *Config) CachePolicy() int {
return c.cachePolicy
}

View File

@ -0,0 +1,11 @@
// Copyright 2022 The Ip2Region Authors. All rights reserved.
// Use of this source code is governed by a Apache2.0-style
// license that can be found in the LICENSE file.
package service
import "testing"
func TestV4Config(t *testing.T) {
}