Skip to content

Commit 553ca05

Browse files
committed
Fix docs
Signed-off-by: Xabier Larrakoetxea <me@slok.dev>
1 parent 4950408 commit 553ca05

File tree

3 files changed

+4
-65
lines changed

3 files changed

+4
-65
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## [Unreleased]
44

5-
Breaking change. The library has been refactored to be more flexible when adding new framework/libraries.
5+
Breaking change: The library has been refactored to be more flexible when adding new framework/libraries.
66

77
### Added
88

@@ -14,7 +14,7 @@ Breaking change. The library has been refactored to be more flexible when adding
1414
- Added `Reporter` interface as the service responsible of getting the data to be measured.
1515
- All different framwork helpers now implement with the new Reporter way.
1616
- Fixed Gin returning duplicated data (#31).
17-
- Standard handler now is on `middleware/std` instead of `middleware`.
17+
- (Breaking) Standard handler now is on `middleware/std` instead of `middleware`.
1818

1919
### Removed
2020

Readme.md

Lines changed: 1 addition & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func main() {
7070
w.WriteHeader(http.StatusOK)
7171
w.Write([]byte("hello world!"))
7272
})
73-
h = middlewarestd.Measure("", mdlw, h)
73+
h = middlewarestd.Handler("", mdlw, h)
7474

7575
// Serve metrics.
7676
log.Printf("serving metrics at: %s", ":9090")
@@ -86,67 +86,6 @@ func main() {
8686

8787
For more examples check the [examples]. [default][default-example] and [custom][custom-example] are the examples for Go net/http std library users.
8888

89-
## V1 migration
90-
91-
From `v0` to `v1` the middleware API has changed (not the metrics API or metric implementations).
92-
93-
This changes was because `v0` started with `http.Handler` in mind, but then the support for some libs/middlwares were implemented, the way these frameworks/libraries are designed itself, are not compatible with go's `http.Handler`, but we want to support these and many more. So to be able to support these correctly and many more,an internal big refactor was required, this lead us to the need to leak a little bit of this internal refactor.
94-
95-
Here is how you can migrate the standard `http.Handler` from one to another (the other framework/lib migrations are straignforward).
96-
97-
Before:
98-
99-
```go
100-
package main
101-
102-
import (
103-
metrics "github.com/slok/go-http-metrics/metrics/prometheus"
104-
"github.com/slok/go-http-metrics/middleware"
105-
)
106-
107-
func main() {
108-
// Create our middleware.
109-
mdlw := middleware.New(middleware.Config{
110-
Recorder: metrics.NewRecorder(metrics.Config{}),
111-
})
112-
113-
myHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
114-
w.WriteHeader(http.StatusOK)
115-
w.Write([]byte("hello world!"))
116-
})
117-
118-
// Measure handler.
119-
h := mdlw.Handler("", myHandler)
120-
}
121-
```
122-
123-
After:
124-
125-
```go
126-
package main
127-
128-
import (
129-
metrics "github.com/slok/go-http-metrics/metrics/prometheus"
130-
"github.com/slok/go-http-metrics/middleware"
131-
middlewarestd "github.com/slok/go-http-metrics/middleware/std"
132-
)
133-
134-
func main() {
135-
// Create our middleware.
136-
mdlw := middleware.New(middleware.Config{
137-
Recorder: metrics.NewRecorder(metrics.Config{}),
138-
})
139-
140-
myHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
141-
w.WriteHeader(http.StatusOK)
142-
w.Write([]byte("hello world!"))
143-
})
144-
145-
// Measure handler.
146-
h := middlewarestd.Measure("", mdlw, myHandler)
147-
}
148-
```
149-
15089
## Prometheus query examples
15190

15291
Get the request rate by handler:

doc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ the main Go net/http handler:
2525
w.WriteHeader(http.StatusOK)
2626
w.Write([]byte("hello world!"))
2727
})
28-
h := httpstdmiddleware.Measure("", mdlw, myHandler)
28+
h := httpstdmiddleware.Handler("", mdlw, myHandler)
2929
3030
// Serve metrics.
3131
log.Printf("serving metrics at: %s", ":9090")

0 commit comments

Comments
 (0)