diff --git a/go.mod b/go.mod index 84726e6..d36dd93 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.21.3 require ( github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6 + github.com/go-echarts/statsview v0.3.4 github.com/go-playground/validator v9.31.0+incompatible github.com/imroc/req/v3 v3.42.2 github.com/labstack/echo/v4 v4.11.3 @@ -21,6 +22,7 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/dustin/go-humanize v1.0.1 // indirect github.com/gaukas/godicttls v0.0.4 // indirect + github.com/go-echarts/go-echarts/v2 v2.2.3 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect @@ -42,6 +44,7 @@ require ( github.com/quic-go/qtls-go1-20 v0.3.3 // indirect github.com/quic-go/quic-go v0.38.1 // indirect github.com/refraction-networking/utls v1.5.3 // indirect + github.com/rs/cors v1.7.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect golang.org/x/crypto v0.14.0 // indirect diff --git a/go.sum b/go.sum index 7bd09a9..38b8012 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,10 @@ github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6 h1:6VSn3hB5U5GeA6kQ github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6/go.mod h1:YxOVT5+yHzKvwhsiSIWmbAYM3Dr9AEEbER2dVayfBkg= github.com/gaukas/godicttls v0.0.4 h1:NlRaXb3J6hAnTmWdsEKb9bcSBD6BvcIjdGdeb0zfXbk= github.com/gaukas/godicttls v0.0.4/go.mod h1:l6EenT4TLWgTdwslVb4sEMOCf7Bv0JAK67deKr9/NCI= +github.com/go-echarts/go-echarts/v2 v2.2.3 h1:H8oPdUpzuiV2K8S4xYZa1JRNjP3U0h7HVqvhPrmCk1A= +github.com/go-echarts/go-echarts/v2 v2.2.3/go.mod h1:6TOomEztzGDVDkOSCFBq3ed7xOYfbOqhaBzD0YV771A= +github.com/go-echarts/statsview v0.3.4 h1:CCuytRAutdnF901NrR4BzSjHXjUp8OyA3/iopgG/1/Y= +github.com/go-echarts/statsview v0.3.4/go.mod h1:AehKjL9cTFMeIo5QdV8sQO43vFmfY65X5GMWa3XMciY= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= @@ -45,6 +49,7 @@ github.com/imroc/req/v3 v3.42.2 h1:/BwrKXGR7X1/ptccaQAiziDCeZ7T6ye55g3ZhiLy1fc= github.com/imroc/req/v3 v3.42.2/go.mod h1:W7dOrfQORA9nFoj+CafIZ6P5iyk+rWdbp2sffOAvABU= github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -80,11 +85,14 @@ github.com/quic-go/quic-go v0.38.1 h1:M36YWA5dEhEeT+slOu/SwMEucbYd0YFidxG3KlGPZa github.com/quic-go/quic-go v0.38.1/go.mod h1:ijnZM7JsFIkp4cRyjxJNIzdSfCLmUMg9wdyhGmg+SN4= github.com/refraction-networking/utls v1.5.3 h1:Ds5Ocg1+MC1ahNx5iBEcHe0jHeLaA/fLey61EENm7ro= github.com/refraction-networking/utls v1.5.3/go.mod h1:SPuDbBmgLGp8s+HLNc83FuavwZCFoMmExj+ltUHiHUw= +github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= +github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.6.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -171,6 +179,7 @@ golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8T google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw= google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/go-playground/assert.v1 v1.2.1 h1:xoYuJVE7KT85PYWrN730RguIQO0ePzVRfFMXadIrXTM= diff --git a/main.go b/main.go index ea9e0b9..ea68bca 100644 --- a/main.go +++ b/main.go @@ -12,12 +12,16 @@ import ( //go:embed all:frontend/dist/* var publicDir embed.FS -var ( - port string +type Flags struct { host string - baseURL string + port string + baseUrl string allowedRemoteDomains string -) + pprofHost string + pprofPort string +} + +var f Flags var version = "dev" func main() { @@ -25,16 +29,37 @@ func main() { fmt.Println(version) return } - flags() - e := pkg.NewEcho(baseURL, publicDir, allowedRemoteDomains) + SetupFlags() + e := pkg.NewEcho(f.baseUrl, publicDir) - pkg.GracefulServerWithPid(e, host, port) + pkg.GracefulServerWithPid(e, f.host, f.port) } -func flags() { - flag.StringVar(&host, "host", "localhost", "host to serve") - flag.StringVar(&port, "port", "3001", "port to serve") - flag.StringVar(&baseURL, "base-url", "/", "base url with slash") - flag.StringVar(&allowedRemoteDomains, "allow-domains", "", "csv list of allowed domains for remote fetching") +func SetupFlags() { + flag.StringVar(&f.host, "host", "localhost", "host to serve") + flag.StringVar(&f.port, "port", "3001", "port to serve") + flag.StringVar(&f.baseUrl, "base-url", "/", "base url with slash") + flag.StringVar(&f.allowedRemoteDomains, "remote-domains", "", "csv list of allowed domains for remote fetching") + flag.StringVar(&f.pprofHost, "pprof-host", "", "pprof host") + flag.StringVar(&f.pprofPort, "pprof-port", "", "pprof port") flag.Parse() + + if f.pprofHost != "" && os.Getenv("PPROF_HOST") == "" { + err := os.Setenv("PPROF_HOST", f.pprofHost) + if err != nil { + pkg.Logger().Error(err) + } + } + if f.pprofPort != "" && os.Getenv("PPROF_PORT") == "" { + err := os.Setenv("PPROF_PORT", f.pprofPort) + if err != nil { + pkg.Logger().Error(err) + } + } + if f.allowedRemoteDomains != "" && os.Getenv("ALLOWED_REMOTE_DOMAINS") == "" { + err := os.Setenv("ALLOWED_REMOTE_DOMAINS", f.allowedRemoteDomains) + if err != nil { + pkg.Logger().Error(err) + } + } } diff --git a/pkg/bar_chart_handler.go b/pkg/bar_chart_handler.go index 6e9014c..e79cd84 100644 --- a/pkg/bar_chart_handler.go +++ b/pkg/bar_chart_handler.go @@ -9,14 +9,12 @@ import ( ) type BarChartHandler struct { - chart *BarChart - allowedRemoteDomains string + chart *BarChart } -func NewBarChartHandler(allowedRemoteDomains string) *BarChartHandler { +func NewBarChartHandler() *BarChartHandler { return &BarChartHandler{ - chart: NewBarChart(), - allowedRemoteDomains: allowedRemoteDomains, + chart: NewBarChart(), } } @@ -38,7 +36,7 @@ func (h *BarChartHandler) Get(c echo.Context) ([]byte, error) { if err != nil { return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, msgs) } - err = SetDataIfRemoteURL(req, h.allowedRemoteDomains) + err = SetDataIfRemoteURL(req) if err != nil { msgs := map[string]string{ "data": err.Error(), diff --git a/pkg/bar_chart_handler_test.go b/pkg/bar_chart_handler_test.go index 16dca1e..cd44716 100644 --- a/pkg/bar_chart_handler_test.go +++ b/pkg/bar_chart_handler_test.go @@ -14,7 +14,7 @@ func TestGetBarChart(t *testing.T) { e := echo.New() e.GET("/bar", func(c echo.Context) error { - img, err := NewBarChartHandler("").Get(c) + img, err := NewBarChartHandler().Get(c) if err != nil { return err } diff --git a/pkg/chart.go b/pkg/chart.go index dc4be78..538fd79 100644 --- a/pkg/chart.go +++ b/pkg/chart.go @@ -4,6 +4,7 @@ import ( "errors" "net/http" "net/url" + "os" "strconv" "strings" @@ -125,7 +126,11 @@ func GetURL(urlStr string) (string, error) { return resp.ToString() } -func SetDataIfRemoteURL(req *ChartRequest, allowedRemoteDomains string) error { +func SetDataIfRemoteURL(req *ChartRequest) error { + allowedRemoteDomains := os.Getenv("ALLOWED_REMOTE_DOMAINS") + if allowedRemoteDomains == "" { + return nil + } if IsURL(req.ChartData) { if !IsAllowedDomain(req.ChartData, allowedRemoteDomains) { return errors.New("URL is not allowed") diff --git a/pkg/donut_chart_handler.go b/pkg/donut_chart_handler.go index caec19b..d6c909a 100644 --- a/pkg/donut_chart_handler.go +++ b/pkg/donut_chart_handler.go @@ -9,14 +9,12 @@ import ( ) type DonutChartHandler struct { - chart *DonutChart - allowedRemoteDomains string + chart *DonutChart } -func NewDonutChartHandler(allowedRemoteDomains string) *DonutChartHandler { +func NewDonutChartHandler() *DonutChartHandler { return &DonutChartHandler{ - chart: NewDonutChart(), - allowedRemoteDomains: allowedRemoteDomains, + chart: NewDonutChart(), } } @@ -36,7 +34,7 @@ func (h *DonutChartHandler) Get(c echo.Context) ([]byte, error) { if err != nil { return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, msgs) } - err = SetDataIfRemoteURL(req, h.allowedRemoteDomains) + err = SetDataIfRemoteURL(req) if err != nil { msgs := map[string]string{ "data": err.Error(), diff --git a/pkg/donut_chart_handler_test.go b/pkg/donut_chart_handler_test.go index 9be94d2..8369cb9 100644 --- a/pkg/donut_chart_handler_test.go +++ b/pkg/donut_chart_handler_test.go @@ -14,7 +14,7 @@ func TestGetDonutChart(t *testing.T) { e := echo.New() e.GET("/donut", func(c echo.Context) error { - img, err := NewDonutChartHandler("").Get(c) + img, err := NewDonutChartHandler().Get(c) if err != nil { return err } diff --git a/pkg/echo.go b/pkg/echo.go index 23cf472..bf4c885 100644 --- a/pkg/echo.go +++ b/pkg/echo.go @@ -8,22 +8,32 @@ import ( "strconv" "github.com/fvbock/endless" + "github.com/go-echarts/statsview" + "github.com/go-echarts/statsview/viewer" "github.com/labstack/echo/v4" "github.com/labstack/echo/v4/middleware" ) -func NewEcho(baseURL string, publicDir embed.FS, allowedRemoteDomains string) *echo.Echo { +func NewEcho(baseURL string, publicDir embed.FS) *echo.Echo { + if os.Getenv("PPROF_HOST") != "" && os.Getenv("PPROF_PORT") != "" { + Logger().Info("pprof enabled and listening on: ", os.Getenv("PPROF_HOST")+":"+os.Getenv("PPROF_PORT")) + addr := os.Getenv("PPROF_HOST") + ":" + os.Getenv("PPROF_PORT") + viewer.SetConfiguration(viewer.WithTheme(viewer.ThemeWesteros), viewer.WithAddr(addr)) + mgr := statsview.New() + _ = mgr + go mgr.Start() + // mgr.Stop() + } e := echo.New() - //recover e.Use(middleware.Recover()) e.HTTPErrorHandler = HTTPErrorHandler e.Pre(middleware.RemoveTrailingSlash()) e.Use(middleware.Gzip()) e.Use(middleware.LoggerWithConfig(middleware.LoggerConfig{ - Format: "REQUEST[${time_custom}] ${method} ${uri} (${latency_human}) ${status} ${remote_ip}\n", + Format: ltsv(), CustomTimeFormat: "2006-01-02 15:04:05", })) - SetupRoutes(e, baseURL, publicDir, allowedRemoteDomains) + SetupRoutes(e, baseURL, publicDir) return e } @@ -72,3 +82,28 @@ func HTTPErrorHandler(err error, c echo.Context) { Logger().Error(err) } } + +func ltsv() string { + time_custom := "2006-01-02 15:04:05" + _ = time_custom + var format string + format += "time:${time_custom}\t" + format += "host:${remote_ip}\t" + format += "forwardedfor:${header:x-forwarded-for}\t" + format += "req:-\t" + format += "status:${status}\t" + format += "method:${method}\t" + format += "uri:${uri}\t" + format += "size:${bytes_out}\t" + format += "referer:${referer}\t" + format += "ua:${user_agent}\t" + format += "reqtime_ns:${latency}\t" + format += "cache:-\t" + format += "runtime:-\t" + format += "apptime:-\t" + format += "vhost:${host}\t" + format += "reqtime_human:${latency_human}\t" + format += "x-request-id:${id}\t" + format += "host:${host}\n" + return format +} diff --git a/pkg/funnel_chart_handler.go b/pkg/funnel_chart_handler.go index 2b14f35..ae2a8e7 100644 --- a/pkg/funnel_chart_handler.go +++ b/pkg/funnel_chart_handler.go @@ -9,14 +9,12 @@ import ( ) type FunnelChartHandler struct { - chart *FunnelChart - allowedRemoteDomains string + chart *FunnelChart } -func NewFunnelChartHandler(allowedRemoteDomains string) *FunnelChartHandler { +func NewFunnelChartHandler() *FunnelChartHandler { return &FunnelChartHandler{ - chart: NewFunnelChart(), - allowedRemoteDomains: allowedRemoteDomains, + chart: NewFunnelChart(), } } @@ -36,7 +34,7 @@ func (h *FunnelChartHandler) Get(c echo.Context) ([]byte, error) { if err != nil { return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, msgs) } - err = SetDataIfRemoteURL(req, h.allowedRemoteDomains) + err = SetDataIfRemoteURL(req) if err != nil { msgs := map[string]string{ "data": err.Error(), diff --git a/pkg/funnel_chart_handler_test.go b/pkg/funnel_chart_handler_test.go index 50491f7..3010fd3 100644 --- a/pkg/funnel_chart_handler_test.go +++ b/pkg/funnel_chart_handler_test.go @@ -14,7 +14,7 @@ func TestGetFunnelChart(t *testing.T) { e := echo.New() e.GET("/funnel", func(c echo.Context) error { - img, err := NewFunnelChartHandler("").Get(c) + img, err := NewFunnelChartHandler().Get(c) if err != nil { return err } diff --git a/pkg/line_chart_handler.go b/pkg/line_chart_handler.go index 7a78750..bbf3df1 100644 --- a/pkg/line_chart_handler.go +++ b/pkg/line_chart_handler.go @@ -9,14 +9,12 @@ import ( ) type LineChartHandler struct { - chart *LineChart - allowedRemoteDomains string + chart *LineChart } -func NewLineChartHandler(allowedRemoteDomains string) *LineChartHandler { +func NewLineChartHandler() *LineChartHandler { return &LineChartHandler{ - chart: NewLineChart(), - allowedRemoteDomains: allowedRemoteDomains, + chart: NewLineChart(), } } @@ -37,7 +35,7 @@ func (h *LineChartHandler) Get(c echo.Context) ([]byte, error) { if err != nil { return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, msgs) } - err = SetDataIfRemoteURL(req, h.allowedRemoteDomains) + err = SetDataIfRemoteURL(req) if err != nil { msgs := map[string]string{ "data": err.Error(), diff --git a/pkg/line_chart_handler_test.go b/pkg/line_chart_handler_test.go index 696098d..64f9158 100644 --- a/pkg/line_chart_handler_test.go +++ b/pkg/line_chart_handler_test.go @@ -14,7 +14,7 @@ func TestGetLineChart(t *testing.T) { e := echo.New() e.GET("/line", func(c echo.Context) error { - img, err := NewLineChartHandler("").Get(c) + img, err := NewLineChartHandler().Get(c) if err != nil { return err } diff --git a/pkg/pie_chart_handler.go b/pkg/pie_chart_handler.go index 603c51f..ddef05a 100644 --- a/pkg/pie_chart_handler.go +++ b/pkg/pie_chart_handler.go @@ -9,14 +9,12 @@ import ( ) type PieChartHandler struct { - chart *PieChart - allowedRemoteDomains string + chart *PieChart } -func NewPieChartHandler(allowedRemoteDomains string) *PieChartHandler { +func NewPieChartHandler() *PieChartHandler { return &PieChartHandler{ - chart: NewPieChart(), - allowedRemoteDomains: allowedRemoteDomains, + chart: NewPieChart(), } } @@ -36,7 +34,7 @@ func (h *PieChartHandler) Get(c echo.Context) ([]byte, error) { if err != nil { return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, msgs) } - err = SetDataIfRemoteURL(req, h.allowedRemoteDomains) + err = SetDataIfRemoteURL(req) if err != nil { msgs := map[string]string{ "data": err.Error(), diff --git a/pkg/pie_chart_handler_test.go b/pkg/pie_chart_handler_test.go index 5fccd06..02e4818 100644 --- a/pkg/pie_chart_handler_test.go +++ b/pkg/pie_chart_handler_test.go @@ -14,7 +14,7 @@ func TestGetPieChart(t *testing.T) { e := echo.New() e.GET("/pie", func(c echo.Context) error { - img, err := NewPieChartHandler("").Get(c) + img, err := NewPieChartHandler().Get(c) if err != nil { return err } diff --git a/pkg/radar_chart_handler.go b/pkg/radar_chart_handler.go index e05d6ff..214d932 100644 --- a/pkg/radar_chart_handler.go +++ b/pkg/radar_chart_handler.go @@ -9,14 +9,12 @@ import ( ) type RadarChartHandler struct { - chart *RadarChart - allowedRemoteDomains string + chart *RadarChart } -func NewRadarChartHandler(allowedRemoteDomains string) *RadarChartHandler { +func NewRadarChartHandler() *RadarChartHandler { return &RadarChartHandler{ - chart: NewRadarChart(), - allowedRemoteDomains: allowedRemoteDomains, + chart: NewRadarChart(), } } @@ -37,7 +35,7 @@ func (h *RadarChartHandler) Get(c echo.Context) ([]byte, error) { if err != nil { return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, msgs) } - err = SetDataIfRemoteURL(req, h.allowedRemoteDomains) + err = SetDataIfRemoteURL(req) if err != nil { msgs := map[string]string{ "data": err.Error(), diff --git a/pkg/radar_chart_handler_test.go b/pkg/radar_chart_handler_test.go index 652e03d..083c973 100644 --- a/pkg/radar_chart_handler_test.go +++ b/pkg/radar_chart_handler_test.go @@ -14,7 +14,7 @@ func TestGetRadarChart(t *testing.T) { e := echo.New() e.GET("/radar", func(c echo.Context) error { - img, err := NewRadarChartHandler("").Get(c) + img, err := NewRadarChartHandler().Get(c) if err != nil { return err } diff --git a/pkg/routes.go b/pkg/routes.go index 40145de..995be64 100644 --- a/pkg/routes.go +++ b/pkg/routes.go @@ -25,7 +25,7 @@ Disallow: /table` DIST_DIR = "frontend/dist" ) -func SetupRoutes(e *echo.Echo, baseURL string, publicDir embed.FS, allowedRemoteDomains string) { +func SetupRoutes(e *echo.Echo, baseURL string, publicDir embed.FS) { e.GET(baseURL+"", func(c echo.Context) error { filename := fmt.Sprintf("%s/%s", DIST_DIR, "index.html") @@ -66,7 +66,7 @@ func SetupRoutes(e *echo.Echo, baseURL string, publicDir embed.FS, allowedRemote // /line e.GET(baseURL+"line", func(c echo.Context) error { - img, err := NewLineChartHandler(allowedRemoteDomains).Get(c) + img, err := NewLineChartHandler().Get(c) if err != nil { return err } @@ -74,7 +74,7 @@ func SetupRoutes(e *echo.Echo, baseURL string, publicDir embed.FS, allowedRemote }) // /bar e.GET(baseURL+"bar", func(c echo.Context) error { - img, err := NewBarChartHandler(allowedRemoteDomains).Get(c) + img, err := NewBarChartHandler().Get(c) if err != nil { return err } @@ -82,7 +82,7 @@ func SetupRoutes(e *echo.Echo, baseURL string, publicDir embed.FS, allowedRemote }) // /radar e.GET(baseURL+"radar", func(c echo.Context) error { - img, err := NewRadarChartHandler(allowedRemoteDomains).Get(c) + img, err := NewRadarChartHandler().Get(c) if err != nil { return err } @@ -90,7 +90,7 @@ func SetupRoutes(e *echo.Echo, baseURL string, publicDir embed.FS, allowedRemote }) // /donut e.GET(baseURL+"donut", func(c echo.Context) error { - img, err := NewDonutChartHandler(allowedRemoteDomains).Get(c) + img, err := NewDonutChartHandler().Get(c) if err != nil { return err } @@ -98,7 +98,7 @@ func SetupRoutes(e *echo.Echo, baseURL string, publicDir embed.FS, allowedRemote }) // /pie e.GET(baseURL+"pie", func(c echo.Context) error { - img, err := NewPieChartHandler(allowedRemoteDomains).Get(c) + img, err := NewPieChartHandler().Get(c) if err != nil { return err } @@ -106,7 +106,7 @@ func SetupRoutes(e *echo.Echo, baseURL string, publicDir embed.FS, allowedRemote }) // /funnel e.GET(baseURL+"funnel", func(c echo.Context) error { - img, err := NewFunnelChartHandler(allowedRemoteDomains).Get(c) + img, err := NewFunnelChartHandler().Get(c) if err != nil { return err } @@ -114,7 +114,7 @@ func SetupRoutes(e *echo.Echo, baseURL string, publicDir embed.FS, allowedRemote }) // /table e.GET(baseURL+"table", func(c echo.Context) error { - img, err := NewTableChartHandler(allowedRemoteDomains).Get(c) + img, err := NewTableChartHandler().Get(c) if err != nil { return err } diff --git a/pkg/table_chart_handler.go b/pkg/table_chart_handler.go index aa7fe1c..0c6710b 100644 --- a/pkg/table_chart_handler.go +++ b/pkg/table_chart_handler.go @@ -9,14 +9,12 @@ import ( ) type TableChartHandler struct { - chart *TableChart - allowedRemoteDomains string + chart *TableChart } -func NewTableChartHandler(allowedRemoteDomains string) *TableChartHandler { +func NewTableChartHandler() *TableChartHandler { return &TableChartHandler{ - chart: NewTableChart(), - allowedRemoteDomains: allowedRemoteDomains, + chart: NewTableChart(), } } @@ -36,7 +34,7 @@ func (h *TableChartHandler) Get(c echo.Context) ([]byte, error) { if err != nil { return nil, echo.NewHTTPError(http.StatusUnprocessableEntity, msgs) } - err = SetDataIfRemoteURL(req, h.allowedRemoteDomains) + err = SetDataIfRemoteURL(req) if err != nil { msgs := map[string]string{ "data": err.Error(), diff --git a/pkg/table_chart_handler_test.go b/pkg/table_chart_handler_test.go index c238110..bb09369 100644 --- a/pkg/table_chart_handler_test.go +++ b/pkg/table_chart_handler_test.go @@ -14,7 +14,7 @@ func TestGetTableChart(t *testing.T) { e := echo.New() e.GET("/table", func(c echo.Context) error { - img, err := NewTableChartHandler("").Get(c) + img, err := NewTableChartHandler().Get(c) if err != nil { return err }