haproxyconfigparser

package module
v0.0.0-...-414f9db Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2019 License: MIT Imports: 7 Imported by: 0

README

haproxyconfigparser

CircleCI Go Report Card

HAProxy config parser for Golang, but under development.

Behavior

  • It parses HAProxy config and binds to golang struct.
  • Analysis ACL, make its reference beteen frontend and backends.

Usage

main.go

package main

import (
	"fmt"
	"github.com/tkmgo/haproxyconfigparser"
)

func main() {
	config, _ := haproxyconfigparser.ParseFromStdin()
	fmt.Println(config)
}
$ cat haproxy.cfg | go run main.go

Documentation

Overview

Package for parsing a HAproxy config file into a structured form. You might also use it to convert the file into a general JSON format.

Limitation: There is currently no way of writing the structure in HAproxy config file format.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseSockAddr

func ParseSockAddr(path string) (string, string)

func RegisterEvent

func RegisterEvent(group string, name string, emitter EmitEvent)

Registers an event listener to the event store.

The group is any of "global", "backend", "frontend" or "*" where the asterisk means any.

The name is the name is the first item on the line (i.e "bind", "acl", "use_backend" etc)

Example
RegisterEvent("backend", "*", func(eventType EventType, line string, parser Parser) {
	if eventType == START_SECTION {
		fmt.Printf("EventType=%s, line=%s\n", eventType, line)
	}
})

_, err := ParseFromFile("testdata/haproxy.cfg")
if err != nil {
	fmt.Printf("Failed to parse data: %s", err)
}
Output:

EventType=start_section, line=backend profileEditingService_20000
EventType=start_section, line=backend accountCreationService_10000

func SeparateConfigLine

func SeparateConfigLine(line string) ([]string, bool)

func SeparateHostAndPort

func SeparateHostAndPort(address string) (string, int, error)

func Uncomment

func Uncomment(line string) (string, bool)

Types

type Acl

type Acl struct {
	Name      string   `json:"name"`
	Type      string   `json:"type"`
	Condition []string `json:"condition"`
}

func (Acl) Hash

func (u Acl) Hash() (uint64, error)

type Backend

type Backend struct {
	Name        string     `json:"name"`
	Mode        string     `json:"mode"`
	Balance     string     `json:"balance"`
	HttpRequest []string   `json:"http-request"`
	Options     [][]string `json:"options"`
	Servers     []*Server  `json:"servers"`
}

func (Backend) Hash

func (u Backend) Hash() (uint64, error)

type BackendParser

type BackendParser struct {
	Backend Backend
}

func NewBackendParser

func NewBackendParser(name string) *BackendParser

func (*BackendParser) Install

func (self *BackendParser) Install(s *Services)

func (*BackendParser) Name

func (self *BackendParser) Name() string

func (*BackendParser) Parse

func (self *BackendParser) Parse(node string, options []string, enable bool) error

type Bind

type Bind struct {
	Host string `json:"host"`
	Port int    `json:"port"`
}

func (Bind) Hash

func (u Bind) Hash() (uint64, error)

type EmitEvent

type EmitEvent func(eventType EventType, line string, parser Parser)

type EventType

type EventType string
const (
	EMPTY_LINE    EventType = "empty"
	COMMENT_OUT   EventType = "comment_out"
	START_SECTION EventType = "start_section"
	IN_SECTION    EventType = "in_section"
	NORMAL        EventType = "normal"
	UNKNOWN       EventType = "unknown"
)

type Frontend

type Frontend struct {
	Name           string        `json:"name"`
	Mode           string        `json:"mode"`
	Maxconn        int           `json:"maxconn"`
	Bind           Bind          `json:"bind"`
	Acls           []*Acl        `json:"acls"`
	UseBackends    []*UseBackend `json:"use_backends"`
	DefaultBackend string        `json:"default_backend"`
}

func (Frontend) Hash

func (u Frontend) Hash() (uint64, error)

type FrontendParser

type FrontendParser struct {
	Frontend Frontend
}

func NewFrontendParser

func NewFrontendParser(name string) *FrontendParser

func (*FrontendParser) Install

func (self *FrontendParser) Install(s *Services)

func (*FrontendParser) Name

func (self *FrontendParser) Name() string

func (*FrontendParser) Parse

func (self *FrontendParser) Parse(node string, options []string, enable bool) error

type Global

type Global struct {
	Stats   []*Socket `json:"stats"`
	Daemon  bool      `json:"daemon"`
	User    string    `json:"user"`
	Group   string    `json:"group"`
	Maxconn int       `json:"maxconn"`
}

func (Global) Hash

func (u Global) Hash() (uint64, error)

type GlobalParser

type GlobalParser struct {
	Global Global
}

The following keywords are supported in the "global" section :

  • Process management and security

  • chroot

  • daemon

  • gid

  • group

  • log

  • log-send-hostname

  • nbproc

  • pidfile

  • uid

  • ulimit-n

  • user

  • stats

  • node

  • description

  • Performance tuning

  • maxconn

  • maxpipes

  • noepoll

  • nokqueue

  • nopoll

  • nosepoll

  • nosplice

  • spread-checks

  • tune.bufsize

  • tune.chksize

  • tune.maxaccept

  • tune.maxpollevents

  • tune.maxrewrite

  • tune.rcvbuf.client

  • tune.rcvbuf.server

  • tune.sndbuf.client

  • tune.sndbuf.server

  • Debugging

  • debug

  • quiet

func NewGlobalParser

func NewGlobalParser() *GlobalParser

func (*GlobalParser) Install

func (self *GlobalParser) Install(s *Services)

func (*GlobalParser) Name

func (self *GlobalParser) Name() string

func (*GlobalParser) Parse

func (self *GlobalParser) Parse(node string, options []string, enable bool) error

type NilParser

type NilParser struct {
	Section string
}

func NewNilParser

func NewNilParser(section string) *NilParser

func (*NilParser) Install

func (self *NilParser) Install(s *Services)

func (*NilParser) Name

func (self *NilParser) Name() string

func (*NilParser) Parse

func (self *NilParser) Parse(node string, options []string, enable bool) error

type Parser

type Parser interface {
	Parse(node string, options []string, enable bool) error
	Install(s *Services)
	Name() string
}

type Server

type Server struct {
	Label   string   `json:"label"`
	Host    string   `json:"host"`
	Port    int      `json:"port"`
	Options []string `json:"options"`
	Enabled bool     `json:"enabled"`
}

func (Server) Hash

func (u Server) Hash() (uint64, error)

type Services

type Services struct {
	Global    Global     `json:"global"`
	Frontends []Frontend `json:"frontends"`
	Backends  []Backend  `json:"backends"`
}

func NewServices

func NewServices() *Services

func Parse

func Parse(config []string) (*Services, error)

func ParseFromFile

func ParseFromFile(path string) (*Services, error)

func ParseFromStdin

func ParseFromStdin() (*Services, error)

func (Services) Hash

func (u Services) Hash() (uint64, error)

type Socket

type Socket struct {
	Type string
	Addr string
}

func (Socket) Hash

func (u Socket) Hash() (uint64, error)

type UseBackend

type UseBackend struct {
	Name      string             `json:"name"`
	Condition *UseBackendClauses `json:"clauses"`
	Backend   *Backend           `json:"backend"`
	Acls      []*Acl             `json:"acls"`
}

func (UseBackend) Hash

func (u UseBackend) Hash() (uint64, error)

type UseBackendClauses

type UseBackendClauses struct {
	ReverseJudge bool       `json:"reserve_judge"`
	Any          [][]string `json:"any"`
}

func CreateUseBackendClauses

func CreateUseBackendClauses(judge string, source []string) (*UseBackendClauses, error)

func (UseBackendClauses) Hash

func (u UseBackendClauses) Hash() (uint64, error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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