Skip to content

Commit

Permalink
Remove use of zap in httpPlusdb example (#1391)
Browse files Browse the repository at this point in the history
Unify on slog for project logging.
  • Loading branch information
MrAlias authored Dec 9, 2024
1 parent 0166c6f commit 9248058
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 27 deletions.
7 changes: 1 addition & 6 deletions examples/httpPlusdb/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,4 @@ module go.opentelemetry.io/auto/examples/httpPlusdb

go 1.20

require (
github.com/mattn/go-sqlite3 v1.14.24
go.uber.org/zap v1.27.0
)

require go.uber.org/multierr v1.11.0 // indirect
require github.com/mattn/go-sqlite3 v1.14.24
9 changes: 0 additions & 9 deletions examples/httpPlusdb/go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,2 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/mattn/go-sqlite3 v1.14.24 h1:tpSp2G2KyMnnQu99ngJ47EIkWVmliIizyZBfPrBWDRM=
github.com/mattn/go-sqlite3 v1.14.24/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
16 changes: 4 additions & 12 deletions examples/httpPlusdb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ package main
import (
"database/sql"
"fmt"
"log/slog"
"net/http"
"os"

_ "github.com/mattn/go-sqlite3"
"go.uber.org/zap"
)

const (
Expand Down Expand Up @@ -84,7 +84,7 @@ func (s *Server) queryDb(w http.ResponseWriter, req *http.Request) {
panic(err)
}

logger.Info("queryDb called")
slog.Info("queryDb called")
for rows.Next() {
var id int
var firstName string
Expand All @@ -99,27 +99,19 @@ func (s *Server) queryDb(w http.ResponseWriter, req *http.Request) {
}
}

var logger *zap.Logger

func setupHandler(s *Server) *http.ServeMux {
mux := http.NewServeMux()
mux.HandleFunc("/query_db", s.queryDb)
return mux
}

func main() {
var err error
logger, err = zap.NewDevelopment()
if err != nil {
fmt.Printf("error creating zap logger, error:%v", err)
return
}
port := fmt.Sprintf(":%d", 8080)
logger.Info("starting http server", zap.String("port", port))
slog.Info("starting http server", "port", port)

s := NewServer()
mux := setupHandler(s)
if err := http.ListenAndServe(port, mux); err != nil {
logger.Error("error running server", zap.Error(err))
slog.Error("error running server", "error", err)
}
}

0 comments on commit 9248058

Please sign in to comment.