Skip to content

Commit

Permalink
feat: add webserver example
Browse files Browse the repository at this point in the history
  • Loading branch information
lvlcn-t committed Feb 24, 2024
1 parent 35babc1 commit 3d6d55f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions examples/webserver/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package main

import (
"context"
"net/http"

"github.com/lvlcn-t/loggerhead/logger"
)

func main() {
ctx := logger.IntoContext(context.Background(), logger.NewNamedLogger("webserver"))
s := &http.Server{
Addr: ":8080",
}

var handler http.HandlerFunc = func(w http.ResponseWriter, r *http.Request) {
log := logger.FromContext(r.Context())
log.Info("Hello, world!")

w.WriteHeader(http.StatusOK)
w.Write([]byte("Hello, world!"))
}

http.Handle("/", logger.Middleware(ctx)(handler))

s.ListenAndServe()
}

0 comments on commit 3d6d55f

Please sign in to comment.