• Stars
    star
    113
  • Rank 310,115 (Top 7 %)
  • Language
    Go
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Go client for HAProxy configuration and runtime API

HAProxy

HAProxy Native Golang Client

Contributors License

HAProxy Native Client is a client that exposes methods for reading and changing HAProxy configuration files, and executing commands and parsing the output of the HAProxy Runtime API (via unix socket, AKA stats socket in HAProxy).

HAProxy Models

This project contains structs and validation methods that are autogenerated using go-swagger from the swagger specification found here.These structs are also used in the DataPlaneAPI

Requirements

go-swagger v0.30.2. Note that at the moment you need to use version 0.30.2

models can be generated with make models. It automatically combines specification parts into a single file, and then use that to generate models.

Usage Example

//import cfg_opt "github.com/haproxytech/client-native/v5/configuration/options"
confClient, err := configuration.New(context.Background(),
    cfg_opt.ConfigurationFile(haproxyOptions.ConfigFile),
    cfg_opt.HAProxyBin(haproxyOptions.HAProxy),
    cfg_opt.Backups(haproxyOptions.BackupsNumber),
    cfg_opt.UsePersistentTransactions,
    cfg_opt.TransactionsDir(haproxyOptions.TransactionDir),
    cfg_opt.MasterWorker,
    cfg_opt.UseMd5Hash,
)
if err != nil {
    return nil, fmt.Errorf("error setting up configuration client: %s", err.Error())
}

// runtime
// import runtime_options "github.com/haproxytech/client-native/v5/runtime/options"
nbproc := 8
ms := runtime_options.MasterSocket(masterSocket, nbproc)
runtimeClient, err = runtime_api.New(ctx, ms)
if err != nil {
    return nil, fmt.Errorf("error setting up runtime client: %s", err.Error())
}
// or if not using master-worker
socketList := map[int]string{
    1: "/var/run/haproxy.sock"
}
sockets := runtime_options.Sockets(socketList)
runtimeClient, err = runtime_api.New(ctx, mapsDir, sockets)
if err != nil {
    return nil, fmt.Errorf("error setting up runtime client: %s", err.Error())
}
// end runtime

// import "github.com/haproxytech/client-native/v5/options"
opt := []options.Option{
    options.Configuration(confClient),
    options.Runtime(runtimeClient),
}

// additional options - not mandatory

//maps storage
mapStorage, err := storage.New(MapsDir, storage.MapsType)
if err != nil {
    log.Fatalf("error initializing map storage: %v", err)
}
opt = append(opt, options.MapStorage(mapStorage))

//ssl cert storage
sslCertStorage, err := storage.New(SSLCertsDir, storage.SSLType)
if err != nil {
    log.Fatalf("error initializing SSL certs storage: %v", err)
}
opt = append(opt, options.SSLCertStorage(sslCertStorage))

// general storage
generalStorage, err := storage.New(GeneralStorage, storage.GeneralType)
if err != nil {
    log.Fatalf("error initializing General storage: %v", err)
}
opt = append(opt, options.GeneralStorage(generalStorage))

//spoe
prms := spoe.Params{
    SpoeDir:        SpoeDir,
    TransactionDir: SpoeTransactionDir,
}
spoe, err := spoe.NewSpoe(prms)
if err != nil {
    log.Fatalf("error setting up spoe: %v", err)
}
opt = append(opt, options.Spoe(spoe))

// combine all together and create a client
client, err := client_native.New(cyx, opt...)
if err != nil {
    log.Fatalf("Error initializing configuration client: %v", err)
}

// fetch configuration handler
configuration, err := client.Configuration()
if err != nil {
    fmt.Println(err.Error())
}

//fetch all backends
bcks, err := configuration.GetBackends(t)
if err != nil {
    fmt.Println(err.Error())
}
//...

backendsJSON, err := bcks.MarshallBinary()

if err != nil {
    fmt.Println(err.Error())
}

fmt.Println(string(backendsJSON))
//...

Contributing

For commit messages and general style please follow the haproxy project's CONTRIBUTING guide and use that where applicable.

More Repositories

1

kubernetes-ingress

HAProxy Kubernetes Ingress Controller
Go
712
star
2

dataplaneapi

HAProxy Data Plane API
Go
296
star
3

helm-charts

Helm chart for HAProxy Kubernetes Ingress Controller
Mustache
138
star
4

haproxy

HAProxy related stuff: scripts, configs, etc...
Shell
119
star
5

haproxy-lua-acme

Lua
104
star
6

haproxy-lua-oauth

JWT Validation implementation for HAProxy Lua host
Lua
103
star
7

haproxy-consul-connect

HaProxy Connector for Consul Connect. Enables Service Mesh with Consul and HaProxy using TLS and Consul Discovery
Go
93
star
8

config-parser

HAProxy configuration parser
Go
82
star
9

haproxy-lua-http

Simple Lua HTTP helper && client for use with HAProxy.
Lua
54
star
10

vmware-haproxy

Python
52
star
11

haproxy-lua-cors

Lua library for enabling CORS in HAProxy
Lua
43
star
12

spoa-mirror

Mirror HTTP requests using the HAProxy SPOP
C
40
star
13

haproxy-docker-ubuntu

HAProxy CE Docker Ubuntu image
Dockerfile
38
star
14

ingress-controller-benchmarks

Shell
34
star
15

haproxy-docker-alpine

HAProxy CE Docker Alpine image
Dockerfile
29
star
16

cloud-blueprints

Cloud HAPEE integration blueprints
Python
29
star
17

ultimate-configs

23
star
18

spoa-opentracing

C
20
star
19

haproxy-spoa-dotnet

HAProxy Stream Processing Offload Agent (SPOA) library for .NET Core.
C#
15
star
20

haproxy-docker-alpine-quic

HAProxy CE Docker Alpine image with QUIC (quictls)
Dockerfile
12
star
21

haproxy-docker-debian

HAProxy CE Docker Debian image
Dockerfile
11
star
22

models

HAProxy Go structs for API
10
star
23

openshift-haproxy

HAProxy OpenShift Docker image
Makefile
9
star
24

dataplaneapi-specification

HAProxy Data Plane API specification
Go
9
star
25

opentracing-c-wrapper

C
6
star
26

haproxy-dev-lua-filters

Lua filters support for HAProxy (based on the internal filters API)
C
5
star
27

github-actions

HAProxy Github Actions
Go
4
star
28

quic-dev

QUIC support for HAProxy.
C
4
star
29

haproxy-dev-dns

dns loadbalancing and dns over TCP support
C
3
star
30

go-logger

Go package that provides interface for logging
Go
3
star
31

haproxy-consul-connect-docker

Docker repository for HAProxy Connect, service mesh with Consul Connect and HAProxy
Shell
3
star
32

haproxy-qns

Dockerfile
1
star
33

bench-algo-p2c

Benchmark code for the Power-of-two-choices (p2c) algorithm
Python
1
star
34

go-linter

Linter for Go projects
Dockerfile
1
star
35

haproxy-pygments-lexer

Python
1
star
36

spoa-mod_defender

Example of a simple wrapper around the mod_defender WAF for use with HAProxy's SPOE filtering
C
1
star
37

haproxy-docker-debian-quic

HAProxy CE Docker Debian image with QUIC (quictls)
Dockerfile
1
star
38

hcl-converter

Go
1
star