good morning!!!!

Skip to content
Snippets Groups Projects
responsewriter.go 761 B
Newer Older
a's avatar
a committed
package server

import (
	"net/http"

	"gfx.cafe/open/jrpc/pkg/codec"
)

var _ codec.ResponseWriter = (*callRespWriter)(nil)

type callRespWriter struct {
	msg *codec.Message

	pkt *codec.Message

	dat    any
	skip   bool
	header http.Header

a's avatar
a  
a committed
	notifications func(env *notifyEnv) error
a's avatar
a committed
}

func (c *callRespWriter) Send(v any, err error) error {
	if err != nil {
		c.pkt.Error = err
		return nil
	}
	c.dat = v
	return nil
}

func (c *callRespWriter) SetExtraField(k string, v any) error {
	c.pkt.SetExtraField(k, v)
	return nil
}

func (c *callRespWriter) Header() http.Header {
	return c.header
}

func (c *callRespWriter) Notify(method string, v any) error {
a's avatar
a  
a committed
	return c.notifications(&notifyEnv{
a's avatar
a committed
		method: method,
		dat:    v,
		extra:  c.pkt.ExtraFields,
a's avatar
a  
a committed
	})
a's avatar
a committed
}