From bd714b13f78ca563b654046b4281da578115306d Mon Sep 17 00:00:00 2001 From: Dwi Siswanto Date: Wed, 25 Oct 2023 20:06:07 +0700 Subject: [PATCH] chore(runner): refactor tunnel generator Signed-off-by: Dwi Siswanto --- internal/runner/runner.go | 4 ++-- internal/runner/utils.go | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/internal/runner/runner.go b/internal/runner/runner.go index ad48094..6d6ca0d 100644 --- a/internal/runner/runner.go +++ b/internal/runner/runner.go @@ -16,7 +16,6 @@ import ( "github.com/kitabisa/teler-proxy/common" "github.com/kitabisa/teler-proxy/internal/cron" "github.com/kitabisa/teler-proxy/internal/writer" - "github.com/kitabisa/teler-proxy/pkg/tunnel" "github.com/kitabisa/teler-waf" "github.com/kitabisa/teler-waf/threat" ) @@ -56,8 +55,9 @@ func New(opt *common.Options) error { } dest := buildDest(opt.Destination) + writer := writer.New() - tun, err := tunnel.NewTunnel(opt.Port, dest, opt.Config.Path, opt.Config.Format, writer.New()) + tun, err := run.createTunnel(dest, writer) if err != nil { return err } diff --git a/internal/runner/utils.go b/internal/runner/utils.go index 43071b9..6e51839 100644 --- a/internal/runner/utils.go +++ b/internal/runner/utils.go @@ -2,11 +2,14 @@ package runner import ( "fmt" + "io" "net" "strings" "time" "net/url" + + "github.com/kitabisa/teler-proxy/pkg/tunnel" ) func parseURL(dest string) (*url.URL, error) { @@ -67,3 +70,9 @@ func (r *Runner) shouldCron() bool { return false } + +func (r *Runner) createTunnel(dest string, writer io.Writer) (*tunnel.Tunnel, error) { + opt := r.Options + + return tunnel.NewTunnel(opt.Port, dest, opt.Config.Path, opt.Config.Format, writer) +}