https://github.com/makepad-fr/gam
An analytics middleware for Go web servers
https://github.com/makepad-fr/gam
analytics go http library middleware
Last synced: 6 months ago
JSON representation
An analytics middleware for Go web servers
- Host: GitHub
- URL: https://github.com/makepad-fr/gam
- Owner: Makepad-fr
- License: apache-2.0
- Created: 2024-06-20T12:20:11.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-21T11:49:48.000Z (almost 2 years ago)
- Last Synced: 2025-03-10T04:41:58.691Z (about 1 year ago)
- Topics: analytics, go, http, library, middleware
- Language: Go
- Homepage: https://pkg.go.dev/github.com/Makepad-fr/gam
- Size: 28.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gam
[](https://pkg.go.dev/github.com/Makepad-fr/gam)
[](https://goreportcard.com/report/github.com/Makepad-fr/gam)
An analytics middleware for Go web servers
## Install
**TIP:** If you want to use a specific version please refer [releases](https://github.com/Makepad-fr/gam/releases) and replace `latest` with the desired version.
```bash
go get -u https://github.com/Makepad-fr/gam@latest
```
## Usage
First create a new instance of gam by using the [`gam.Init` function](https://pkg.go.dev/github.com/Makepad-fr/gam#Init)
```go
g, err := gam.Init("ch_username", "ch_password", "ch_hostname", "ch_port", "ch_database_name", "ch_table_name", true, true)
```
This will return an error if there's a connection issue or if the table names `ch_table_name` exists but have a different schema then the [expected schema](https://github.com/Makepad-fr/gam/blob/v1.0.0-rc5/db.go#L11-L45). Otherwise it will create an table named `ch_table_name` if it does not exists yet.
Then pass your handler function to the `g.Middleware` as you'd done with any middleware functions in go
```go
h := g.Middleware(myHandlerFunc)
```
It will create you a `http.Handler` that you can pass to a `http.ServerMux` or `http.Server` using `Handle` method