diff --git a/.github/workflows/go_ci_lint.yml b/.github/workflows/go_ci_lint.yml index 2d5211c..9b1ad53 100644 --- a/.github/workflows/go_ci_lint.yml +++ b/.github/workflows/go_ci_lint.yml @@ -14,7 +14,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: - go-version: '1.20' + go-version: '1.21' - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: diff --git a/.github/workflows/go_mod_check.yml b/.github/workflows/go_mod_check.yml index 2109152..8530fdb 100644 --- a/.github/workflows/go_mod_check.yml +++ b/.github/workflows/go_mod_check.yml @@ -15,7 +15,7 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: - go-version: '1.20' + go-version: '1.21' - name: Run Go Mod Check Action uses: Shoothzj/go-mod-check-action@main with: diff --git a/.github/workflows/go_unit_test.yml b/.github/workflows/go_unit_test.yml index b31e5a8..aeb105e 100644 --- a/.github/workflows/go_unit_test.yml +++ b/.github/workflows/go_unit_test.yml @@ -15,6 +15,6 @@ jobs: - uses: actions/checkout@v4 - uses: actions/setup-go@v4 with: - go-version: '1.20' + go-version: '1.21' - name: Run coverage run: go test ./... -coverpkg=./opcua/... -race -coverprofile=coverage.out -covermode=atomic diff --git a/go.mod b/go.mod index d41d48b..692723c 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module opcua-go -go 1.20 +go 1.21 require github.com/stretchr/testify v1.9.0 diff --git a/opcua/client.go b/opcua/client.go index f71e3f1..61240a9 100644 --- a/opcua/client.go +++ b/opcua/client.go @@ -1,12 +1,18 @@ package opcua +import "log/slog" + type ClientConfig struct { + logger *slog.Logger } type Client struct { + logger *slog.Logger } func NewClient(config *ClientConfig) *Client { - client := &Client{} + client := &Client{ + logger: config.logger, + } return client } diff --git a/opcua/server.go b/opcua/server.go index dd20d49..cd99d5b 100644 --- a/opcua/server.go +++ b/opcua/server.go @@ -2,6 +2,7 @@ package opcua import ( "fmt" + "log/slog" "net" "sync" ) @@ -9,6 +10,8 @@ import ( type ServerConfig struct { Host string Port int + + logger *slog.Logger } func (s *ServerConfig) addr() string { @@ -19,6 +22,8 @@ type Server struct { config *ServerConfig listener net.Listener + logger *slog.Logger + mutex sync.RWMutex quit chan bool } @@ -27,7 +32,9 @@ func NewServer(config *ServerConfig) *Server { server := &Server{ config: config, quit: make(chan bool), + logger: config.logger, } + server.logger.Info("server initialized", slog.String("host", config.Host), slog.Int("port", config.Port)) return server } @@ -91,6 +98,7 @@ func (s *Server) Close() error { err := s.listener.Close() s.listener = nil if err == nil { + s.logger.Info("server closed successfully") return nil } return fmt.Errorf("failed to close listener: %w", err) diff --git a/opcua/server_test.go b/opcua/server_test.go index d6a762e..2e74862 100644 --- a/opcua/server_test.go +++ b/opcua/server_test.go @@ -3,13 +3,15 @@ package opcua import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "log/slog" "testing" ) func TestStartWithZeroPort(t *testing.T) { config := &ServerConfig{ - Host: "localhost", - Port: 0, + Host: "localhost", + Port: 0, + logger: slog.Default(), } server := NewServer(config)