diff --git a/.gitignore b/.gitignore index 52aeb50..dc71557 100644 --- a/.gitignore +++ b/.gitignore @@ -26,8 +26,12 @@ _testmain.go *.swo # our binaries +/client +/client.exe /inbucket /inbucket.exe /dist/** /cmd/client/client /cmd/client/client.exe +/cmd/inbucket/inbucket +/cmd/inbucket/inbucket.exe diff --git a/Makefile b/Makefile index 8101866..ae01ee8 100644 --- a/Makefile +++ b/Makefile @@ -1,26 +1,27 @@ -PKG := inbucket -SHELL := /bin/sh +SHELL = /bin/sh -SRC := $(shell find . -type f -name '*.go' -not -path "./vendor/*") -PKGS := $$(go list ./... | grep -v /vendor/) +SRC ::= $(shell find . -type f -name '*.go' -not -path "./vendor/*") +PKGS ::= $(shell go list ./... | grep -v /vendor/) -.PHONY: all build clean fmt install lint simplify test +.PHONY: all build clean fmt lint simplify test -all: test lint build +commands ::= client inbucket + +all: clean test lint build + +$(commands): %: cmd/% + go build ./$< clean: - go clean + go clean $(PKGS) + rm -f $(commands) deps: go get -t ./... -build: clean deps - go build +build: deps $(commands) -install: build - go install - -test: clean deps +test: deps go test -race ./... fmt: @@ -31,5 +32,5 @@ simplify: lint: @test -z "$(shell gofmt -l . | tee /dev/stderr)" || echo "[WARN] Fix formatting issues with 'make fmt'" - @golint -set_exit_status $${PKGS} - @go vet $${PKGS} + @golint -set_exit_status $(PKGS) + @go vet $(PKGS) diff --git a/cmd/client/list.go b/cmd/client/list.go index eda64bb..82f69d8 100644 --- a/cmd/client/list.go +++ b/cmd/client/list.go @@ -6,7 +6,7 @@ import ( "fmt" "github.com/google/subcommands" - "github.com/jhillyerd/inbucket/rest/client" + "github.com/jhillyerd/inbucket/pkg/rest/client" ) type listCmd struct { diff --git a/cmd/client/match.go b/cmd/client/match.go index df49a87..21a4ad0 100644 --- a/cmd/client/match.go +++ b/cmd/client/match.go @@ -10,7 +10,7 @@ import ( "time" "github.com/google/subcommands" - "github.com/jhillyerd/inbucket/rest/client" + "github.com/jhillyerd/inbucket/pkg/rest/client" ) type matchCmd struct { diff --git a/cmd/client/mbox.go b/cmd/client/mbox.go index cf2b46e..2105d24 100644 --- a/cmd/client/mbox.go +++ b/cmd/client/mbox.go @@ -7,7 +7,7 @@ import ( "os" "github.com/google/subcommands" - "github.com/jhillyerd/inbucket/rest/client" + "github.com/jhillyerd/inbucket/pkg/rest/client" ) type mboxCmd struct { diff --git a/inbucket.go b/cmd/inbucket/main.go similarity index 83% rename from inbucket.go rename to cmd/inbucket/main.go index 23c646a..0886a71 100644 --- a/inbucket.go +++ b/cmd/inbucket/main.go @@ -12,15 +12,15 @@ import ( "syscall" "time" - "github.com/jhillyerd/inbucket/config" - "github.com/jhillyerd/inbucket/filestore" - "github.com/jhillyerd/inbucket/httpd" - "github.com/jhillyerd/inbucket/log" - "github.com/jhillyerd/inbucket/msghub" - "github.com/jhillyerd/inbucket/pop3d" - "github.com/jhillyerd/inbucket/rest" - "github.com/jhillyerd/inbucket/smtpd" - "github.com/jhillyerd/inbucket/webui" + "github.com/jhillyerd/inbucket/pkg/config" + "github.com/jhillyerd/inbucket/pkg/log" + "github.com/jhillyerd/inbucket/pkg/msghub" + "github.com/jhillyerd/inbucket/pkg/rest" + "github.com/jhillyerd/inbucket/pkg/server/pop3" + "github.com/jhillyerd/inbucket/pkg/server/smtp" + "github.com/jhillyerd/inbucket/pkg/server/web" + "github.com/jhillyerd/inbucket/pkg/storage/file" + "github.com/jhillyerd/inbucket/pkg/webui" ) var ( @@ -39,8 +39,8 @@ var ( shutdownChan = make(chan bool) // Server instances - smtpServer *smtpd.Server - pop3Server *pop3d.Server + smtpServer *smtp.Server + pop3Server *pop3.Server ) func init() { @@ -119,17 +119,17 @@ func main() { ds := filestore.DefaultFileDataStore() // Start HTTP server - httpd.Initialize(config.GetWebConfig(), shutdownChan, ds, msgHub) - webui.SetupRoutes(httpd.Router) - rest.SetupRoutes(httpd.Router) - go httpd.Start(rootCtx) + web.Initialize(config.GetWebConfig(), shutdownChan, ds, msgHub) + webui.SetupRoutes(web.Router) + rest.SetupRoutes(web.Router) + go web.Start(rootCtx) // Start POP3 server - pop3Server = pop3d.New(config.GetPOP3Config(), shutdownChan, ds) + pop3Server = pop3.New(config.GetPOP3Config(), shutdownChan, ds) go pop3Server.Start(rootCtx) // Startup SMTP server - smtpServer = smtpd.NewServer(config.GetSMTPConfig(), shutdownChan, ds, msgHub) + smtpServer = smtp.NewServer(config.GetSMTPConfig(), shutdownChan, ds, msgHub) go smtpServer.Start(rootCtx) // Loop forever waiting for signals or shutdown channel diff --git a/config/config.go b/pkg/config/config.go similarity index 100% rename from config/config.go rename to pkg/config/config.go diff --git a/log/logging.go b/pkg/log/logging.go similarity index 100% rename from log/logging.go rename to pkg/log/logging.go diff --git a/log/metrics.go b/pkg/log/metrics.go similarity index 100% rename from log/metrics.go rename to pkg/log/metrics.go diff --git a/log/stdout_unix.go b/pkg/log/stdout_unix.go similarity index 100% rename from log/stdout_unix.go rename to pkg/log/stdout_unix.go diff --git a/log/stdout_windows.go b/pkg/log/stdout_windows.go similarity index 100% rename from log/stdout_windows.go rename to pkg/log/stdout_windows.go diff --git a/msghub/hub.go b/pkg/msghub/hub.go similarity index 100% rename from msghub/hub.go rename to pkg/msghub/hub.go diff --git a/msghub/hub_test.go b/pkg/msghub/hub_test.go similarity index 100% rename from msghub/hub_test.go rename to pkg/msghub/hub_test.go diff --git a/rest/apiv1_controller.go b/pkg/rest/apiv1_controller.go similarity index 91% rename from rest/apiv1_controller.go rename to pkg/rest/apiv1_controller.go index 9037eb1..abd9b0b 100644 --- a/rest/apiv1_controller.go +++ b/pkg/rest/apiv1_controller.go @@ -10,15 +10,15 @@ import ( "io/ioutil" "strconv" - "github.com/jhillyerd/inbucket/datastore" - "github.com/jhillyerd/inbucket/httpd" - "github.com/jhillyerd/inbucket/log" - "github.com/jhillyerd/inbucket/rest/model" - "github.com/jhillyerd/inbucket/stringutil" + "github.com/jhillyerd/inbucket/pkg/log" + "github.com/jhillyerd/inbucket/pkg/rest/model" + "github.com/jhillyerd/inbucket/pkg/server/web" + "github.com/jhillyerd/inbucket/pkg/storage" + "github.com/jhillyerd/inbucket/pkg/stringutil" ) // MailboxListV1 renders a list of messages in a mailbox -func MailboxListV1(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) { +func MailboxListV1(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { // Don't have to validate these aren't empty, Gorilla returns 404 name, err := stringutil.ParseMailboxName(ctx.Vars["name"]) if err != nil { @@ -48,11 +48,11 @@ func MailboxListV1(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) Size: msg.Size(), } } - return httpd.RenderJSON(w, jmessages) + return web.RenderJSON(w, jmessages) } // MailboxShowV1 renders a particular message from a mailbox -func MailboxShowV1(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) { +func MailboxShowV1(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { // Don't have to validate these aren't empty, Gorilla returns 404 id := ctx.Vars["id"] name, err := stringutil.ParseMailboxName(ctx.Vars["name"]) @@ -96,7 +96,7 @@ func MailboxShowV1(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) } } - return httpd.RenderJSON(w, + return web.RenderJSON(w, &model.JSONMessageV1{ Mailbox: name, ID: msg.ID(), @@ -115,7 +115,7 @@ func MailboxShowV1(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) } // MailboxPurgeV1 deletes all messages from a mailbox -func MailboxPurgeV1(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) { +func MailboxPurgeV1(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { // Don't have to validate these aren't empty, Gorilla returns 404 name, err := stringutil.ParseMailboxName(ctx.Vars["name"]) if err != nil { @@ -133,11 +133,11 @@ func MailboxPurgeV1(w http.ResponseWriter, req *http.Request, ctx *httpd.Context } log.Tracef("HTTP purged mailbox for %q", name) - return httpd.RenderJSON(w, "OK") + return web.RenderJSON(w, "OK") } // MailboxSourceV1 displays the raw source of a message, including headers. Renders text/plain -func MailboxSourceV1(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) { +func MailboxSourceV1(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { // Don't have to validate these aren't empty, Gorilla returns 404 id := ctx.Vars["id"] name, err := stringutil.ParseMailboxName(ctx.Vars["name"]) @@ -171,7 +171,7 @@ func MailboxSourceV1(w http.ResponseWriter, req *http.Request, ctx *httpd.Contex } // MailboxDeleteV1 removes a particular message from a mailbox -func MailboxDeleteV1(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) { +func MailboxDeleteV1(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { // Don't have to validate these aren't empty, Gorilla returns 404 id := ctx.Vars["id"] name, err := stringutil.ParseMailboxName(ctx.Vars["name"]) @@ -197,5 +197,5 @@ func MailboxDeleteV1(w http.ResponseWriter, req *http.Request, ctx *httpd.Contex return fmt.Errorf("Delete(%q) failed: %v", id, err) } - return httpd.RenderJSON(w, "OK") + return web.RenderJSON(w, "OK") } diff --git a/rest/apiv1_controller_test.go b/pkg/rest/apiv1_controller_test.go similarity index 99% rename from rest/apiv1_controller_test.go rename to pkg/rest/apiv1_controller_test.go index b1c9a00..7f5aba7 100644 --- a/rest/apiv1_controller_test.go +++ b/pkg/rest/apiv1_controller_test.go @@ -9,7 +9,7 @@ import ( "testing" "time" - "github.com/jhillyerd/inbucket/datastore" + "github.com/jhillyerd/inbucket/pkg/storage" ) const ( diff --git a/rest/client/apiv1_client.go b/pkg/rest/client/apiv1_client.go similarity index 98% rename from rest/client/apiv1_client.go rename to pkg/rest/client/apiv1_client.go index d75bfa3..ad62dcb 100644 --- a/rest/client/apiv1_client.go +++ b/pkg/rest/client/apiv1_client.go @@ -8,7 +8,7 @@ import ( "net/url" "time" - "github.com/jhillyerd/inbucket/rest/model" + "github.com/jhillyerd/inbucket/pkg/rest/model" ) // Client accesses the Inbucket REST API v1 diff --git a/rest/client/apiv1_client_test.go b/pkg/rest/client/apiv1_client_test.go similarity index 100% rename from rest/client/apiv1_client_test.go rename to pkg/rest/client/apiv1_client_test.go diff --git a/rest/client/rest.go b/pkg/rest/client/rest.go similarity index 100% rename from rest/client/rest.go rename to pkg/rest/client/rest.go diff --git a/rest/client/rest_test.go b/pkg/rest/client/rest_test.go similarity index 100% rename from rest/client/rest_test.go rename to pkg/rest/client/rest_test.go diff --git a/rest/model/apiv1_model.go b/pkg/rest/model/apiv1_model.go similarity index 100% rename from rest/model/apiv1_model.go rename to pkg/rest/model/apiv1_model.go diff --git a/pkg/rest/routes.go b/pkg/rest/routes.go new file mode 100644 index 0000000..fad722d --- /dev/null +++ b/pkg/rest/routes.go @@ -0,0 +1,23 @@ +package rest + +import "github.com/gorilla/mux" +import "github.com/jhillyerd/inbucket/pkg/server/web" + +// SetupRoutes populates the routes for the REST interface +func SetupRoutes(r *mux.Router) { + // API v1 + r.Path("/api/v1/mailbox/{name}").Handler( + web.Handler(MailboxListV1)).Name("MailboxListV1").Methods("GET") + r.Path("/api/v1/mailbox/{name}").Handler( + web.Handler(MailboxPurgeV1)).Name("MailboxPurgeV1").Methods("DELETE") + r.Path("/api/v1/mailbox/{name}/{id}").Handler( + web.Handler(MailboxShowV1)).Name("MailboxShowV1").Methods("GET") + r.Path("/api/v1/mailbox/{name}/{id}").Handler( + web.Handler(MailboxDeleteV1)).Name("MailboxDeleteV1").Methods("DELETE") + r.Path("/api/v1/mailbox/{name}/{id}/source").Handler( + web.Handler(MailboxSourceV1)).Name("MailboxSourceV1").Methods("GET") + r.Path("/api/v1/monitor/messages").Handler( + web.Handler(MonitorAllMessagesV1)).Name("MonitorAllMessagesV1").Methods("GET") + r.Path("/api/v1/monitor/messages/{name}").Handler( + web.Handler(MonitorMailboxMessagesV1)).Name("MonitorMailboxMessagesV1").Methods("GET") +} diff --git a/rest/socketv1_controller.go b/pkg/rest/socketv1_controller.go similarity index 88% rename from rest/socketv1_controller.go rename to pkg/rest/socketv1_controller.go index 78bec2d..8bbf5a9 100644 --- a/rest/socketv1_controller.go +++ b/pkg/rest/socketv1_controller.go @@ -5,11 +5,11 @@ import ( "time" "github.com/gorilla/websocket" - "github.com/jhillyerd/inbucket/httpd" - "github.com/jhillyerd/inbucket/log" - "github.com/jhillyerd/inbucket/msghub" - "github.com/jhillyerd/inbucket/rest/model" - "github.com/jhillyerd/inbucket/stringutil" + "github.com/jhillyerd/inbucket/pkg/log" + "github.com/jhillyerd/inbucket/pkg/msghub" + "github.com/jhillyerd/inbucket/pkg/rest/model" + "github.com/jhillyerd/inbucket/pkg/server/web" + "github.com/jhillyerd/inbucket/pkg/stringutil" ) const ( @@ -145,16 +145,16 @@ func (ml *msgListener) Close() { } func MonitorAllMessagesV1( - w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) { + w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { // Upgrade to Websocket conn, err := upgrader.Upgrade(w, req, nil) if err != nil { return err } - httpd.ExpWebSocketConnectsCurrent.Add(1) + web.ExpWebSocketConnectsCurrent.Add(1) defer func() { _ = conn.Close() - httpd.ExpWebSocketConnectsCurrent.Add(-1) + web.ExpWebSocketConnectsCurrent.Add(-1) }() log.Tracef("HTTP[%v] Upgraded to websocket", req.RemoteAddr) @@ -168,7 +168,7 @@ func MonitorAllMessagesV1( } func MonitorMailboxMessagesV1( - w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) { + w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { name, err := stringutil.ParseMailboxName(ctx.Vars["name"]) if err != nil { return err @@ -178,10 +178,10 @@ func MonitorMailboxMessagesV1( if err != nil { return err } - httpd.ExpWebSocketConnectsCurrent.Add(1) + web.ExpWebSocketConnectsCurrent.Add(1) defer func() { _ = conn.Close() - httpd.ExpWebSocketConnectsCurrent.Add(-1) + web.ExpWebSocketConnectsCurrent.Add(-1) }() log.Tracef("HTTP[%v] Upgraded to websocket", req.RemoteAddr) diff --git a/rest/testutils_test.go b/pkg/rest/testutils_test.go similarity index 95% rename from rest/testutils_test.go rename to pkg/rest/testutils_test.go index 6ef4182..7955828 100644 --- a/rest/testutils_test.go +++ b/pkg/rest/testutils_test.go @@ -10,10 +10,10 @@ import ( "time" "github.com/jhillyerd/enmime" - "github.com/jhillyerd/inbucket/config" - "github.com/jhillyerd/inbucket/datastore" - "github.com/jhillyerd/inbucket/httpd" - "github.com/jhillyerd/inbucket/msghub" + "github.com/jhillyerd/inbucket/pkg/config" + "github.com/jhillyerd/inbucket/pkg/msghub" + "github.com/jhillyerd/inbucket/pkg/server/web" + "github.com/jhillyerd/inbucket/pkg/storage" ) type InputMessageData struct { @@ -184,7 +184,7 @@ func testRestGet(url string) (*httptest.ResponseRecorder, error) { } w := httptest.NewRecorder() - httpd.Router.ServeHTTP(w, req) + web.Router.ServeHTTP(w, req) return w, nil } @@ -200,8 +200,8 @@ func setupWebServer(ds datastore.DataStore) *bytes.Buffer { PublicDir: "../themes/bootstrap/public", } shutdownChan := make(chan bool) - httpd.Initialize(cfg, shutdownChan, ds, &msghub.Hub{}) - SetupRoutes(httpd.Router) + web.Initialize(cfg, shutdownChan, ds, &msghub.Hub{}) + SetupRoutes(web.Router) return buf } diff --git a/pop3d/handler.go b/pkg/server/pop3/handler.go similarity index 99% rename from pop3d/handler.go rename to pkg/server/pop3/handler.go index 7f5967e..7922ca2 100644 --- a/pop3d/handler.go +++ b/pkg/server/pop3/handler.go @@ -1,4 +1,4 @@ -package pop3d +package pop3 import ( "bufio" @@ -11,8 +11,8 @@ import ( "strings" "time" - "github.com/jhillyerd/inbucket/datastore" - "github.com/jhillyerd/inbucket/log" + "github.com/jhillyerd/inbucket/pkg/log" + "github.com/jhillyerd/inbucket/pkg/storage" ) // State tracks the current mode of our POP3 state machine diff --git a/pop3d/listener.go b/pkg/server/pop3/listener.go similarity index 95% rename from pop3d/listener.go rename to pkg/server/pop3/listener.go index 58b0d82..42aaa56 100644 --- a/pop3d/listener.go +++ b/pkg/server/pop3/listener.go @@ -1,4 +1,4 @@ -package pop3d +package pop3 import ( "context" @@ -7,9 +7,9 @@ import ( "sync" "time" - "github.com/jhillyerd/inbucket/config" - "github.com/jhillyerd/inbucket/datastore" - "github.com/jhillyerd/inbucket/log" + "github.com/jhillyerd/inbucket/pkg/config" + "github.com/jhillyerd/inbucket/pkg/log" + "github.com/jhillyerd/inbucket/pkg/storage" ) // Server defines an instance of our POP3 server diff --git a/smtpd/handler.go b/pkg/server/smtp/handler.go similarity index 98% rename from smtpd/handler.go rename to pkg/server/smtp/handler.go index cbae977..96646b1 100644 --- a/smtpd/handler.go +++ b/pkg/server/smtp/handler.go @@ -1,4 +1,4 @@ -package smtpd +package smtp import ( "bufio" @@ -12,10 +12,10 @@ import ( "strings" "time" - "github.com/jhillyerd/inbucket/datastore" - "github.com/jhillyerd/inbucket/log" - "github.com/jhillyerd/inbucket/msghub" - "github.com/jhillyerd/inbucket/stringutil" + "github.com/jhillyerd/inbucket/pkg/log" + "github.com/jhillyerd/inbucket/pkg/msghub" + "github.com/jhillyerd/inbucket/pkg/storage" + "github.com/jhillyerd/inbucket/pkg/stringutil" ) // State tracks the current mode of our SMTP state machine diff --git a/smtpd/handler_test.go b/pkg/server/smtp/handler_test.go similarity index 98% rename from smtpd/handler_test.go rename to pkg/server/smtp/handler_test.go index e541f4e..c1e6168 100644 --- a/smtpd/handler_test.go +++ b/pkg/server/smtp/handler_test.go @@ -1,4 +1,4 @@ -package smtpd +package smtp import ( "bytes" @@ -13,9 +13,9 @@ import ( "testing" "time" - "github.com/jhillyerd/inbucket/config" - "github.com/jhillyerd/inbucket/datastore" - "github.com/jhillyerd/inbucket/msghub" + "github.com/jhillyerd/inbucket/pkg/config" + "github.com/jhillyerd/inbucket/pkg/msghub" + "github.com/jhillyerd/inbucket/pkg/storage" ) type scriptStep struct { diff --git a/smtpd/listener.go b/pkg/server/smtp/listener.go similarity index 96% rename from smtpd/listener.go rename to pkg/server/smtp/listener.go index 60953b6..986d112 100644 --- a/smtpd/listener.go +++ b/pkg/server/smtp/listener.go @@ -1,4 +1,4 @@ -package smtpd +package smtp import ( "container/list" @@ -10,10 +10,10 @@ import ( "sync" "time" - "github.com/jhillyerd/inbucket/config" - "github.com/jhillyerd/inbucket/datastore" - "github.com/jhillyerd/inbucket/log" - "github.com/jhillyerd/inbucket/msghub" + "github.com/jhillyerd/inbucket/pkg/config" + "github.com/jhillyerd/inbucket/pkg/log" + "github.com/jhillyerd/inbucket/pkg/msghub" + "github.com/jhillyerd/inbucket/pkg/storage" ) func init() { diff --git a/httpd/context.go b/pkg/server/web/context.go similarity index 90% rename from httpd/context.go rename to pkg/server/web/context.go index 6a54541..01d6c85 100644 --- a/httpd/context.go +++ b/pkg/server/web/context.go @@ -1,4 +1,4 @@ -package httpd +package web import ( "net/http" @@ -6,9 +6,9 @@ import ( "github.com/gorilla/mux" "github.com/gorilla/sessions" - "github.com/jhillyerd/inbucket/config" - "github.com/jhillyerd/inbucket/datastore" - "github.com/jhillyerd/inbucket/msghub" + "github.com/jhillyerd/inbucket/pkg/config" + "github.com/jhillyerd/inbucket/pkg/msghub" + "github.com/jhillyerd/inbucket/pkg/storage" ) // Context is passed into every request handler function diff --git a/httpd/helpers.go b/pkg/server/web/helpers.go similarity index 97% rename from httpd/helpers.go rename to pkg/server/web/helpers.go index a5f66c6..c41e1e6 100644 --- a/httpd/helpers.go +++ b/pkg/server/web/helpers.go @@ -1,4 +1,4 @@ -package httpd +package web import ( "fmt" @@ -8,7 +8,7 @@ import ( "strings" "time" - "github.com/jhillyerd/inbucket/log" + "github.com/jhillyerd/inbucket/pkg/log" ) // TemplateFuncs declares functions made available to all templates (including partials) diff --git a/httpd/helpers_test.go b/pkg/server/web/helpers_test.go similarity index 98% rename from httpd/helpers_test.go rename to pkg/server/web/helpers_test.go index fe0ca5c..39dc6eb 100644 --- a/httpd/helpers_test.go +++ b/pkg/server/web/helpers_test.go @@ -1,4 +1,4 @@ -package httpd +package web import ( "html/template" diff --git a/httpd/rest.go b/pkg/server/web/rest.go similarity index 96% rename from httpd/rest.go rename to pkg/server/web/rest.go index 805bbc9..aa9d864 100644 --- a/httpd/rest.go +++ b/pkg/server/web/rest.go @@ -1,4 +1,4 @@ -package httpd +package web import ( "encoding/json" diff --git a/httpd/server.go b/pkg/server/web/server.go similarity index 93% rename from httpd/server.go rename to pkg/server/web/server.go index f89b9ff..a9cd22a 100644 --- a/httpd/server.go +++ b/pkg/server/web/server.go @@ -1,5 +1,5 @@ -// Package httpd provides the plumbing for Inbucket's web GUI and RESTful API -package httpd +// Package web provides the plumbing for Inbucket's web GUI and RESTful API +package web import ( "context" @@ -12,10 +12,10 @@ import ( "github.com/gorilla/mux" "github.com/gorilla/securecookie" "github.com/gorilla/sessions" - "github.com/jhillyerd/inbucket/config" - "github.com/jhillyerd/inbucket/datastore" - "github.com/jhillyerd/inbucket/log" - "github.com/jhillyerd/inbucket/msghub" + "github.com/jhillyerd/inbucket/pkg/config" + "github.com/jhillyerd/inbucket/pkg/log" + "github.com/jhillyerd/inbucket/pkg/msghub" + "github.com/jhillyerd/inbucket/pkg/storage" ) // Handler is a function type that handles an HTTP request in Inbucket diff --git a/httpd/template.go b/pkg/server/web/template.go similarity index 97% rename from httpd/template.go rename to pkg/server/web/template.go index 3aa81ce..216a1a4 100644 --- a/httpd/template.go +++ b/pkg/server/web/template.go @@ -1,4 +1,4 @@ -package httpd +package web import ( "html/template" @@ -8,7 +8,7 @@ import ( "strings" "sync" - "github.com/jhillyerd/inbucket/log" + "github.com/jhillyerd/inbucket/pkg/log" ) var cachedMutex sync.Mutex diff --git a/datastore/datastore.go b/pkg/storage/datastore.go similarity index 100% rename from datastore/datastore.go rename to pkg/storage/datastore.go diff --git a/filestore/fmessage.go b/pkg/storage/file/fmessage.go similarity index 98% rename from filestore/fmessage.go rename to pkg/storage/file/fmessage.go index 54da127..8d0fa3d 100644 --- a/filestore/fmessage.go +++ b/pkg/storage/file/fmessage.go @@ -11,8 +11,8 @@ import ( "time" "github.com/jhillyerd/enmime" - "github.com/jhillyerd/inbucket/datastore" - "github.com/jhillyerd/inbucket/log" + "github.com/jhillyerd/inbucket/pkg/storage" + "github.com/jhillyerd/inbucket/pkg/log" ) // FileMessage implements Message and contains a little bit of data about a diff --git a/filestore/fstore.go b/pkg/storage/file/fstore.go similarity index 98% rename from filestore/fstore.go rename to pkg/storage/file/fstore.go index 7b15f27..98341d0 100644 --- a/filestore/fstore.go +++ b/pkg/storage/file/fstore.go @@ -11,10 +11,10 @@ import ( "sync" "time" - "github.com/jhillyerd/inbucket/config" - "github.com/jhillyerd/inbucket/datastore" - "github.com/jhillyerd/inbucket/log" - "github.com/jhillyerd/inbucket/stringutil" + "github.com/jhillyerd/inbucket/pkg/config" + "github.com/jhillyerd/inbucket/pkg/storage" + "github.com/jhillyerd/inbucket/pkg/log" + "github.com/jhillyerd/inbucket/pkg/stringutil" ) // Name of index file in each mailbox diff --git a/filestore/fstore_test.go b/pkg/storage/file/fstore_test.go similarity index 99% rename from filestore/fstore_test.go rename to pkg/storage/file/fstore_test.go index 9cac985..b9fd41c 100644 --- a/filestore/fstore_test.go +++ b/pkg/storage/file/fstore_test.go @@ -11,7 +11,7 @@ import ( "testing" "time" - "github.com/jhillyerd/inbucket/config" + "github.com/jhillyerd/inbucket/pkg/config" "github.com/stretchr/testify/assert" ) diff --git a/datastore/lock.go b/pkg/storage/lock.go similarity index 100% rename from datastore/lock.go rename to pkg/storage/lock.go diff --git a/datastore/lock_test.go b/pkg/storage/lock_test.go similarity index 96% rename from datastore/lock_test.go rename to pkg/storage/lock_test.go index 2da536a..203ebf1 100644 --- a/datastore/lock_test.go +++ b/pkg/storage/lock_test.go @@ -3,7 +3,7 @@ package datastore_test import ( "testing" - "github.com/jhillyerd/inbucket/datastore" + "github.com/jhillyerd/inbucket/pkg/storage" ) func TestHashLock(t *testing.T) { diff --git a/datastore/retention.go b/pkg/storage/retention.go similarity index 98% rename from datastore/retention.go rename to pkg/storage/retention.go index 7d52c27..ef3154b 100644 --- a/datastore/retention.go +++ b/pkg/storage/retention.go @@ -6,8 +6,8 @@ import ( "sync" "time" - "github.com/jhillyerd/inbucket/config" - "github.com/jhillyerd/inbucket/log" + "github.com/jhillyerd/inbucket/pkg/config" + "github.com/jhillyerd/inbucket/pkg/log" ) var ( diff --git a/datastore/retention_test.go b/pkg/storage/retention_test.go similarity index 100% rename from datastore/retention_test.go rename to pkg/storage/retention_test.go diff --git a/datastore/testing.go b/pkg/storage/testing.go similarity index 100% rename from datastore/testing.go rename to pkg/storage/testing.go diff --git a/stringutil/utils.go b/pkg/stringutil/utils.go similarity index 100% rename from stringutil/utils.go rename to pkg/stringutil/utils.go diff --git a/stringutil/utils_test.go b/pkg/stringutil/utils_test.go similarity index 100% rename from stringutil/utils_test.go rename to pkg/stringutil/utils_test.go diff --git a/webui/mailbox_controller.go b/pkg/webui/mailbox_controller.go similarity index 84% rename from webui/mailbox_controller.go rename to pkg/webui/mailbox_controller.go index 7f2d6e8..bc2ef77 100644 --- a/webui/mailbox_controller.go +++ b/pkg/webui/mailbox_controller.go @@ -7,29 +7,29 @@ import ( "net/http" "strconv" - "github.com/jhillyerd/inbucket/datastore" - "github.com/jhillyerd/inbucket/httpd" - "github.com/jhillyerd/inbucket/log" - "github.com/jhillyerd/inbucket/sanitize" - "github.com/jhillyerd/inbucket/stringutil" + "github.com/jhillyerd/inbucket/pkg/log" + "github.com/jhillyerd/inbucket/pkg/server/web" + "github.com/jhillyerd/inbucket/pkg/storage" + "github.com/jhillyerd/inbucket/pkg/stringutil" + "github.com/jhillyerd/inbucket/pkg/webui/sanitize" ) // MailboxIndex renders the index page for a particular mailbox -func MailboxIndex(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) { +func MailboxIndex(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { // Form values must be validated manually name := req.FormValue("name") selected := req.FormValue("id") if len(name) == 0 { ctx.Session.AddFlash("Account name is required", "errors") _ = ctx.Session.Save(req, w) - http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther) + http.Redirect(w, req, web.Reverse("RootIndex"), http.StatusSeeOther) return nil } name, err = stringutil.ParseMailboxName(name) if err != nil { ctx.Session.AddFlash(err.Error(), "errors") _ = ctx.Session.Save(req, w) - http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther) + http.Redirect(w, req, web.Reverse("RootIndex"), http.StatusSeeOther) return nil } // Remember this mailbox was visited @@ -40,7 +40,7 @@ func MailboxIndex(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) return err } // Render template - return httpd.RenderTemplate("mailbox/index.html", w, map[string]interface{}{ + return web.RenderTemplate("mailbox/index.html", w, map[string]interface{}{ "ctx": ctx, "errorFlash": errorFlash, "name": name, @@ -49,24 +49,24 @@ func MailboxIndex(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) } // MailboxLink handles pretty links to a particular message. Renders a redirect -func MailboxLink(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) { +func MailboxLink(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { // Don't have to validate these aren't empty, Gorilla returns 404 id := ctx.Vars["id"] name, err := stringutil.ParseMailboxName(ctx.Vars["name"]) if err != nil { ctx.Session.AddFlash(err.Error(), "errors") _ = ctx.Session.Save(req, w) - http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther) + http.Redirect(w, req, web.Reverse("RootIndex"), http.StatusSeeOther) return nil } // Build redirect - uri := fmt.Sprintf("%s?name=%s&id=%s", httpd.Reverse("MailboxIndex"), name, id) + uri := fmt.Sprintf("%s?name=%s&id=%s", web.Reverse("MailboxIndex"), name, id) http.Redirect(w, req, uri, http.StatusSeeOther) return nil } // MailboxList renders a list of messages in a mailbox. Renders a partial -func MailboxList(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) { +func MailboxList(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { // Don't have to validate these aren't empty, Gorilla returns 404 name, err := stringutil.ParseMailboxName(ctx.Vars["name"]) if err != nil { @@ -84,7 +84,7 @@ func MailboxList(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) ( } log.Tracef("Got %v messsages", len(messages)) // Render partial template - return httpd.RenderPartial("mailbox/_list.html", w, map[string]interface{}{ + return web.RenderPartial("mailbox/_list.html", w, map[string]interface{}{ "ctx": ctx, "name": name, "messages": messages, @@ -92,7 +92,7 @@ func MailboxList(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) ( } // MailboxShow renders a particular message from a mailbox. Renders an HTML partial -func MailboxShow(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) { +func MailboxShow(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { // Don't have to validate these aren't empty, Gorilla returns 404 id := ctx.Vars["id"] name, err := stringutil.ParseMailboxName(ctx.Vars["name"]) @@ -117,7 +117,7 @@ func MailboxShow(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) ( if err != nil { return fmt.Errorf("ReadBody(%q) failed: %v", id, err) } - body := template.HTML(httpd.TextToHTML(mime.Text)) + body := template.HTML(web.TextToHTML(mime.Text)) htmlAvailable := mime.HTML != "" var htmlBody template.HTML if htmlAvailable { @@ -128,7 +128,7 @@ func MailboxShow(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) ( } } // Render partial template - return httpd.RenderPartial("mailbox/_show.html", w, map[string]interface{}{ + return web.RenderPartial("mailbox/_show.html", w, map[string]interface{}{ "ctx": ctx, "name": name, "message": msg, @@ -141,7 +141,7 @@ func MailboxShow(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) ( } // MailboxHTML displays the HTML content of a message. Renders a partial -func MailboxHTML(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) { +func MailboxHTML(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { // Don't have to validate these aren't empty, Gorilla returns 404 id := ctx.Vars["id"] name, err := stringutil.ParseMailboxName(ctx.Vars["name"]) @@ -168,7 +168,7 @@ func MailboxHTML(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) ( } // Render partial template w.Header().Set("Content-Type", "text/html; charset=UTF-8") - return httpd.RenderPartial("mailbox/_html.html", w, map[string]interface{}{ + return web.RenderPartial("mailbox/_html.html", w, map[string]interface{}{ "ctx": ctx, "name": name, "message": message, @@ -178,7 +178,7 @@ func MailboxHTML(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) ( } // MailboxSource displays the raw source of a message, including headers. Renders text/plain -func MailboxSource(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) { +func MailboxSource(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { // Don't have to validate these aren't empty, Gorilla returns 404 id := ctx.Vars["id"] name, err := stringutil.ParseMailboxName(ctx.Vars["name"]) @@ -213,14 +213,14 @@ func MailboxSource(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) // MailboxDownloadAttach sends the attachment to the client; disposition: // attachment, type: application/octet-stream -func MailboxDownloadAttach(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) { +func MailboxDownloadAttach(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { // Don't have to validate these aren't empty, Gorilla returns 404 id := ctx.Vars["id"] name, err := stringutil.ParseMailboxName(ctx.Vars["name"]) if err != nil { ctx.Session.AddFlash(err.Error(), "errors") _ = ctx.Session.Save(req, w) - http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther) + http.Redirect(w, req, web.Reverse("RootIndex"), http.StatusSeeOther) return nil } numStr := ctx.Vars["num"] @@ -228,7 +228,7 @@ func MailboxDownloadAttach(w http.ResponseWriter, req *http.Request, ctx *httpd. if err != nil { ctx.Session.AddFlash("Attachment number must be unsigned numeric", "errors") _ = ctx.Session.Save(req, w) - http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther) + http.Redirect(w, req, web.Reverse("RootIndex"), http.StatusSeeOther) return nil } mb, err := ctx.DataStore.MailboxFor(name) @@ -252,7 +252,7 @@ func MailboxDownloadAttach(w http.ResponseWriter, req *http.Request, ctx *httpd. if int(num) >= len(body.Attachments) { ctx.Session.AddFlash("Attachment number too high", "errors") _ = ctx.Session.Save(req, w) - http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther) + http.Redirect(w, req, web.Reverse("RootIndex"), http.StatusSeeOther) return nil } part := body.Attachments[num] @@ -266,13 +266,13 @@ func MailboxDownloadAttach(w http.ResponseWriter, req *http.Request, ctx *httpd. } // MailboxViewAttach sends the attachment to the client for online viewing -func MailboxViewAttach(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) { +func MailboxViewAttach(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { // Don't have to validate these aren't empty, Gorilla returns 404 name, err := stringutil.ParseMailboxName(ctx.Vars["name"]) if err != nil { ctx.Session.AddFlash(err.Error(), "errors") _ = ctx.Session.Save(req, w) - http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther) + http.Redirect(w, req, web.Reverse("RootIndex"), http.StatusSeeOther) return nil } id := ctx.Vars["id"] @@ -281,7 +281,7 @@ func MailboxViewAttach(w http.ResponseWriter, req *http.Request, ctx *httpd.Cont if err != nil { ctx.Session.AddFlash("Attachment number must be unsigned numeric", "errors") _ = ctx.Session.Save(req, w) - http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther) + http.Redirect(w, req, web.Reverse("RootIndex"), http.StatusSeeOther) return nil } mb, err := ctx.DataStore.MailboxFor(name) @@ -305,7 +305,7 @@ func MailboxViewAttach(w http.ResponseWriter, req *http.Request, ctx *httpd.Cont if int(num) >= len(body.Attachments) { ctx.Session.AddFlash("Attachment number too high", "errors") _ = ctx.Session.Save(req, w) - http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther) + http.Redirect(w, req, web.Reverse("RootIndex"), http.StatusSeeOther) return nil } part := body.Attachments[num] diff --git a/webui/recent.go b/pkg/webui/recent.go similarity index 83% rename from webui/recent.go rename to pkg/webui/recent.go index 14118ac..97168d3 100644 --- a/webui/recent.go +++ b/pkg/webui/recent.go @@ -1,7 +1,7 @@ package webui import ( - "github.com/jhillyerd/inbucket/httpd" + "github.com/jhillyerd/inbucket/pkg/server/web" ) const ( @@ -12,7 +12,7 @@ const ( ) // RememberMailbox manages the list of recently accessed mailboxes stored in the session -func RememberMailbox(ctx *httpd.Context, mailbox string) { +func RememberMailbox(ctx *web.Context, mailbox string) { recent := RecentMailboxes(ctx) newRecent := make([]string, 1, maxRemembered) newRecent[0] = mailbox @@ -28,7 +28,7 @@ func RememberMailbox(ctx *httpd.Context, mailbox string) { } // RecentMailboxes returns a slice of the most recently accessed mailboxes -func RecentMailboxes(ctx *httpd.Context) []string { +func RecentMailboxes(ctx *web.Context) []string { val := ctx.Session.Values[mailboxKey] recent, _ := val.([]string) return recent diff --git a/webui/root_controller.go b/pkg/webui/root_controller.go similarity index 75% rename from webui/root_controller.go rename to pkg/webui/root_controller.go index 9a64bc5..85d1662 100644 --- a/webui/root_controller.go +++ b/pkg/webui/root_controller.go @@ -6,13 +6,13 @@ import ( "io/ioutil" "net/http" - "github.com/jhillyerd/inbucket/config" - "github.com/jhillyerd/inbucket/httpd" - "github.com/jhillyerd/inbucket/stringutil" + "github.com/jhillyerd/inbucket/pkg/config" + "github.com/jhillyerd/inbucket/pkg/server/web" + "github.com/jhillyerd/inbucket/pkg/stringutil" ) // RootIndex serves the Inbucket landing page -func RootIndex(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) { +func RootIndex(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { greeting, err := ioutil.ReadFile(config.GetWebConfig().GreetingFile) if err != nil { return fmt.Errorf("Failed to load greeting: %v", err) @@ -23,7 +23,7 @@ func RootIndex(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (er return err } // Render template - return httpd.RenderTemplate("root/index.html", w, map[string]interface{}{ + return web.RenderTemplate("root/index.html", w, map[string]interface{}{ "ctx": ctx, "errorFlash": errorFlash, "greeting": template.HTML(string(greeting)), @@ -31,11 +31,11 @@ func RootIndex(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (er } // RootMonitor serves the Inbucket monitor page -func RootMonitor(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) { +func RootMonitor(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { if !config.GetWebConfig().MonitorVisible { ctx.Session.AddFlash("Monitor is disabled in configuration", "errors") _ = ctx.Session.Save(req, w) - http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther) + http.Redirect(w, req, web.Reverse("RootIndex"), http.StatusSeeOther) return nil } // Get flash messages, save session @@ -44,25 +44,25 @@ func RootMonitor(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) ( return err } // Render template - return httpd.RenderTemplate("root/monitor.html", w, map[string]interface{}{ + return web.RenderTemplate("root/monitor.html", w, map[string]interface{}{ "ctx": ctx, "errorFlash": errorFlash, }) } // RootMonitorMailbox serves the Inbucket monitor page for a particular mailbox -func RootMonitorMailbox(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) { +func RootMonitorMailbox(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { if !config.GetWebConfig().MonitorVisible { ctx.Session.AddFlash("Monitor is disabled in configuration", "errors") _ = ctx.Session.Save(req, w) - http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther) + http.Redirect(w, req, web.Reverse("RootIndex"), http.StatusSeeOther) return nil } name, err := stringutil.ParseMailboxName(ctx.Vars["name"]) if err != nil { ctx.Session.AddFlash(err.Error(), "errors") _ = ctx.Session.Save(req, w) - http.Redirect(w, req, httpd.Reverse("RootIndex"), http.StatusSeeOther) + http.Redirect(w, req, web.Reverse("RootIndex"), http.StatusSeeOther) return nil } // Get flash messages, save session @@ -71,7 +71,7 @@ func RootMonitorMailbox(w http.ResponseWriter, req *http.Request, ctx *httpd.Con return err } // Render template - return httpd.RenderTemplate("root/monitor.html", w, map[string]interface{}{ + return web.RenderTemplate("root/monitor.html", w, map[string]interface{}{ "ctx": ctx, "errorFlash": errorFlash, "name": name, @@ -79,7 +79,7 @@ func RootMonitorMailbox(w http.ResponseWriter, req *http.Request, ctx *httpd.Con } // RootStatus serves the Inbucket status page -func RootStatus(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (err error) { +func RootStatus(w http.ResponseWriter, req *http.Request, ctx *web.Context) (err error) { smtpListener := fmt.Sprintf("%s:%d", config.GetSMTPConfig().IP4address.String(), config.GetSMTPConfig().IP4port) pop3Listener := fmt.Sprintf("%s:%d", config.GetPOP3Config().IP4address.String(), @@ -92,7 +92,7 @@ func RootStatus(w http.ResponseWriter, req *http.Request, ctx *httpd.Context) (e return err } // Render template - return httpd.RenderTemplate("root/status.html", w, map[string]interface{}{ + return web.RenderTemplate("root/status.html", w, map[string]interface{}{ "ctx": ctx, "errorFlash": errorFlash, "version": config.Version, diff --git a/pkg/webui/routes.go b/pkg/webui/routes.go new file mode 100644 index 0000000..1bbe888 --- /dev/null +++ b/pkg/webui/routes.go @@ -0,0 +1,35 @@ +// Package webui powers Inbucket's web GUI +package webui + +import ( + "github.com/gorilla/mux" + "github.com/jhillyerd/inbucket/pkg/server/web" +) + +// SetupRoutes populates routes for the webui into the provided Router +func SetupRoutes(r *mux.Router) { + r.Path("/").Handler( + web.Handler(RootIndex)).Name("RootIndex").Methods("GET") + r.Path("/monitor").Handler( + web.Handler(RootMonitor)).Name("RootMonitor").Methods("GET") + r.Path("/monitor/{name}").Handler( + web.Handler(RootMonitorMailbox)).Name("RootMonitorMailbox").Methods("GET") + r.Path("/status").Handler( + web.Handler(RootStatus)).Name("RootStatus").Methods("GET") + r.Path("/link/{name}/{id}").Handler( + web.Handler(MailboxLink)).Name("MailboxLink").Methods("GET") + r.Path("/mailbox").Handler( + web.Handler(MailboxIndex)).Name("MailboxIndex").Methods("GET") + r.Path("/mailbox/{name}").Handler( + web.Handler(MailboxList)).Name("MailboxList").Methods("GET") + r.Path("/mailbox/{name}/{id}").Handler( + web.Handler(MailboxShow)).Name("MailboxShow").Methods("GET") + r.Path("/mailbox/{name}/{id}/html").Handler( + web.Handler(MailboxHTML)).Name("MailboxHtml").Methods("GET") + r.Path("/mailbox/{name}/{id}/source").Handler( + web.Handler(MailboxSource)).Name("MailboxSource").Methods("GET") + r.Path("/mailbox/dattach/{name}/{id}/{num}/{file}").Handler( + web.Handler(MailboxDownloadAttach)).Name("MailboxDownloadAttach").Methods("GET") + r.Path("/mailbox/vattach/{name}/{id}/{num}/{file}").Handler( + web.Handler(MailboxViewAttach)).Name("MailboxViewAttach").Methods("GET") +} diff --git a/sanitize/css.go b/pkg/webui/sanitize/css.go similarity index 100% rename from sanitize/css.go rename to pkg/webui/sanitize/css.go diff --git a/sanitize/css_test.go b/pkg/webui/sanitize/css_test.go similarity index 100% rename from sanitize/css_test.go rename to pkg/webui/sanitize/css_test.go diff --git a/sanitize/html.go b/pkg/webui/sanitize/html.go similarity index 100% rename from sanitize/html.go rename to pkg/webui/sanitize/html.go diff --git a/sanitize/html_test.go b/pkg/webui/sanitize/html_test.go similarity index 98% rename from sanitize/html_test.go rename to pkg/webui/sanitize/html_test.go index c6acf09..c5443f4 100644 --- a/sanitize/html_test.go +++ b/pkg/webui/sanitize/html_test.go @@ -3,7 +3,7 @@ package sanitize_test import ( "testing" - "github.com/jhillyerd/inbucket/sanitize" + "github.com/jhillyerd/inbucket/pkg/webui/sanitize" ) // TestHTMLPlainStrings test plain text passthrough diff --git a/rest/routes.go b/rest/routes.go deleted file mode 100644 index 1bc73d1..0000000 --- a/rest/routes.go +++ /dev/null @@ -1,23 +0,0 @@ -package rest - -import "github.com/gorilla/mux" -import "github.com/jhillyerd/inbucket/httpd" - -// SetupRoutes populates the routes for the REST interface -func SetupRoutes(r *mux.Router) { - // API v1 - r.Path("/api/v1/mailbox/{name}").Handler( - httpd.Handler(MailboxListV1)).Name("MailboxListV1").Methods("GET") - r.Path("/api/v1/mailbox/{name}").Handler( - httpd.Handler(MailboxPurgeV1)).Name("MailboxPurgeV1").Methods("DELETE") - r.Path("/api/v1/mailbox/{name}/{id}").Handler( - httpd.Handler(MailboxShowV1)).Name("MailboxShowV1").Methods("GET") - r.Path("/api/v1/mailbox/{name}/{id}").Handler( - httpd.Handler(MailboxDeleteV1)).Name("MailboxDeleteV1").Methods("DELETE") - r.Path("/api/v1/mailbox/{name}/{id}/source").Handler( - httpd.Handler(MailboxSourceV1)).Name("MailboxSourceV1").Methods("GET") - r.Path("/api/v1/monitor/messages").Handler( - httpd.Handler(MonitorAllMessagesV1)).Name("MonitorAllMessagesV1").Methods("GET") - r.Path("/api/v1/monitor/messages/{name}").Handler( - httpd.Handler(MonitorMailboxMessagesV1)).Name("MonitorMailboxMessagesV1").Methods("GET") -} diff --git a/webui/routes.go b/webui/routes.go deleted file mode 100644 index 3103d7f..0000000 --- a/webui/routes.go +++ /dev/null @@ -1,35 +0,0 @@ -// Package webui powers Inbucket's web GUI -package webui - -import ( - "github.com/gorilla/mux" - "github.com/jhillyerd/inbucket/httpd" -) - -// SetupRoutes populates routes for the webui into the provided Router -func SetupRoutes(r *mux.Router) { - r.Path("/").Handler( - httpd.Handler(RootIndex)).Name("RootIndex").Methods("GET") - r.Path("/monitor").Handler( - httpd.Handler(RootMonitor)).Name("RootMonitor").Methods("GET") - r.Path("/monitor/{name}").Handler( - httpd.Handler(RootMonitorMailbox)).Name("RootMonitorMailbox").Methods("GET") - r.Path("/status").Handler( - httpd.Handler(RootStatus)).Name("RootStatus").Methods("GET") - r.Path("/link/{name}/{id}").Handler( - httpd.Handler(MailboxLink)).Name("MailboxLink").Methods("GET") - r.Path("/mailbox").Handler( - httpd.Handler(MailboxIndex)).Name("MailboxIndex").Methods("GET") - r.Path("/mailbox/{name}").Handler( - httpd.Handler(MailboxList)).Name("MailboxList").Methods("GET") - r.Path("/mailbox/{name}/{id}").Handler( - httpd.Handler(MailboxShow)).Name("MailboxShow").Methods("GET") - r.Path("/mailbox/{name}/{id}/html").Handler( - httpd.Handler(MailboxHTML)).Name("MailboxHtml").Methods("GET") - r.Path("/mailbox/{name}/{id}/source").Handler( - httpd.Handler(MailboxSource)).Name("MailboxSource").Methods("GET") - r.Path("/mailbox/dattach/{name}/{id}/{num}/{file}").Handler( - httpd.Handler(MailboxDownloadAttach)).Name("MailboxDownloadAttach").Methods("GET") - r.Path("/mailbox/vattach/{name}/{id}/{num}/{file}").Handler( - httpd.Handler(MailboxViewAttach)).Name("MailboxViewAttach").Methods("GET") -}