Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,8 @@ func TestEncodeComment(t *testing.T) {
buf := new(bytes.Buffer)
enc := NewEncoder(buf, false)
text := "This is a comment"
comm := comment{value: "This is a comment"}
expected := ":" + text + "\n"
if err := enc.Encode(comm); err != nil {
if err := enc.Encode(Comment(text)); err != nil {
t.Fatal(err)
}
if buf.String() != expected {
Expand Down
4 changes: 2 additions & 2 deletions encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ func (enc *Encoder) Encode(ec eventOrComment) error {
if _, err := io.WriteString(enc.w, "\n"); err != nil {
return fmt.Errorf("eventsource encode: %v", err)
}
case comment:
line := ":" + item.value + "\n"
case Comment:
line := ":" + string(item) + "\n"
if _, err := io.WriteString(enc.w, line); err != nil {
return fmt.Errorf("eventsource encode: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestEncoderMultiLineData(t *testing.T) {

func TestEncoderComment(t *testing.T) {
buf := bytes.NewBuffer(nil)
c := comment{value: "hello"}
c := Comment("hello")
NewEncoder(buf, false).Encode(c)
assert.Equal(t, ":hello\n", string(buf.Bytes()))
}
Expand Down
6 changes: 2 additions & 4 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ type unregistration struct {
forceDisconnect bool
}

type comment struct {
value string
}
type Comment string

type eventBatch struct {
events <-chan Event
Expand Down Expand Up @@ -246,7 +244,7 @@ func (srv *Server) PublishWithAcknowledgment(channels []string, ev Event) <-chan
func (srv *Server) PublishComment(channels []string, text string) {
srv.pub <- &outbound{
channels: channels,
eventOrComment: comment{value: text},
eventOrComment: Comment(text),
}
}

Expand Down