From 7cb82c875b6b0a5821bbeba2b867ea58145c70cf Mon Sep 17 00:00:00 2001 From: DVK Date: Thu, 18 Jan 2024 10:35:12 +0800 Subject: [PATCH] fix: use release binary instead of self compiling (#24) --- .gitignore | 1 + cmd/client/control.go | 4 ++-- cmd/server/server.go | 4 ++-- pkg/service/service.go | 5 +++-- s.yaml | 4 ++-- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index ebb1a72..c037d28 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ *.dll *.so *.dylib +*.tar.gz # Test binary, built with `go test -c` *.test diff --git a/cmd/client/control.go b/cmd/client/control.go index a0bab28..dfda504 100644 --- a/cmd/client/control.go +++ b/cmd/client/control.go @@ -69,8 +69,8 @@ func listen(ctx context.Context, server net.Listener, pa string, pt tunnel.Type, if err != nil { slog.Error(consts.ACCEPT_ERROR, "err", err) } - if srv, ok := service.Factory[pt]; ok { - destConn, err := srv.Conn(ctx, t, service.WithAddr(pa)) + if srv, ok := service.Factory.Load(pt); ok { + destConn, err := srv.(service.Service).Conn(ctx, t, service.WithAddr(pa)) if err != nil { slog.Error(consts.CONNECT_RMOET_ERROR, "err", err) continue diff --git a/cmd/server/server.go b/cmd/server/server.go index 2d1cf2a..048a6ad 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -24,8 +24,8 @@ func New(opts ...Option) (*Server, error) { } } // check - if srv, ok := service.Factory[s.opts.proto]; ok { - s.srv = srv + if srv, ok := service.Factory.Load(s.opts.proto); ok { + s.srv = srv.(service.Service) } if s.srv == nil { diff --git a/pkg/service/service.go b/pkg/service/service.go index 2825525..0aa9da4 100644 --- a/pkg/service/service.go +++ b/pkg/service/service.go @@ -3,6 +3,7 @@ package service import ( "context" "net" + "sync" "github.com/DVKunion/SeaMoon/pkg/transfer" "github.com/DVKunion/SeaMoon/pkg/tunnel" @@ -13,8 +14,8 @@ type Service interface { Serve(ln net.Listener, srvOpt ...Option) error } -var Factory = map[tunnel.Type]Service{} +var Factory = sync.Map{} func register(t tunnel.Type, s Service) { - Factory[t] = s + Factory.Store(t, s) } diff --git a/s.yaml b/s.yaml index 3c2e83a..cc99193 100644 --- a/s.yaml +++ b/s.yaml @@ -14,9 +14,9 @@ vars: actions: pre-deploy: - - run: go mod tidy + - run: wget https://github.com/DVKunion/SeaMoon/releases/download/1.2.0-beta.1/SeaMoon_1.2.0-beta.1_linux_amd64.tar.gz path: ./ - - run: GO111MODULE=on GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -ldflags "-X github.com/DVKunion/SeaMoon/pkg/consts.Version=2.0.0-beta.1" -o seamoon cmd/main.go + - run: tar -zvxf SeaMoon_1.2.0-beta.1_linux_amd64.tar.gz path: ./ - run: chmod +x seamoon path: ./