Categorygithub.com/charliego3/websocket
modulepackage
1.2.1
Repository: https://github.com/charliego3/websocket.git
Documentation: pkg.go.dev

# README

websocket

This is a golang websocket client easy to use

Usage

import (
	"context"
	"io"

	logger "github.com/charmbracelet/log"
)

type Receiver struct {
	*logger.Logger
}

func (r *Receiver) OnReceive(frame *Frame) {
	bs, err := io.ReadAll(frame.Reader)
	if err != nil {
		r.Error("读取消息失败!", "err", err)
		return
	}
	r.Infof("收到消息: %s", bs)
}

// SetLogger is a Optional func with Processor
func (r *Receiver) SetLogger(l *logger.Logger) {
	r.Logger = l
}

type Message struct {
	*JsonMessage
	Name string
}

func main() {
	ctx := context.Background()
	client := NewClient(ctx, "ws://121.40.165.18:8800", &Receiver{}, WithPing(NewStringMessage("ping")))
	err := client.Connect()
	if err != nil {
		logger.Fatal(err)
	}

	client.Subscribe(&Message{
		Name: "Joe",
	})

	<-make(chan struct{})
}

# Functions

No description provided by the author
No description provided by the author
No description provided by the author
EventString retrieves an enum value from the enum constants string name.
EventStrings returns a slice of all String values of the enum.
EventValues returns all values of the enum.
FrameTypeString retrieves an enum value from the enum constants string name.
FrameTypeStrings returns a slice of all String values of the enum.
FrameTypeValues returns all values of the enum.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
StatusString retrieves an enum value from the enum constants string name.
StatusStrings returns a slice of all String values of the enum.
StatusValues returns all values of the enum.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
WithLogger custom specify logger instance.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
unused.
unused.
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
No description provided by the author
No description provided by the author
go:generate enumer -type Event -text -values -json -trimprefix Event -output event_string.go.
go:generate enumer -type FrameType -text -values -json -trimprefix FrameType -output types_string.go.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
go:generate enumer -type Status -text -values -trimprefix Status -output status_string.go.