Introduction

A counting service for PV and UV (based on Golang and Redis)

1. Why do this

I write a personal website: https://plantree.meopen in new window, to archive my blogs. In the beginning, I used the visitor-badgeopen in new window service to show the number of visitors of each page. However, I found some drawbacks:

  1. The service is not robust enough, which will limit the request when the QPS is too high.
  2. This service is just designed for generating badge, and the data service behind is countapiopen in new window. Unfortunately, it just provide limited interfaces and services, which could not satisfy my need.

I need a service that contains these functions:

  1. 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-badgeopen in new window.
  2. Count service could support PV(Page-Views) and UV(Unique-Visitors).
  3. Count service could support reset/update manually, with secret to avoid malicious tampering.

2. counter vs countapiopen in new window vs visitor-badgeopen in new window/hit-counteropen in new window

countercountapivisitor-badge/hit-counter
Servicejust countjust counthybrid count and badge generator, but not easy to get the data
Open Source
Self Deploymenteasydifficultmedium
Featuresread/write, with secretread/write, without secretread only

3. How to use

4. Changelog

0.0.9 (2022-12-26)
Feature
  1. README, the documentation and first version implementation
  2. support PV, includes: get/increment/reset/delete

Reference:

  1. https://github.com/jwenjian/visitor-badgeopen in new window
  2. https://countapi.xyz/open in new window
  3. https://github.com/gjbae1212/hit-counteropen in new window
  4. https://github.com/golang-standards/project-layout/blob/master/README.mdopen in new window
  5. https://www.qikqiak.com/post/use-github-actions-build-go-app/open in new window
  6. https://www.liwenzhou.com/posts/Go/deploy/open in new window
  7. https://abigeater.com/archives/194open in new window