Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to use over tcp? #89

Open
theunknownport opened this issue Jul 25, 2022 · 0 comments
Open

Possible to use over tcp? #89

theunknownport opened this issue Jul 25, 2022 · 0 comments

Comments

@theunknownport
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant