1
0
mirror of https://github.com/kataras/iris.git synced 2026-01-05 19:27:05 +00:00

Update to 3.0.0-rc.1 - Read the HISTORY.md. Relative: #183 #184 #166 #176 #181

Read https://github.com/kataras/iris/tree/master/HISTORY.md
This commit is contained in:
Makis Maropoulos
2016-06-14 08:45:40 +03:00
parent 2da67206c8
commit d837381b16
59 changed files with 3972 additions and 4927 deletions

View File

@@ -28,7 +28,7 @@ import (
func main() {
iris.Plugins().Add(iriscontrol.Web(9090, map[string]string{
iris.Plugins.Add(iriscontrol.Web(9090, map[string]string{
"irisusername1": "irispassword1",
"irisusername2": "irispassowrd2",
}))
@@ -39,7 +39,6 @@ func main() {
iris.Post("/something", func(ctx *iris.Context) {
})
fmt.Printf("Iris is listening on :%d", 8080)
iris.Listen(":8080")
}

View File

@@ -7,7 +7,6 @@ import (
"github.com/kataras/iris"
"github.com/kataras/iris/config"
"github.com/kataras/iris/plugin/routesinfo"
)
var pathSeperator = string(os.PathSeparator)
@@ -27,13 +26,13 @@ func (i *irisControlPlugin) startControlPanel() {
}
i.server = iris.New()
i.server.Config().DisableBanner = true
i.server.Config().Render.Template.Directory = installationPath + "templates"
i.server.Config.DisableBanner = true
i.server.Config.Render.Template.Directory = installationPath + "templates"
//i.server.SetRenderConfig(i.server.Config.Render)
i.setPluginsInfo()
i.setPanelRoutes()
go i.server.Listen(strconv.Itoa(i.options.Port))
go i.server.Listen(":" + strconv.Itoa(i.options.Port))
i.pluginContainer.Printf("[%s] %s is running at port %d", time.Now().UTC().String(), Name, i.options.Port)
@@ -43,7 +42,7 @@ func (i *irisControlPlugin) startControlPanel() {
// contains a boolean if server is running, the routes and the plugins
type DashboardPage struct {
ServerIsRunning bool
Routes []routesinfo.RouteInfo
Routes []iris.Route
Plugins []PluginInfo
LastOperationDateStr string
}
@@ -52,7 +51,18 @@ func (i *irisControlPlugin) setPluginsInfo() {
plugins := i.pluginContainer.GetAll()
i.plugins = make([]PluginInfo, 0, len(plugins))
for _, plugin := range plugins {
i.plugins = append(i.plugins, PluginInfo{Name: i.pluginContainer.GetName(plugin), Description: i.pluginContainer.GetDescription(plugin)})
name := i.pluginContainer.GetName(plugin)
desc := i.pluginContainer.GetDescription(plugin)
if name == "" {
// means an iris internaly plugin or a nameless plugin
name = "Internal Iris Plugin"
}
if desc == "" {
// means an iris internaly plugin or a descriptionless plugin
desc = "Propably an internal Iris Plugin - no description provided"
}
i.plugins = append(i.plugins, PluginInfo{Name: name, Description: desc})
}
}
@@ -75,8 +85,8 @@ 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(),
ServerIsRunning: i.station.HTTPServer.IsListening(),
Routes: i.routes,
Plugins: i.plugins,
LastOperationDateStr: i.lastOperationDate.Format(config.TimeFormat),
})

View File

@@ -1,11 +1,7 @@
package iriscontrol
// NOT READY YET
// PluginInfo holds the Name and the description of the registed plugins
// PluginInfo the name and the description of a plugin
type PluginInfo struct {
Name string
Description string
}
//func getPluginlist...

View File

@@ -6,8 +6,6 @@ import (
"github.com/kataras/iris"
"github.com/kataras/iris/config"
"github.com/kataras/iris/middleware/basicauth"
"github.com/kataras/iris/plugin/routesinfo"
"github.com/kataras/iris/server"
)
// Name the name(string) of this plugin which is Iris Control
@@ -16,17 +14,17 @@ const Name = "Iris Control"
type irisControlPlugin struct {
options config.IrisControl
// the pluginContainer is the container which keeps this plugin from the main user's iris instance
pluginContainer iris.IPluginContainer
pluginContainer iris.PluginContainer
// the station object of the main user's iris instance
station *iris.Iris
station *iris.Framework
//a copy of the server which the main user's iris is listening for
stationServer *server.Server
stationServer *iris.Server
// the server is this plugin's server object, it is managed by this plugin only
server *iris.Iris
server *iris.Framework
//
//infos
routes *routesinfo.Plugin
routes []iris.Route
plugins []PluginInfo
// last time the server was on
lastOperationDate time.Time
@@ -37,7 +35,7 @@ type irisControlPlugin struct {
// New returns the plugin which is ready-to-use inside iris.Plugin method
// receives config.IrisControl
func New(cfg ...config.IrisControl) iris.IPlugin {
func New(cfg ...config.IrisControl) iris.Plugin {
c := config.DefaultIrisControl()
if len(cfg) > 0 {
c = cfg[0]
@@ -48,21 +46,20 @@ func New(cfg ...config.IrisControl) iris.IPlugin {
auth := basicauth.Default(c.Users)
return &irisControlPlugin{options: c, authFunc: auth, routes: routesinfo.RoutesInfo()}
return &irisControlPlugin{options: c, authFunc: auth, routes: make([]iris.Route, 0)}
}
// Web set the options for the plugin and return the plugin which is ready-to-use inside iris.Plugin method
// first parameter is port
// second parameter is map of users (username:password)
func Web(port int, users map[string]string) iris.IPlugin {
return New(config.IrisControl{port, users})
func Web(port int, users map[string]string) iris.Plugin {
return New(config.IrisControl{Port: port, Users: users})
}
// implement the base IPlugin
func (i *irisControlPlugin) Activate(container iris.IPluginContainer) error {
func (i *irisControlPlugin) Activate(container iris.PluginContainer) error {
i.pluginContainer = container
container.Add(i.routes) // add the routesinfo plugin to the main server
return nil
}
@@ -78,25 +75,21 @@ func (i irisControlPlugin) GetDescription() string {
// implement the rest of the plugin
// PostHandle
func (i *irisControlPlugin) PostHandle(route iris.IRoute) {
}
// PostListen sets the station object after the main server starts
// starts the actual work of the plugin
func (i *irisControlPlugin) PostListen(s *iris.Iris) {
func (i *irisControlPlugin) PostListen(s *iris.Framework) {
//if the first time, because other times start/stop of the server so listen and no listen will be only from the control panel
if i.station == nil {
i.station = s
i.stationServer = i.station.Server()
i.stationServer = i.station.HTTPServer
i.lastOperationDate = time.Now()
i.routes = s.Lookups()
i.startControlPanel()
}
}
func (i *irisControlPlugin) PreClose(s *iris.Iris) {
func (i *irisControlPlugin) PreClose(s *iris.Framework) {
// Do nothing. This is a wrapper of the main server if we destroy when users stop the main server then we cannot continue the control panel i.Destroy()
}

View File

@@ -2,19 +2,19 @@ package iriscontrol
// for the main server
func (i *irisControlPlugin) StartServer() {
if i.station.Server().IsListening() == false {
if i.station.Server().IsSecure() {
if i.station.HTTPServer.IsListening() == false {
if i.station.HTTPServer.IsSecure() {
//listen with ListenTLS
i.station.ListenTLS(i.station.Server().Config.ListeningAddr, i.station.Server().Config.CertFile, i.station.Server().Config.KeyFile)
i.station.ListenTLS(i.station.Config.Server.ListeningAddr, i.station.Config.Server.CertFile, i.station.Config.Server.KeyFile)
} else {
//listen normal
i.station.Listen(i.station.Server().Config.ListeningAddr)
i.station.Listen(i.station.Config.Server.ListeningAddr)
}
}
}
func (i *irisControlPlugin) StopServer() {
if i.station.Server().IsListening() {
if i.station.HTTPServer.IsListening() {
i.station.Close()
}
}