Make New return the Server
This will be useful to implement hot reload.
This commit is contained in:
parent
3d9ddc05be
commit
f6758264b2
2 changed files with 7 additions and 6 deletions
|
@ -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())
|
||||
|
|
10
server.go
10
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue