mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 02:31:04 +01:00
Add FromAlias to the Mail service and some iriscontrol fixes
This commit is contained in:
parent
48aaca5bc0
commit
86694df84e
|
@ -10,6 +10,8 @@ type Mail struct {
|
|||
Username string
|
||||
// Password is the auth password for the sender
|
||||
Password string
|
||||
// FromAlias is the from part, if empty this is the first part before @ from the Username field
|
||||
FromAlias string
|
||||
// UseCommand enable it if you want to send e-mail with the mail command instead of smtp
|
||||
//
|
||||
// Host,Port & Password will be ignored
|
||||
|
|
7
iris.go
7
iris.go
|
@ -93,13 +93,17 @@ func New(cfg ...config.Iris) *Iris {
|
|||
c := config.Default().Merge(cfg)
|
||||
|
||||
// create the Iris
|
||||
s := &Iris{config: &c, plugins: &PluginContainer{}}
|
||||
s := &Iris{config: &c}
|
||||
|
||||
// create & set the router
|
||||
s.router = newRouter(s)
|
||||
|
||||
// set the Logger
|
||||
s.logger = logger.New()
|
||||
|
||||
//set the plugin container
|
||||
s.plugins = &PluginContainer{logger: s.logger}
|
||||
|
||||
// set the gzip writer pool
|
||||
s.gzipWriterPool = sync.Pool{New: func() interface{} { return &gzip.Writer{} }}
|
||||
return s
|
||||
|
@ -123,6 +127,7 @@ func (s *Iris) initTemplates() {
|
|||
return err.Error()
|
||||
}
|
||||
})
|
||||
|
||||
s.templates = template.New(s.config.Render.Template)
|
||||
|
||||
}
|
||||
|
|
|
@ -33,9 +33,12 @@ type (
|
|||
func New(cfg config.Mail) Service {
|
||||
m := &mailer{config: cfg}
|
||||
|
||||
// not necessary
|
||||
if !cfg.UseCommand && cfg.Username != "" && strings.Contains(cfg.Username, "@") {
|
||||
m.fromAddr = mail.Address{cfg.Username[0:strings.IndexByte(cfg.Username, '@')], cfg.Username}
|
||||
if cfg.FromAlias == "" {
|
||||
if !cfg.UseCommand && cfg.Username != "" && strings.Contains(cfg.Username, "@") {
|
||||
m.fromAddr = mail.Address{cfg.Username[0:strings.IndexByte(cfg.Username, '@')], cfg.Username}
|
||||
}
|
||||
} else {
|
||||
m.fromAddr = mail.Address{cfg.FromAlias, cfg.Username}
|
||||
}
|
||||
|
||||
return m
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
package iris
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/kataras/iris/logger"
|
||||
"github.com/kataras/iris/utils"
|
||||
)
|
||||
|
||||
|
@ -222,6 +221,7 @@ func (d *DownloadManager) Install(remoteFileZip string, targetDirectory string)
|
|||
type PluginContainer struct {
|
||||
activatedPlugins []IPlugin
|
||||
downloader *DownloadManager
|
||||
logger *logger.Logger
|
||||
}
|
||||
|
||||
// Add activates the plugins and if succeed then adds it to the activated plugins list
|
||||
|
@ -327,7 +327,10 @@ func (p *PluginContainer) GetDownloader() IDownloadManager {
|
|||
// Printf sends plain text to any registed logger (future), some plugins maybe want use this method
|
||||
// maybe at the future I change it, instead of sync even-driven to async channels...
|
||||
func (p *PluginContainer) Printf(format string, a ...interface{}) {
|
||||
fmt.Printf(format, a...) //for now just this.
|
||||
if p.logger != nil {
|
||||
p.logger.Printf(format, a...) //for now just this.
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// PreHandle adds a PreHandle plugin-function to the plugin flow container
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/config"
|
||||
"github.com/kataras/iris/plugin/routesinfo"
|
||||
)
|
||||
|
||||
|
@ -41,9 +42,10 @@ func (i *irisControlPlugin) startControlPanel() {
|
|||
// DashboardPage is the main data struct for the index
|
||||
// contains a boolean if server is running, the routes and the plugins
|
||||
type DashboardPage struct {
|
||||
ServerIsRunning bool
|
||||
Routes []routesinfo.RouteInfo
|
||||
Plugins []PluginInfo
|
||||
ServerIsRunning bool
|
||||
Routes []routesinfo.RouteInfo
|
||||
Plugins []PluginInfo
|
||||
LastOperationDateStr string
|
||||
}
|
||||
|
||||
func (i *irisControlPlugin) setPluginsInfo() {
|
||||
|
@ -72,12 +74,18 @@ func (i *irisControlPlugin) setPanelRoutes() {
|
|||
|
||||
i.server.Use(i.authFunc)
|
||||
i.server.Get("/", func(ctx *iris.Context) {
|
||||
ctx.Render("index.html", DashboardPage{ServerIsRunning: i.station.Server().IsListening(), Routes: i.routes.All(), Plugins: i.plugins})
|
||||
ctx.Render("index.html", DashboardPage{
|
||||
ServerIsRunning: i.station.Server().IsListening(),
|
||||
Routes: i.routes.All(),
|
||||
Plugins: i.plugins,
|
||||
LastOperationDateStr: i.lastOperationDate.Format(config.TimeFormat),
|
||||
})
|
||||
})
|
||||
|
||||
//the controls
|
||||
i.server.Post("/start_server", func(ctx *iris.Context) {
|
||||
//println("server start")
|
||||
i.lastOperationDate = time.Now()
|
||||
old := i.stationServer
|
||||
if !old.IsSecure() {
|
||||
i.station.Listen(old.Config.ListeningAddr)
|
||||
|
|
|
@ -28,6 +28,8 @@ type irisControlPlugin struct {
|
|||
//infos
|
||||
routes *routesinfo.Plugin
|
||||
plugins []PluginInfo
|
||||
// last time the server was on
|
||||
lastOperationDate time.Time
|
||||
//
|
||||
|
||||
authFunc iris.HandlerFunc
|
||||
|
@ -88,6 +90,7 @@ func (i *irisControlPlugin) PostListen(s *iris.Iris) {
|
|||
if i.station == nil {
|
||||
i.station = s
|
||||
i.stationServer = i.station.Server()
|
||||
i.lastOperationDate = time.Now()
|
||||
i.startControlPanel()
|
||||
}
|
||||
|
||||
|
@ -106,6 +109,7 @@ func (i *irisControlPlugin) Destroy() {
|
|||
i.options = config.IrisControl{}
|
||||
i.routes = nil
|
||||
i.station = nil
|
||||
i.lastOperationDate = config.CookieExpireNever
|
||||
i.server.Close()
|
||||
i.pluginContainer = nil
|
||||
i.authFunc = nil
|
||||
|
|
|
@ -157,6 +157,7 @@ func (s *Server) listenUnix() (err error) {
|
|||
err = ErrServerRemoveUnix.Format(s.Config.ListeningAddr, errOs.Error())
|
||||
return
|
||||
}
|
||||
//
|
||||
s.listener, err = net.Listen("unix", s.Config.ListeningAddr)
|
||||
|
||||
if err != nil {
|
||||
|
@ -201,6 +202,7 @@ func (s *Server) CloseServer() error {
|
|||
}
|
||||
|
||||
if s.listener != nil {
|
||||
s.started = false
|
||||
return s.listener.Close()
|
||||
}
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue
Block a user