Skip to content

Commit

Permalink
fix: Turn-off random logging by Go stdlib
Browse files Browse the repository at this point in the history
fix:  Turn-off random logging by Go stdlib
  • Loading branch information
jiuker committed Jun 12, 2024
1 parent 6c17042 commit bbade76
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"errors"
"fmt"
"io"
"log"
"math"
"math/rand"
"net"
Expand Down Expand Up @@ -910,6 +911,11 @@ func sidekickMain(ctx *cli.Context) {
}

router.PathPrefix(slashSeparator).Handler(m)
server := &http.Server{
Addr: addr,
Handler: router,
ErrorLog: log.New(io.Discard, "", 0), // Turn-off random logging by Go stdlib. From MinIO server implementation.
}
if ctx.String("cert") != "" && ctx.String("key") != "" {
manager, err := certs.NewManager(context.Background(), ctx.String("cert"), ctx.String("key"), tls.LoadX509KeyPair)
if err != nil {
Expand All @@ -922,21 +928,17 @@ func sidekickMain(ctx *cli.Context) {
MinVersion: tls.VersionTLS12,
ClientSessionCache: tls.NewLRUClientSessionCache(tlsClientSessionCacheSize),
}
server.TLSConfig = tlsConfig
listener, err := tls.Listen("tcp", addr, tlsConfig)
if err != nil {
console.Fatalln(err)
}
server := &http.Server{
Handler: router,
Addr: addr,
TLSConfig: tlsConfig,
}
err = server.Serve(listener)
if err != nil {
console.Fatalln(err)
}
} else {
if err := http.ListenAndServe(addr, router); err != nil {
if err := server.ListenAndServe(); err != nil {
console.Fatalln(err)
}
}
Expand Down

0 comments on commit bbade76

Please sign in to comment.