Created
November 18, 2016 12:35
-
-
Save keks/0f2412fa616129cfc1af3ff011f67d7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package commands | |
// ... | |
func (cmd *Command) Call(r Request, w io.Writer) error { | |
// ... | |
res := NewResponse(r, w) // pass the writer | |
cmd.Run(...) | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package commands | |
// ... | |
type Request struct { | |
// ... | |
Mode() RequestMode // json, text, whatevs | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package commands | |
var PubsubSubCmd := &Command { | |
// ... | |
Run: func(req cmds.Request, res cmds.Response) { | |
m := FloodsubMarshaller(req.Mode(), res) // res is an io.Writer | |
sub := floodsub.Subscribe(req.GetArg("topic")) | |
f, isFlusher := res.(http.Flusher) | |
go func() { | |
if isFlusher { | |
f.Flush() | |
} | |
for { | |
msg := sub.Next() | |
m.Write(msg) | |
if isFlusher { | |
f.Flush() | |
} | |
} | |
}() | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment