aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Ser <contact@emersion.fr>2020-01-08 10:38:33 +0100
committerSimon Ser <contact@emersion.fr>2020-01-08 10:38:33 +0100
commitf6758264b2448771d3d7a6b85937c13b57888e81 (patch)
tree507fa87c63ad83a4e30c530327763986c99525d6
parent3d9ddc05beb35e10af9340e04fca8606dd116892 (diff)
downloadalps-f6758264b2448771d3d7a6b85937c13b57888e81.tar.gz
alps-f6758264b2448771d3d7a6b85937c13b57888e81.zip
Make New return the Server
This will be useful to implement hot reload.
-rw-r--r--cmd/koushin/main.go3
-rw-r--r--server.go10
2 files changed, 7 insertions, 6 deletions
diff --git a/cmd/koushin/main.go b/cmd/koushin/main.go
index c9df12b..0f6c776 100644
--- a/cmd/koushin/main.go
+++ b/cmd/koushin/main.go
@@ -35,7 +35,8 @@ func main() {
if l, ok := e.Logger.(*log.Logger); ok {
l.SetHeader("${time_rfc3339} ${level}")
}
- if err := koushin.New(e, &options); err != nil {
+ _, err := koushin.New(e, &options)
+ if err != nil {
e.Logger.Fatal(err)
}
e.Use(middleware.Recover())
diff --git a/server.go b/server.go
index df48303..266e582 100644
--- a/server.go
+++ b/server.go
@@ -133,10 +133,10 @@ type Options struct {
}
// New creates a new server.
-func New(e *echo.Echo, options *Options) error {
+func New(e *echo.Echo, options *Options) (*Server, error) {
s, err := newServer(options.IMAPURL, options.SMTPURL)
if err != nil {
- return err
+ return nil, err
}
s.Plugins = append([]Plugin(nil), plugins...)
@@ -146,13 +146,13 @@ func New(e *echo.Echo, options *Options) error {
luaPlugins, err := loadAllLuaPlugins(e.Logger)
if err != nil {
- return fmt.Errorf("failed to load plugins: %v", err)
+ return nil, fmt.Errorf("failed to load plugins: %v", err)
}
s.Plugins = append(s.Plugins, luaPlugins...)
e.Renderer, err = loadTemplates(e.Logger, options.Theme, s.Plugins)
if err != nil {
- return fmt.Errorf("failed to load templates: %v", err)
+ return nil, fmt.Errorf("failed to load templates: %v", err)
}
e.HTTPErrorHandler = func(err error, c echo.Context) {
@@ -209,5 +209,5 @@ func New(e *echo.Echo, options *Options) error {
p.SetRoutes(e.Group(""))
}
- return nil
+ return s, nil
}