Skip to content

Commit

Permalink
return a number for current_visitors
Browse files Browse the repository at this point in the history
  • Loading branch information
gernest committed Feb 17, 2024
1 parent 848095f commit 75afca7
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 1 addition & 3 deletions docs/3-stats.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,7 @@ in the last 5 minutes.

```bash
+ curl -X GET 'http://localhost:8080/api/v1/stats/realtime/visitors?site_id=vinceanalytics.com'
{
"visitors": "5"
}
6
```


Expand Down
10 changes: 8 additions & 2 deletions request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,14 @@ func Validate(ctx context.Context, w http.ResponseWriter, o proto.Message) bool
return true
}

func Write(ctx context.Context, w http.ResponseWriter, o proto.Message) {
data, err := m.Marshal(o)
func Write(ctx context.Context, w http.ResponseWriter, o any) {
var data []byte
var err error
if a, ok := o.(proto.Message); ok {
data, err = m.Marshal(a)
} else {
data, err = json.Marshal(o)
}
if err != nil {
logger.Fail("Can't marshall proto messages", "err", err)
}
Expand Down
2 changes: 1 addition & 1 deletion stats/current_visitors.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ func Realtime(w http.ResponseWriter, r *http.Request) {
request.Internal(ctx, w)
return
}
request.Write(ctx, w, &v1.Realtime_Response{Visitors: uint64(visitors)})
request.Write(ctx, w, uint64(visitors))
}

0 comments on commit 75afca7

Please sign in to comment.