utils

package
v0.0.0-...-cd2be41 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LavalinkWebSocketEndpoint = "/websocket"
	LavalinkRestEndpoint      = "/v3/players"
)

API Endpoints

View Source
const (
	EventTypeTrackStart      = "TrackStartEvent"
	EventTypeTrackEnd        = "TrackEndEvent"
	EventTypeTrackException  = "TrackExceptionEvent"
	EventTypeTrackStuck      = "TrackStuckEvent"
	EventTypeWebSocketClosed = "WebSocketClosedEvent"
)

Event Types

View Source
const (
	DefaultReconnectDelay = 5 // seconds
	DefaultBufferSize     = 4096
	DefaultVolume         = 100
)

Default Values

View Source
const (
	ProtocolVersion = "1.0"
	UserAgent       = "liblavalink.go"
)

Other Constants

Variables

View Source
var (
	ErrNodeConnectionFailed = &LavalinkError{Code: 1001, Message: "Failed to connect to Lavalink node"}
	ErrWebSocketClosed      = &LavalinkError{Code: 1002, Message: "WebSocket connection closed unexpectedly"}
	ErrTrackNotFound        = &LavalinkError{Code: 1003, Message: "Track not found"}
	ErrInvalidRequest       = &LavalinkError{Code: 1004, Message: "Invalid request"}
	ErrPlaybackFailed       = &LavalinkError{Code: 1005, Message: "Playback failed"}
)

Functions

func ConnectWebSocket

func ConnectWebSocket(url string, headers http.Header) (*websocket.Conn, *http.Response, error)

WebSocket utility functions

func Error

func Error(message string)

func Errorf

func Errorf(format string, v ...interface{})

func FromJSON

func FromJSON(data string, v interface{}) error

func HandleError

func HandleError(err error)

func Info

func Info(message string)

func Infof

func Infof(format string, v ...interface{})

func MakeHTTPRequest

func MakeHTTPRequest(method, url string, headers map[string]string, body interface{}) (*http.Response, error)

MakeHTTPRequest makes an HTTP request with the specified method, URL, headers, and body.

func NewLavalinkError

func NewLavalinkError(code int, message string) error

Error handling functions

func ReadWebSocketMessage

func ReadWebSocketMessage(conn *websocket.Conn) (messageType int, message []byte, err error)

func Retry

func Retry(attempts int, sleep time.Duration, fn func() error) error

Retry logic

func ToJSON

func ToJSON(v interface{}) (string, error)

JSON utility functions

func WriteWebSocketMessage

func WriteWebSocketMessage(conn *websocket.Conn, messageType int, message []byte) error

Types

type LavalinkError

type LavalinkError struct {
	Code    int
	Message string
}

Custom error types

func (*LavalinkError) Error

func (e *LavalinkError) Error() string

Jump to

Keyboard shortcuts

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