@@ -20,38 +20,31 @@ For this you can use the `ReplaceGroup` and `ReplaceAttr` fields in `Options`:
2020
2121
2222``` go
23- packag
23+ package main
24+
2425import (
2526 " log/slog"
2627 sloghttp " github.com/samber/slog-http"
2728 slogjournal " github.com/systemd/slog-journal"
2829)
2930
30- h , err := slogjournal.NewHandler (&slogjournal.Options {
31- ReplaceGroup : func (k string ) string {
32- return strings.ReplaceAll (strings.ToUpper (k), " -" , " _" )
33- },
34- ReplaceAttr : func (groups []string , a slog.Attr ) slog.Attr {
35- a.Key = strings.ReplaceAll (strings.ToUpper (a.Key ), " -" , " _" )
36- return a
37- },
38- })
39-
40- log := slog.New (h)
41- mux := http.NewServeMux ()
42- mux.HandleFunc (" /" , func (w http.ResponseWriter , r *http.Request ) {
43- log.Info (" Hello world" )
44- w.Write ([]byte (" Hello, world!" ))
45- })
46- http.ListenAndServe (" :8080" , sloghttp.New (log)(mux))
47- ```
48-
49-
50-
51-
52-
53-
54-
55-
56-
31+ func main () {
32+ h , err := slogjournal.NewHandler (&slogjournal.Options {
33+ ReplaceGroup: func (k string ) string {
34+ return strings.ReplaceAll (strings.ToUpper (k), " -" , " _" )
35+ },
36+ ReplaceAttr: func (groups []string , a slog.Attr ) slog.Attr {
37+ a.Key = strings.ReplaceAll (strings.ToUpper (a.Key ), " -" , " _" )
38+ return a
39+ },
40+ })
41+
42+ log := slog.New (h)
43+ mux := http.NewServeMux ()
44+ mux.HandleFunc (" /" , func (w http.ResponseWriter , r *http.Request ) {
45+ log.Info (" Hello world" )
46+ w.Write ([]byte (" Hello, world!" ))
47+ })
48+ http.ListenAndServe (" :8080" , sloghttp.New (log)(mux))
49+ }
5750```
0 commit comments