socket

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Wrapper around net package to make it convinient to use for UNIX domain sockets.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Socket

type Socket struct {
	Path       string
	Listener   net.Listener
	Connection net.Conn
}

func New

func New(path string) *Socket

Returns a new socket instance. To create the socker use the Create method.

func (*Socket) Accept

func (s *Socket) Accept() (net.Conn, error)

Accepts a new connection. Returns a net.Conn.

func (*Socket) Close

func (s *Socket) Close() error

Closes the socket.

func (*Socket) CloseConnection

func (s *Socket) CloseConnection() error

Only closes the connection.

func (*Socket) Connect

func (s *Socket) Connect() error

Connects to the socket. Returns a net.Conn.

func (*Socket) Create

func (s *Socket) Create() error

Creates a socket.

func (*Socket) Exists

func (s *Socket) Exists() bool

Checks if the socket exists.

func (*Socket) Listen

func (s *Socket) Listen(cb func())

Waits for a connection. When a connection is made, it will run the callback function with the connection as argument.

func (*Socket) Reader

func (s *Socket) Reader() (io.Reader, error)

Returns a reader for the socket.

func (*Socket) Receive

func (s *Socket) Receive() ([]byte, error)

Receives a message from the socket. Returns the message received.

func (*Socket) ReceiveJSON

func (s *Socket) ReceiveJSON(v any) error

Receives JSON from the socket. Returns an unmarshaled JSON object using the provided interface.

func (*Socket) Send

func (s *Socket) Send(msg string) (int, error)

Sends a message to the socket. Returns the amount of bytes sent.

func (*Socket) SendJSON

func (s *Socket) SendJSON(v any) (int, error)

Sends JSON to the socket. Returns the amount of bytes sent.

func (*Socket) Writer

func (s *Socket) Writer() (io.Writer, error)

Returns a writer for the socket.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL