cmd/koushin: add -debug flag
This commit is contained in:
parent
e59ad57e32
commit
13f5414691
4 changed files with 18 additions and 3 deletions
|
@ -23,9 +23,10 @@ func main() {
|
|||
var addr string
|
||||
flag.StringVar(&options.Theme, "theme", "", "default theme")
|
||||
flag.StringVar(&addr, "addr", ":1323", "listening address")
|
||||
flag.BoolVar(&options.Debug, "debug", false, "enable debug logs")
|
||||
|
||||
flag.Usage = func() {
|
||||
fmt.Fprintf(flag.CommandLine.Output(), "usage: koushin [options...] <upstream server...>\n")
|
||||
fmt.Fprintf(flag.CommandLine.Output(), "usage: koushin [options...] <upstream servers...>\n")
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
|
||||
|
@ -48,6 +49,10 @@ func main() {
|
|||
}
|
||||
e.Use(middleware.Recover())
|
||||
|
||||
if options.Debug {
|
||||
e.Logger.SetLevel(log.DEBUG)
|
||||
}
|
||||
|
||||
sigs := make(chan os.Signal, 1)
|
||||
signal.Notify(sigs, syscall.SIGUSR1)
|
||||
go func() {
|
||||
|
|
|
@ -33,6 +33,8 @@ The following URL schemes are supported:
|
|||
|
||||
**-addr**: listening address (default: ":1323")
|
||||
|
||||
**-debug**: enable debug logs and print IMAP network activity
|
||||
|
||||
**-h**, **--help**: show help message and exit
|
||||
|
||||
# SIGNALS
|
||||
|
|
|
@ -59,7 +59,7 @@ func newServer(e *echo.Echo, options *Options) (*Server, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
s.Sessions = newSessionManager(s.dialIMAP, s.dialSMTP, e.Logger)
|
||||
s.Sessions = newSessionManager(s.dialIMAP, s.dialSMTP, e.Logger, options.Debug)
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
@ -283,6 +283,7 @@ func handleUnauthenticated(next echo.HandlerFunc, ctx *Context) error {
|
|||
type Options struct {
|
||||
Upstreams []string
|
||||
Theme string
|
||||
Debug bool
|
||||
}
|
||||
|
||||
// New creates a new server.
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -142,17 +143,19 @@ type SessionManager struct {
|
|||
dialIMAP DialIMAPFunc
|
||||
dialSMTP DialSMTPFunc
|
||||
logger echo.Logger
|
||||
debug bool
|
||||
|
||||
locker sync.Mutex
|
||||
sessions map[string]*Session // protected by locker
|
||||
}
|
||||
|
||||
func newSessionManager(dialIMAP DialIMAPFunc, dialSMTP DialSMTPFunc, logger echo.Logger) *SessionManager {
|
||||
func newSessionManager(dialIMAP DialIMAPFunc, dialSMTP DialSMTPFunc, logger echo.Logger, debug bool) *SessionManager {
|
||||
return &SessionManager{
|
||||
sessions: make(map[string]*Session),
|
||||
dialIMAP: dialIMAP,
|
||||
dialSMTP: dialSMTP,
|
||||
logger: logger,
|
||||
debug: debug,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,6 +170,10 @@ func (sm *SessionManager) connectIMAP(username, password string) (*imapclient.Cl
|
|||
return nil, AuthError{err}
|
||||
}
|
||||
|
||||
if sm.debug {
|
||||
c.SetDebug(os.Stderr)
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue