socket

package
v0.6.3 Latest Latest
Warning

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

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

Documentation

Overview

Package socket is a 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
}

Socket stores the socket information.

func New

func New(path string) *Socket

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

func (*Socket) Accept

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

Accept accepts a new connection. Returns a net.Conn.

func (*Socket) Close

func (s *Socket) Close() error

Close closes the socket and the connection.

func (*Socket) CloseConnection

func (s *Socket) CloseConnection() error

CloseConnection only closes the connection but not the socket.

func (*Socket) Connect

func (s *Socket) Connect() error

Connect connects to the socket. Returns a net.Conn.

func (*Socket) Create

func (s *Socket) Create() error

Create creates a socket.

func (*Socket) Exists

func (s *Socket) Exists() bool

Exists checks if the socket exists.

func (*Socket) Listen

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

Listen 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)

Reader returns a reader for the socket.

func (*Socket) Receive

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

Receive receives a message from the socket. Returns the message received.

func (*Socket) ReceiveJSON

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

ReceiveJSON receives and parses JSON from the socket. Returns an unmarshaled JSON object using the provided interface.

func (*Socket) Send

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

Send sends a message to the socket. Returns the amount of bytes sent.

func (*Socket) SendJSON

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

SendJSON sends JSON bytes to the socket. Returns the amount of bytes sent.

func (*Socket) Writer

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

Writer returns a writer for the socket.

Jump to

Keyboard shortcuts

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