MCPcopy
hub / github.com/coder/websocket / publish

Method publish

internal/examples/chat/chat_test.go:203–220  ·  view source on GitHub ↗
(ctx context.Context, msg string)

Source from the content-addressed store, hash-verified

201}
202
203func (cl *client) publish(ctx context.Context, msg string) (err error) {
204 defer func() {
205 if err != nil {
206 cl.c.Close(websocket.StatusInternalError, "publish failed")
207 }
208 }()
209
210 req, _ := http.NewRequestWithContext(ctx, http.MethodPost, cl.url+"/publish", strings.NewReader(msg))
211 resp, err := http.DefaultClient.Do(req)
212 if err != nil {
213 return err
214 }
215 defer resp.Body.Close()
216 if resp.StatusCode != http.StatusAccepted {
217 return fmt.Errorf("publish request failed: %v", resp.StatusCode)
218 }
219 return nil
220}
221
222func (cl *client) publishMsgs(ctx context.Context, msgs map[string]struct{}) error {
223 for m := range msgs {

Callers 2

publishMsgsMethod · 0.95
Test_chatServerFunction · 0.45

Calls 1

CloseMethod · 0.45

Tested by

no test coverage detected