https://github.com/varnishcache-friends/vago
Go bindings for the Varnish API
https://github.com/varnishcache-friends/vago
cgo go golang libvarnishapi vago varnish varnish-api
Last synced: 6 months ago
JSON representation
Go bindings for the Varnish API
- Host: GitHub
- URL: https://github.com/varnishcache-friends/vago
- Owner: varnishcache-friends
- License: bsd-2-clause
- Created: 2016-01-25T23:17:31.000Z (over 10 years ago)
- Default Branch: main
- Last Pushed: 2023-07-20T15:08:14.000Z (almost 3 years ago)
- Last Synced: 2024-12-06T20:12:45.155Z (over 1 year ago)
- Topics: cgo, go, golang, libvarnishapi, vago, varnish, varnish-api
- Language: Go
- Homepage:
- Size: 57.6 KB
- Stars: 30
- Watchers: 6
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# vago

[](https://pkg.go.dev/github.com/varnishcache-friends/vago)
Go bindings for Varnish 6.0, 7.2 and 7.3.
Older Varnish versions are not supported.
## Requirements
To build this package you will need:
* pkg-config
* libvarnishapi-dev
You will also need to set PKG_CONFIG_PATH to the directory where `varnishapi.pc`
is located before running `go get`. For example:
```
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
```
## Installation
```
go get github.com/varnishcache-friends/vago
```
## Examples
Same as running `varnishlog -g raw`:
```go
package main
import (
"fmt"
"log"
"github.com/varnishcache-friends/vago"
)
func main() {
// Open the default Varnish Shared Memory file
c := vago.Config{}
v, err := vago.Open(&c)
if err != nil {
log.Fatal(err)
}
v.Log("", vago.RAW, vago.COPT_TAIL|vago.COPT_BATCH, func(vxid uint32, tag, _type, data string) int {
fmt.Printf("%10d %-14s %s %s\n", vxid, tag, _type, data)
// -1 : Stop after it finds the first record
// >= 0 : Nothing to do but wait
return 0
})
v.Close()
}
```
Same for `varnishstat -1`:
```go
package main
import (
"fmt"
"log"
"github.com/varnishcache-friends/vago"
)
func main() {
// Open the default Varnish Shared Memory file
c := vago.Config{}
v, err := vago.Open(&c)
if err != nil {
log.Fatal(err)
}
stats := v.Stats()
for field, value := range stats {
fmt.Printf("%-35s\t%12d\n", field, value)
}
v.Close()
}
```