vago

package module
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 1, 2019 License: BSD-2-Clause Imports: 7 Imported by: 0

README

Build Status

vago

Go bindings for Varnish 5.2.x using cgo.

For Varnish 4.1 refer to branch varnish-4.1.

Requirements

To build this package you will need:

  • pkg-config
  • libvarnishapi-dev >= 5.2.0

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/phenomenes/vago

Examples

Same as running varnishlog -g raw:

package main

import (
	"fmt"

	"github.com/phenomenes/vago"
)

func main() {
	// Open the default Varnish Shared Memory file
	c := vago.Config{}
	v, err := vago.Open(&c)
	if err != nil {
		fmt.Println(err)
		return
	}
	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:

package main

import (
	"fmt"

	"github.com/phenomenes/vago"
)

func main() {
	// Open the default Varnish Shared Memory file
	c := vago.Config{}
	v, err := vago.Open(&c)
	if err != nil {
		fmt.Println(err)
		return
	}
	stats := v.Stats()
	for field, value := range stats {
		fmt.Printf("%-35s\t%12d\n", field, value)
	}
	v.Close()
}

Documentation

Index

Constants

View Source
const (

	// Cursor options
	COPT_TAIL     = 1 << 0
	COPT_BATCH    = 1 << 1
	COPT_TAILSTOP = 1 << 2
)
View Source
const (
	// Grouping mode
	RAW  = C.VSL_g_raw
	VXID = C.VSL_g_vxid
	REQ  = C.VSL_g_request
	SESS = C.VSL_g_session
)
View Source
const (
	Yes tribool
	No
)

Variables

View Source
var (
	ErrAbandoned = errors.New("log abandoned")
	ErrOverrun   = errors.New("log overrun")
)

Functions

This section is empty.

Types

type Config added in v1.0.1

type Config struct {
	// Path to Varnish Shared Memory file
	Path string
	// VSM connection timeout in milliseconds
	// -1 for no timeout
	Timeout time.Duration
	// Whether to reacquire the to the log
	// Values can be Yes or No. Default Yes
	VslReattach tribool
}

Config parameters to connect to a Varnish instance.

type ErrVSL added in v1.0.1

type ErrVSL string

func (ErrVSL) Error added in v1.0.1

func (e ErrVSL) Error() string

type LogCallback

type LogCallback func(vxid uint32, tag, _type, data string) int

LogCallback defines a callback function. It's used by Log.

type Varnish

type Varnish struct {
	// contains filtered or unexported fields
}

A Varnish struct represents a handler for Varnish Shared Memory and Varnish Shared Log.

func Open

func Open(c *Config) (*Varnish, error)

Open opens a Varnish Shared Memory file. If successful, returns a new Varnish.

func (*Varnish) Close

func (v *Varnish) Close()

Close closes and unmaps the Varnish Shared Memory.

func (*Varnish) Log

func (v *Varnish) Log(query string, grouping uint32, copt uint, logCallback LogCallback) error

Log calls the given callback for any transactions matching the query and grouping.

func (*Varnish) Stat

func (v *Varnish) Stat(s string) (uint64, bool)

Stat takes a Varnish stat field and returns its value and true if found, 0 and false otherwise.

func (*Varnish) Stats

func (v *Varnish) Stats() map[string]uint64

Stats returns a map with all stat counters and their values.

func (*Varnish) Stop

func (v *Varnish) Stop()

Stop stops processing Varnish events.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL