get rid of some old cruft that's already been moved

master
Jordan Orelli 4 years ago
parent 6859ca132d
commit d3b3f5788f

@ -1,13 +0,0 @@
package main
func errorResponse(re int, err error) response {
var body struct {
Message string `json:"message"`
}
body.Message = err.Error()
return response{
Re: re,
Type: "error",
Body: body,
}
}

@ -1,23 +0,0 @@
package main
import "encoding/json"
// requestBody is a container structure that contains the data of a user
// request. This is what clients serialize directly.
type requestBody struct {
// client-side sequence number. Clients are expected to send requests with
// a monotonically-incrementing sequence number.
Seq int `json:"seq"`
// command represents the command to be executed on the server. Command
// names are globally unique.
Command string `json:"cmd"`
// args are the arguments passed to the command for parameterized commands
// executed on the server.
Args map[string]json.RawMessage `json:"args"`
}
type request struct {
body requestBody
}

@ -1,14 +0,0 @@
package main
type response struct {
Re int `json:"re"`
Type string `json:"type"`
Body interface{} `json:"body,omitempty"`
}
func ok(re int) response {
return response{
Re: re,
Type: "ok",
}
}

@ -1,56 +0,0 @@
package main
import (
"context"
"encoding/json"
"time"
"github.com/gorilla/websocket"
"github.com/jordanorelli/blammo"
)
// session represents the server side of a client's session. i.e., a single
// connection along with its associated state.
type session struct {
*blammo.Log
id int
conn *websocket.Conn
outbox chan response
}
// pump is the session send loop. Pump should pump the session's outbox
// messages to the underlying connection until the context is closed.
func (sn *session) pump(ctx context.Context) {
for {
select {
case res := <-sn.outbox:
payload, err := json.Marshal(res)
if err != nil {
sn.Error("failed to marshal outgoing response: %v", err)
break
}
if err := sn.conn.SetWriteDeadline(time.Now().Add(3 * time.Second)); err != nil {
sn.Error("failed to set write deadline: %v", err)
break
}
w, err := sn.conn.NextWriter(websocket.TextMessage)
if err != nil {
sn.Error("failed get a writer frame: %v", err)
break
}
if _, err := w.Write(payload); err != nil {
sn.Error("failed write payload: %v", err)
break
}
if err := w.Close(); err != nil {
sn.Error("failed to close write frame: %v", err)
break
}
sn.Child("sent-frame").Info(string(payload))
case <-ctx.Done():
sn.Info("parent context done, shutting down write pump")
return
}
}
}
Loading…
Cancel
Save