mirror of
https://gitlab.com/ric_harvey/MailHog.git
synced 2024-11-23 22:34:04 +00:00
Fix #18
This commit is contained in:
parent
309b4cde67
commit
d7093a57a7
2 changed files with 11 additions and 18 deletions
|
@ -11,18 +11,16 @@ import (
|
||||||
"github.com/ian-kent/go-log/log"
|
"github.com/ian-kent/go-log/log"
|
||||||
gotcha "github.com/ian-kent/gotcha/app"
|
gotcha "github.com/ian-kent/gotcha/app"
|
||||||
"github.com/ian-kent/gotcha/http"
|
"github.com/ian-kent/gotcha/http"
|
||||||
|
|
||||||
|
"github.com/ian-kent/goose"
|
||||||
)
|
)
|
||||||
|
|
||||||
type APIv1 struct {
|
type APIv1 struct {
|
||||||
config *config.Config
|
config *config.Config
|
||||||
eventlisteners []*EventListener
|
app *gotcha.App
|
||||||
app *gotcha.App
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type EventListener struct {
|
var stream *goose.EventStream
|
||||||
session *http.Session
|
|
||||||
ch chan []byte
|
|
||||||
}
|
|
||||||
|
|
||||||
type ReleaseConfig struct {
|
type ReleaseConfig struct {
|
||||||
Email string
|
Email string
|
||||||
|
@ -33,11 +31,11 @@ type ReleaseConfig struct {
|
||||||
func CreateAPIv1(conf *config.Config, app *gotcha.App) *APIv1 {
|
func CreateAPIv1(conf *config.Config, app *gotcha.App) *APIv1 {
|
||||||
log.Println("Creating API v1")
|
log.Println("Creating API v1")
|
||||||
apiv1 := &APIv1{
|
apiv1 := &APIv1{
|
||||||
config: conf,
|
config: conf,
|
||||||
eventlisteners: make([]*EventListener, 0),
|
app: app,
|
||||||
app: app,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stream = goose.NewEventStream()
|
||||||
r := app.Router
|
r := app.Router
|
||||||
|
|
||||||
r.Get("/api/v1/messages/?", apiv1.messages)
|
r.Get("/api/v1/messages/?", apiv1.messages)
|
||||||
|
@ -68,19 +66,13 @@ func CreateAPIv1(conf *config.Config, app *gotcha.App) *APIv1 {
|
||||||
func (apiv1 *APIv1) broadcast(json string) {
|
func (apiv1 *APIv1) broadcast(json string) {
|
||||||
log.Println("[APIv1] BROADCAST /api/v1/events")
|
log.Println("[APIv1] BROADCAST /api/v1/events")
|
||||||
b := []byte(json)
|
b := []byte(json)
|
||||||
for _, l := range apiv1.eventlisteners {
|
stream.Notify("data", b)
|
||||||
log.Printf("Sending to connection: %s\n", l.session.Request.RemoteAddr)
|
|
||||||
l.ch <- b
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (apiv1 *APIv1) eventstream(session *http.Session) {
|
func (apiv1 *APIv1) eventstream(session *http.Session) {
|
||||||
log.Println("[APIv1] GET /api/v1/events")
|
log.Println("[APIv1] GET /api/v1/events")
|
||||||
|
|
||||||
apiv1.eventlisteners = append(apiv1.eventlisteners, &EventListener{
|
stream.AddReceiver(session.Response.GetWriter())
|
||||||
session,
|
|
||||||
session.Response.EventStream(),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (apiv1 *APIv1) messages(session *http.Session) {
|
func (apiv1 *APIv1) messages(session *http.Session) {
|
||||||
|
|
1
Makefile
1
Makefile
|
@ -24,6 +24,7 @@ deps:
|
||||||
go get github.com/ian-kent/gotcha/gotcha
|
go get github.com/ian-kent/gotcha/gotcha
|
||||||
go get github.com/ian-kent/go-log/log
|
go get github.com/ian-kent/go-log/log
|
||||||
go get github.com/ian-kent/envconf
|
go get github.com/ian-kent/envconf
|
||||||
|
go get github.com/ian-kent/goose
|
||||||
go get github.com/jteeuwen/go-bindata/...
|
go get github.com/jteeuwen/go-bindata/...
|
||||||
go get labix.org/v2/mgo
|
go get labix.org/v2/mgo
|
||||||
# added to fix travis issues
|
# added to fix travis issues
|
||||||
|
|
Loading…
Reference in a new issue