From 463e96447a7c2db4a14ea23a622449e6d8ab65ca Mon Sep 17 00:00:00 2001 From: Ming Deng Date: Sun, 27 Sep 2020 00:37:46 +0800 Subject: [PATCH 1/2] decouple httplib from web module --- pkg/client/httplib/filter/prometheus/filter.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pkg/client/httplib/filter/prometheus/filter.go b/pkg/client/httplib/filter/prometheus/filter.go index 917d4720..b4a418e0 100644 --- a/pkg/client/httplib/filter/prometheus/filter.go +++ b/pkg/client/httplib/filter/prometheus/filter.go @@ -23,11 +23,13 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/astaxie/beego/pkg/client/httplib" - "github.com/astaxie/beego/pkg/server/web" ) type FilterChainBuilder struct { summaryVec prometheus.ObserverVec + AppName string + ServerName string + RunMode string } func (builder *FilterChainBuilder) FilterChain(next httplib.Filter) httplib.Filter { @@ -36,9 +38,9 @@ func (builder *FilterChainBuilder) FilterChain(next httplib.Filter) httplib.Filt Name: "beego", Subsystem: "remote_http_request", ConstLabels: map[string]string{ - "server": web.BConfig.ServerName, - "env": web.BConfig.RunMode, - "appname": web.BConfig.AppName, + "server": builder.ServerName, + "env": builder.RunMode, + "appname": builder.AppName, }, Help: "The statics info for remote http requests", }, []string{"proto", "scheme", "method", "host", "path", "status", "duration", "isError"}) From dd3f1ce9be8c6d33ad4ad379d4aadcdf000e1e15 Mon Sep 17 00:00:00 2001 From: Ming Deng Date: Sun, 27 Sep 2020 00:44:02 +0800 Subject: [PATCH 2/2] decouple httplib from config --- pkg/client/httplib/testing/client.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/pkg/client/httplib/testing/client.go b/pkg/client/httplib/testing/client.go index 00fa3059..107b28cc 100644 --- a/pkg/client/httplib/testing/client.go +++ b/pkg/client/httplib/testing/client.go @@ -16,8 +16,6 @@ package testing import ( "github.com/astaxie/beego/pkg/client/httplib" - - "github.com/astaxie/beego/pkg/infrastructure/config" ) var port = "" @@ -28,16 +26,13 @@ type TestHTTPRequest struct { httplib.BeegoHTTPRequest } +func SetTestingPort(p string) { + port = p +} + func getPort() string { if port == "" { - config, err := config.NewConfig("ini", "../conf/app.conf") - if err != nil { - return "8080" - } - port, err = config.String(nil, "httpport") - if err != nil { - return "8080" - } + port = "8080" return port } return port