From 4c9ef35a9aeffe7049e2b1602e7168ea3120dcb7 Mon Sep 17 00:00:00 2001 From: lionsoul2014 Date: Thu, 4 Dec 2025 13:13:49 +0800 Subject: [PATCH] Add string method --- binding/golang/service/config.go | 17 +++++++++++++++++ binding/golang/service/config_test.go | 11 +++++++++++ 2 files changed, 28 insertions(+) create mode 100644 binding/golang/service/config_test.go diff --git a/binding/golang/service/config.go b/binding/golang/service/config.go index 825a9dd..9f26c2f 100644 --- a/binding/golang/service/config.go +++ b/binding/golang/service/config.go @@ -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 } diff --git a/binding/golang/service/config_test.go b/binding/golang/service/config_test.go new file mode 100644 index 0000000..f3b8e9c --- /dev/null +++ b/binding/golang/service/config_test.go @@ -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) { + +}