client-native
client-native copied to clipboard
Possible to use over tcp?
How can I interact with the runtime api over tcp?
I've created a fork https://github.com/theunknownport/client-native where I just override the net.DialTimeout Function
- if api, err = net.DialTimeout("unix", s.socketPath, taskTimeout); err != nil {
+ if api, err = net.DialTimeout("tcp", s.socketPath, taskTimeout); err != nil {
My haproxy config
global
stats socket [email protected]:9999 level admin
stats socket /var/run/haproxy-runtime-api.sock mode 666 level admin
stats timeout 2m
defaults
timeout connect 5s
timeout client 1m
timeout server 1m
listen stats
bind *:8080
mode http
stats enable
stats uri /stats
C:\Users\finnb\Downloads\socat-1.7.2.1>socat stdio tcp4-connect:127.0.0.1:9999
0 [main] socat 186416 find_fast_cwd: WARNING: Couldn't compute FAST_CWD pointer. Please report this problem to
the public mailing list [email protected]
show version
2.4.17-9f97155
My code to interact with the api
func ConnectHaProxy(ctx context.Context) (configuration.Configuration, error) {
confClient, _ := configuration.New(context.Background(),
cfg_opt.ConfigurationFile("/usr/local/etc/haproxy/haproxy.cfg"),
cfg_opt.UsePersistentTransactions,
cfg_opt.MasterWorker,
cfg_opt.UseMd5Hash,
)
// runtime
// import runtime_options "github.com/haproxytech/client-native/v4/runtime/options"
// or if not using master-worker
socketList := map[int]string{
1: "127.0.0.1:9999",
}
sockets := runtime_options.Sockets(socketList)
runtimeClient, _ := runtime_api.New(ctx, sockets)
// end runtime
// import "github.com/haproxytech/client-native/v4/options"
opt := []options.Option{
options.Configuration(confClient),
options.Runtime(runtimeClient),
}
// combine all together and create a client
client, err := client_native.New(ctx, opt...)
if err != nil {
log.Fatalf("Error initializing configuration client: %v", err)
}
c, err := client.Configuration()
if err != nil {
log.Fatalf("Error initializing configuration client: %v", err)
}
t, err := c.StartTransaction(1)
if err != nil {
log.Fatalf("Error initializing configuration client: %v", err)
}
c.IncrementVersion()
_, b, err := c.GetBackends(t.ID)
if err != nil {
log.Fatalf("Error initializing configuration client: %v", err)
}
fmt.Print(b)
// fetch configuration handler
return client.Configuration()
}
But when I run the code I always get option is not available
at client.Configuration()
.
Sorry if this issue seems annoying but I'm not so experience at coding in go yet, just started a month ago. I have my use case of interacting with the haproxy api via an external go program, maybe someone can help me with that.
Thanks in advance.