avyos.dev/pkg/net

package net

Package Overview

No package-level documentation is provided.

Export GroupCount
Constants2
Variables0
Functions4
Types12

Constants

const (
	ConfigPath         = "/config/net.conf"
	DefaultDNSTimeout  = 5
	DefaultHTTPTimeout = 30
	DefaultUserAgent   = "AvyOS/1.0"
)
const (
	TypeA     uint16 = 1
	TypeAAAA  uint16 = 28
	TypeCNAME uint16 = 5
	TypeMX    uint16 = 15
	TypeTXT   uint16 = 16
	TypeNS    uint16 = 2

	ClassIN uint16 = 1
)

DNS record types

Functions

func Dial(network, address string) (net.Conn, error)

Dial connects to the address using the default dialer

func DialTLS(network, address string) (*tls.Conn, error)

DialTLS connects to the address over TLS using the default dialer

func DialTimeout(network, address string, timeout time.Duration) (net.Conn, error)

DialTimeout connects to the address with a custom timeout

func LookupHost(host string) ([]string, error)

LookupHost is a convenience function using the default resolver

Types

Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a custom HTTP client

Functions

func NewClient() *Client

NewClient creates a new HTTP client

Methods

func (c *Client) Do(req *Request) (*Response, error)

Do performs an HTTP request

func (c *Client) Get(url string) (*Response, error)

Get performs an HTTP GET request

func (c *Client) Post(url string, contentType string, body io.Reader) (*Response, error)

Post performs an HTTP POST request

Config

type Config struct {
	DNS  DNSConfig
	HTTP HTTPConfig
	TLS  TLSConfig
}

Config holds network configuration

Functions

func DefaultConfig() *Config

DefaultConfig returns the default network configuration

func GetConfig() *Config

GetConfig returns the current global configuration

func LoadConfig() (*Config, error)

LoadConfig loads network configuration from the config file

func ReloadConfig() (*Config, error)

ReloadConfig forces a reload of the configuration

DNSConfig

type DNSConfig struct {
	Servers []string
	Timeout int
	Cache   bool
}

DNSConfig holds DNS resolver configuration

DNSQuestion

type DNSQuestion struct {
	Name  string
	Type  uint16
	Class uint16
}

DNSQuestion represents a DNS question

DNSRecord

type DNSRecord struct {
	Name  string
	Type  uint16
	Class uint16
	TTL   uint32
	Data  string
}

DNSRecord represents a DNS record

DNSResponse

type DNSResponse struct {
	ID        uint16
	Questions []DNSQuestion
	Answers   []DNSRecord
	Authority []DNSRecord
	Extra     []DNSRecord
}

DNSResponse represents a DNS response

Dialer

type Dialer struct {
	Timeout  time.Duration
	Resolver *Resolver
	Config   *Config
	Pool     *x509.CertPool
}

Dialer provides custom connection dialing with AvyOS DNS resolution

Functions

func NewDialer() *Dialer

NewDialer creates a new Dialer with default configuration

Methods

func (d *Dialer) Dial(network, address string) (net.Conn, error)

Dial connects to the address using custom DNS resolution

func (d *Dialer) DialTLS(network, address string) (*tls.Conn, error)

DialTLS connects to the address over TLS using custom DNS resolution

HTTPConfig

type HTTPConfig struct {
	UserAgent       string
	Timeout         int
	FollowRedirects bool
	MaxRedirects    int
}

HTTPConfig holds HTTP client configuration

Request

type Request struct {
	Method  string
	URL     string
	Host    string
	Path    string
	Headers map[string]string
	Body    io.Reader
}

Request represents an HTTP request

Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver is a custom DNS resolver

Functions

func DefaultResolver() *Resolver

DefaultResolver returns the default DNS resolver

func NewResolver(servers []string, timeout time.Duration, enableCache bool) *Resolver

NewResolver creates a new DNS resolver

Methods

func (r *Resolver) LookupHost(host string) ([]string, error)

LookupHost resolves a hostname to IP addresses

func (r *Resolver) Query(name string, qtype uint16) ([]DNSRecord, error)

Query performs a DNS query

Response

type Response struct {
	StatusCode int
	Status     string
	Headers    map[string]string
	Body       io.ReadCloser
	Request    *Request
}

Response represents an HTTP response

Functions

func Get(url string) (*Response, error)

Get performs an HTTP GET request using the default client

func Post(url string, contentType string, body io.Reader) (*Response, error)

Post performs an HTTP POST request using the default client

TLSConfig

type TLSConfig struct {
	Verify        bool
	CertPath      string
	InsecureHosts []string
}

TLSConfig holds TLS configuration