From 4cb51f370311bca5f37ff76da1d278eaab2714b7 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 9 Jan 2022 10:53:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/const/vars.go | 4 ++++ internal/iplibrary/action_http_api.go | 2 +- internal/nodes/http_request.go | 16 ++++++++++++++++ internal/nodes/node.go | 5 +++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/internal/const/vars.go b/internal/const/vars.go index c7b5b3c..3a338e2 100644 --- a/internal/const/vars.go +++ b/internal/const/vars.go @@ -2,6 +2,8 @@ package teaconst +import "github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs" + var ( // 流量统计 @@ -10,4 +12,6 @@ var ( NodeId int64 = 0 NodeIdString = "" + + GlobalProductName = nodeconfigs.DefaultProductName ) diff --git a/internal/iplibrary/action_http_api.go b/internal/iplibrary/action_http_api.go index c6bbc15..ef3f3ec 100644 --- a/internal/iplibrary/action_http_api.go +++ b/internal/iplibrary/action_http_api.go @@ -71,7 +71,7 @@ func (this *HTTPAPIAction) runAction(action string, listType IPListType, item *p if err != nil { return err } - req.Header.Set("User-Agent", "GoEdge-Node/"+teaconst.Version) + req.Header.Set("User-Agent", teaconst.GlobalProductName+"-Node/"+teaconst.Version) resp, err := httpAPIClient.Do(req) if err != nil { return err diff --git a/internal/nodes/http_request.go b/internal/nodes/http_request.go index bc4b203..6853ea7 100644 --- a/internal/nodes/http_request.go +++ b/internal/nodes/http_request.go @@ -949,6 +949,22 @@ func (this *HTTPRequest) Format(source string) string { } } + // product + if prefix == "product" { + switch suffix { + case "name": + if sharedNodeConfig.ProductConfig != nil && len(sharedNodeConfig.ProductConfig.Name) > 0 { + return sharedNodeConfig.ProductConfig.Name + } + return teaconst.GlobalProductName + case "version": + if sharedNodeConfig.ProductConfig != nil && len(sharedNodeConfig.ProductConfig.Version) > 0 { + return sharedNodeConfig.ProductConfig.Version + } + return teaconst.Version + } + } + return "${" + varName + "}" }) } diff --git a/internal/nodes/node.go b/internal/nodes/node.go index 3e64ad9..c06c2d1 100644 --- a/internal/nodes/node.go +++ b/internal/nodes/node.go @@ -713,4 +713,9 @@ func (this *Node) onReload(config *nodeconfigs.NodeConfig) { time.Local = location this.timezone = timeZone } + + // product information + if config.ProductConfig != nil { + teaconst.GlobalProductName = config.ProductConfig.Name + } }