32 lines
782 B
Go
32 lines
782 B
Go
package payment
|
|
|
|
import (
|
|
"net"
|
|
"net/url"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// PaymentClient holds connection data
|
|
type PaymentClient struct {
|
|
Addr string // e.g., "127.0.0.1:1869"
|
|
}
|
|
|
|
func InitializeConnection(paymentrUrl string) (net.Conn, error) {
|
|
const funcName = "InitializeServerConnection"
|
|
// Parse the URL to extract host and port
|
|
parsedUrl, err := url.Parse(paymentrUrl)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("[%s] failed to parse LockserverUrl: %v", funcName, err)
|
|
}
|
|
|
|
// Remove any leading/trailing slashes just in case
|
|
address := strings.Trim(parsedUrl.Host, "/")
|
|
|
|
// Establish a TCP connection to the Visionline server
|
|
conn, err := net.Dial("tcp", address)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("failed to connect to payment server: %v", err)
|
|
}
|
|
return conn, nil
|
|
} |