diff options
author | Simon Ser <contact@emersion.fr> | 2019-12-11 13:03:31 +0100 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2019-12-11 13:03:31 +0100 |
commit | e54a359acb7b308b75cb76ff8b3dba289903c3fb (patch) | |
tree | 900d246e32b318e8ab32dc6b488ed08d7cd1106a | |
parent | 28a8f3f6acc148b2dde213f2beb6e24c67338b5d (diff) | |
download | alps-e54a359acb7b308b75cb76ff8b3dba289903c3fb.tar.gz alps-e54a359acb7b308b75cb76ff8b3dba289903c3fb.zip |
Export Server.{Sessions,Plugins}
And unexport a few internal functions.
-rw-r--r-- | handlers.go | 2 | ||||
-rw-r--r-- | server.go | 17 | ||||
-rw-r--r-- | session.go | 4 | ||||
-rw-r--r-- | template.go | 2 |
4 files changed, 12 insertions, 13 deletions
diff --git a/handlers.go b/handlers.go index 4919d33..f53085c 100644 --- a/handlers.go +++ b/handlers.go @@ -82,7 +82,7 @@ func handleLogin(ectx echo.Context) error { username := ctx.FormValue("username") password := ctx.FormValue("password") if username != "" && password != "" { - s, err := ctx.Server.sessions.Put(username, password) + s, err := ctx.Server.Sessions.Put(username, password) if err != nil { if _, ok := err.(AuthError); ok { return ctx.Render(http.StatusOK, "login.html", nil) @@ -15,7 +15,8 @@ const cookieName = "koushin_session" const messagesPerPage = 50 type Server struct { - sessions *SessionManager + Sessions *SessionManager + Plugins []Plugin imap struct { host string @@ -28,8 +29,6 @@ type Server struct { tls bool insecure bool } - - plugins []Plugin } func (s *Server) parseIMAPURL(imapURL string) error { @@ -76,7 +75,7 @@ func (s *Server) parseSMTPURL(smtpURL string) error { func newServer(imapURL, smtpURL string) (*Server, error) { s := &Server{} - s.sessions = newSessionManager(s.connectIMAP) + s.Sessions = newSessionManager(s.connectIMAP) if err := s.parseIMAPURL(imapURL); err != nil { return nil, err @@ -134,12 +133,12 @@ func New(e *echo.Echo, options *Options) error { return err } - s.plugins, err = loadAllLuaPlugins(e.Logger) + s.Plugins, err = loadAllLuaPlugins(e.Logger) if err != nil { return fmt.Errorf("failed to load plugins: %v", err) } - e.Renderer, err = loadTemplates(e.Logger, options.Theme, s.plugins) + e.Renderer, err = loadTemplates(e.Logger, options.Theme, s.Plugins) if err != nil { return fmt.Errorf("failed to load templates: %v", err) } @@ -172,14 +171,14 @@ func New(e *echo.Echo, options *Options) error { return err } - ctx.Session, err = ctx.Server.sessions.Get(cookie.Value) + ctx.Session, err = ctx.Server.Sessions.get(cookie.Value) if err == ErrSessionExpired { ctx.SetSession(nil) return ctx.Redirect(http.StatusFound, "/login") } else if err != nil { return err } - ctx.Session.Ping() + ctx.Session.ping() return next(ctx) } @@ -210,7 +209,7 @@ func New(e *echo.Echo, options *Options) error { e.Static("/assets", "public/assets") e.Static("/themes", "public/themes") - for _, p := range s.plugins { + for _, p := range s.Plugins { p.SetRoutes(e.Group("")) } @@ -45,7 +45,7 @@ type Session struct { imapConn *imapclient.Client // protected by locker, can be nil } -func (s *Session) Ping() { +func (s *Session) ping() { s.pings <- struct{}{} } @@ -102,7 +102,7 @@ func (sm *SessionManager) connect(username, password string) (*imapclient.Client return c, nil } -func (sm *SessionManager) Get(token string) (*Session, error) { +func (sm *SessionManager) get(token string) (*Session, error) { sm.locker.Lock() defer sm.locker.Unlock() diff --git a/template.go b/template.go index 1c38c07..7f4d658 100644 --- a/template.go +++ b/template.go @@ -55,7 +55,7 @@ func (r *renderer) Render(w io.Writer, name string, data interface{}, ectx echo. // ectx is the raw *echo.context, not our own *Context ctx := ectx.Get("context").(*Context) - for _, plugin := range ctx.Server.plugins { + for _, plugin := range ctx.Server.Plugins { if err := plugin.Inject(name, data); err != nil { return fmt.Errorf("failed to run plugin '%v': %v", plugin.Name(), err) } |