mirror of
https://github.com/siderolabs/omni.git
synced 2025-08-06 01:27:02 +02:00
Fixes: https://github.com/siderolabs/omni/issues/858 Signed-off-by: Artem Chernyshev <artem.chernyshev@talos-systems.com>
50 lines
1.2 KiB
Go
50 lines
1.2 KiB
Go
// Copyright (c) 2025 Sidero Labs, Inc.
|
|
//
|
|
// Use of this software is governed by the Business Source License
|
|
// included in the LICENSE file.
|
|
|
|
// Package memconn provides a memory-based net.Conn implementation.
|
|
package memconn
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net"
|
|
|
|
"github.com/akutz/memconn"
|
|
)
|
|
|
|
// NewTransport creates a new transport.
|
|
func NewTransport(address string) *Transport {
|
|
return &Transport{address: address}
|
|
}
|
|
|
|
// Transport is transport for in-memory connection.
|
|
type Transport struct {
|
|
address string
|
|
}
|
|
|
|
// Listener creates new listener.
|
|
func (l *Transport) Listener() (net.Listener, error) {
|
|
if l.address == "" {
|
|
return nil, errors.New("address is not set")
|
|
}
|
|
|
|
return memconn.Listen("memu", l.address)
|
|
}
|
|
|
|
// DialContext creates a new connection.
|
|
func (l *Transport) DialContext(ctx context.Context) (net.Conn, error) {
|
|
if l.address == "" {
|
|
return nil, errors.New("address is not set")
|
|
}
|
|
|
|
return memconn.DialContext(ctx, "memu", l.address)
|
|
}
|
|
|
|
// Address returns the address. Since this is a memory-based connection, the address is always "passthrough:" + address,
|
|
// because the address is not a real network address and gRPC tries to resolve it otherwise.
|
|
func (l *Transport) Address() string {
|
|
return "passthrough:" + l.address
|
|
}
|