Introduction
A counting service for PV and UV (based on Golang and Redis)
1. Why do this
I write a personal website: https://plantree.me, to archive my blogs. In the beginning, I used the visitor-badge service to show the number of visitors of each page. However, I found some drawbacks:
- The service is not robust enough, which will limit the request when the QPS is too high.
- This service is just designed for generating badge, and the data service behind is countapi. Unfortunately, it just provide limited interfaces and services, which could not satisfy my need.
I need a service that contains these functions:
- Count service and badge generator service are deployed independently, and count service just provide data service. BTW, source code about badge generator service will be put in visitor-badge.
- Count service could support PV(Page-Views) and UV(Unique-Visitors).
- Count service could support reset/update manually, with secret to avoid malicious tampering.
countapi vs visitor-badge/hit-counter
2. counter vscounter | countapi | visitor-badge/hit-counter | |
---|---|---|---|
Service | just count | just count | hybrid count and badge generator, but not easy to get the data |
Open Source | ✅ | ❌ | ✅ |
Self Deployment | easy | difficult | medium |
Features | read/write, with secret | read/write, without secret | read only |
3. How to use
- API description: https://app.swaggerhub.com/apis/plantree/counter/1.0.0
- Home page: https://counter.plantree.me/
4. Changelog
0.0.9 (2022-12-26)
Feature
- README, the documentation and first version implementation
- support PV, includes: get/increment/reset/delete
Reference:
- https://github.com/jwenjian/visitor-badge
- https://countapi.xyz/
- https://github.com/gjbae1212/hit-counter
- https://github.com/golang-standards/project-layout/blob/master/README.md
- https://www.qikqiak.com/post/use-github-actions-build-go-app/
- https://www.liwenzhou.com/posts/Go/deploy/
- https://abigeater.com/archives/194