mirror of
https://github.com/kataras/iris.git
synced 2025-12-22 20:37:05 +00:00
Read https://github.com/kataras/iris/tree/master/HISTORY.md
This commit is contained in:
@@ -24,7 +24,7 @@ import (
|
||||
func main(){
|
||||
e := editor.New("username","password").Port(4444).Dir("/path/to/the/client/side/directory")
|
||||
|
||||
iris.Plugins().Add(e)
|
||||
iris.Plugins.Add(e)
|
||||
|
||||
iris.Get("/", func (ctx *iris.Context){})
|
||||
|
||||
|
||||
@@ -11,10 +11,10 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/iris-contrib/npm"
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/config"
|
||||
"github.com/kataras/iris/logger"
|
||||
"github.com/kataras/iris/npm"
|
||||
"github.com/kataras/iris/utils"
|
||||
)
|
||||
|
||||
@@ -85,13 +85,13 @@ func (e *Plugin) GetDescription() string {
|
||||
}
|
||||
|
||||
// PreListen runs before the server's listens, saves the keyfile,certfile and the host from the Iris station to listen for
|
||||
func (e *Plugin) PreListen(s *iris.Iris) {
|
||||
e.logger = s.Logger()
|
||||
e.keyfile = s.Server().Config.KeyFile
|
||||
e.certfile = s.Server().Config.CertFile
|
||||
func (e *Plugin) PreListen(s *iris.Framework) {
|
||||
e.logger = s.Logger
|
||||
e.keyfile = s.Config.Server.KeyFile
|
||||
e.certfile = s.Config.Server.CertFile
|
||||
|
||||
if e.config.Host == "" {
|
||||
h := s.Server().Config.ListeningAddr
|
||||
h := s.Config.Server.ListeningAddr
|
||||
|
||||
if idx := strings.Index(h, ":"); idx >= 0 {
|
||||
h = h[0:idx]
|
||||
@@ -107,7 +107,7 @@ func (e *Plugin) PreListen(s *iris.Iris) {
|
||||
}
|
||||
|
||||
// PreClose kills the editor's server when Iris is closed
|
||||
func (e *Plugin) PreClose(s *iris.Iris) {
|
||||
func (e *Plugin) PreClose(s *iris.Framework) {
|
||||
if e.process != nil {
|
||||
err := e.process.Kill()
|
||||
if err != nil {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
|
||||
@@ -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),
|
||||
})
|
||||
|
||||
@@ -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...
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
## RoutesInfo plugin
|
||||
|
||||
This plugin collects & stores all registered routes and gives information about them.
|
||||
|
||||
#### The RouteInfo
|
||||
|
||||
```go
|
||||
|
||||
type RouteInfo struct {
|
||||
Method string
|
||||
Domain string
|
||||
Path string
|
||||
RegistedAt time.Time
|
||||
}
|
||||
|
||||
```
|
||||
## How to use
|
||||
|
||||
```go
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/plugin/routesinfo"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
info := routesinfo.New()
|
||||
iris.Plugins().Add(info)
|
||||
|
||||
iris.Get("/yourpath", func(c *iris.Context) {
|
||||
c.Write("yourpath")
|
||||
})
|
||||
|
||||
iris.Post("/otherpostpath", func(c *iris.Context) {
|
||||
c.Write("other post path")
|
||||
})
|
||||
|
||||
all := info.All()
|
||||
// allget := info.ByMethod("GET") -> slice
|
||||
// alllocalhost := info.ByDomain("localhost") -> slice
|
||||
// bypath:= info.ByPath("/yourpath") -> slice
|
||||
// bydomainandmethod:= info.ByDomainAndMethod("localhost","GET") -> slice
|
||||
// bymethodandpath:= info.ByMethodAndPath("GET","/yourpath") -> single (it could be slice for all domains too but it's not)
|
||||
|
||||
println("The first registed route was: ", all[0].Path, "registed at: ", all[0].RegistedAt.String())
|
||||
println("All routes info:")
|
||||
for i:= range all {
|
||||
println(all[i].String())
|
||||
//outputs->
|
||||
// Domain: localhost Method: GET Path: /yourpath RegistedAt: 2016/03/27 15:27:05:029 ...
|
||||
// Domain: localhost Method: POST Path: /otherpostpath RegistedAt: 2016/03/27 15:27:05:030 ...
|
||||
}
|
||||
iris.Listen(":8080")
|
||||
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
@@ -1,151 +0,0 @@
|
||||
package routesinfo
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
)
|
||||
|
||||
//Name the name of the plugin, is "RoutesInfo"
|
||||
const Name = "RoutesInfo"
|
||||
|
||||
// RouteInfo holds the method, domain, path and registered time of a route
|
||||
type RouteInfo struct {
|
||||
Method string
|
||||
Domain string
|
||||
Path string
|
||||
RegistedAt time.Time
|
||||
}
|
||||
|
||||
// String returns the string presentation of the Route(Info)
|
||||
func (ri RouteInfo) String() string {
|
||||
if ri.Domain == "" {
|
||||
ri.Domain = "localhost" // only for printing, this doesn't save it, no pointer.
|
||||
}
|
||||
return fmt.Sprintf("Domain: %s Method: %s Path: %s RegistedAt: %s", ri.Domain, ri.Method, ri.Path, ri.RegistedAt.String())
|
||||
}
|
||||
|
||||
// Plugin the routes info plugin, holds the routes as RouteInfo objects
|
||||
type Plugin struct {
|
||||
routes []RouteInfo
|
||||
}
|
||||
|
||||
// implement the base IPlugin
|
||||
|
||||
// GetName ...
|
||||
func (r Plugin) GetName() string {
|
||||
return Name
|
||||
}
|
||||
|
||||
// GetDescription RoutesInfo gives information about the registed routes
|
||||
func (r Plugin) GetDescription() string {
|
||||
return Name + " gives information about the registed routes.\n"
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
// implement the rest of the plugin
|
||||
|
||||
// PostHandle collect the registed routes information
|
||||
func (r *Plugin) PostHandle(route iris.IRoute) {
|
||||
if r.routes == nil {
|
||||
r.routes = make([]RouteInfo, 0)
|
||||
}
|
||||
r.routes = append(r.routes, RouteInfo{route.GetMethod(), route.GetDomain(), route.GetPath(), time.Now()})
|
||||
}
|
||||
|
||||
// All returns all routeinfos
|
||||
// returns a slice
|
||||
func (r Plugin) All() []RouteInfo {
|
||||
return r.routes
|
||||
}
|
||||
|
||||
// ByDomain returns all routeinfos which registed to a specific domain
|
||||
// returns a slice, if nothing founds this slice has 0 len&cap
|
||||
func (r Plugin) ByDomain(domain string) []RouteInfo {
|
||||
var routesByDomain []RouteInfo
|
||||
rlen := len(r.routes)
|
||||
if domain == "localhost" || domain == "127.0.0.1" || domain == ":" {
|
||||
domain = ""
|
||||
}
|
||||
for i := 0; i < rlen; i++ {
|
||||
if r.routes[i].Domain == domain {
|
||||
routesByDomain = append(routesByDomain, r.routes[i])
|
||||
}
|
||||
}
|
||||
return routesByDomain
|
||||
}
|
||||
|
||||
// ByMethod returns all routeinfos by a http method
|
||||
// returns a slice, if nothing founds this slice has 0 len&cap
|
||||
func (r Plugin) ByMethod(method string) []RouteInfo {
|
||||
var routesByMethod []RouteInfo
|
||||
rlen := len(r.routes)
|
||||
method = strings.ToUpper(method)
|
||||
for i := 0; i < rlen; i++ {
|
||||
if r.routes[i].Method == method {
|
||||
routesByMethod = append(routesByMethod, r.routes[i])
|
||||
}
|
||||
}
|
||||
return routesByMethod
|
||||
}
|
||||
|
||||
// ByPath returns all routeinfos by a path
|
||||
// maybe one path is the same on GET and POST ( for example /login GET, /login POST)
|
||||
// because of that it returns a slice and not only one RouteInfo
|
||||
// returns a slice, if nothing founds this slice has 0 len&cap
|
||||
func (r Plugin) ByPath(path string) []RouteInfo {
|
||||
var routesByPath []RouteInfo
|
||||
rlen := len(r.routes)
|
||||
for i := 0; i < rlen; i++ {
|
||||
if r.routes[i].Path == path {
|
||||
routesByPath = append(routesByPath, r.routes[i])
|
||||
}
|
||||
}
|
||||
return routesByPath
|
||||
}
|
||||
|
||||
// ByDomainAndMethod returns all routeinfos registed to a specific domain and has specific http method
|
||||
// returns a slice, if nothing founds this slice has 0 len&cap
|
||||
func (r Plugin) ByDomainAndMethod(domain string, method string) []RouteInfo {
|
||||
var routesByDomainAndMethod []RouteInfo
|
||||
rlen := len(r.routes)
|
||||
method = strings.ToUpper(method)
|
||||
if domain == "localhost" || domain == "127.0.0.1" || domain == ":" {
|
||||
domain = ""
|
||||
}
|
||||
|
||||
for i := 0; i < rlen; i++ {
|
||||
if r.routes[i].Method == method && r.routes[i].Domain == domain {
|
||||
routesByDomainAndMethod = append(routesByDomainAndMethod, r.routes[i])
|
||||
}
|
||||
}
|
||||
return routesByDomainAndMethod
|
||||
}
|
||||
|
||||
// ByMethodAndPath returns a single *RouteInfo which has specific http method and path
|
||||
// returns only the first match
|
||||
// if nothing founds returns nil
|
||||
func (r Plugin) ByMethodAndPath(method string, path string) *RouteInfo {
|
||||
|
||||
rlen := len(r.routes)
|
||||
for i := 0; i < rlen; i++ {
|
||||
if r.routes[i].Method == method && r.routes[i].Path == path {
|
||||
return &r.routes[i]
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//
|
||||
// RoutesInfo returns the Plugin, same as New()
|
||||
func RoutesInfo() *Plugin {
|
||||
return &Plugin{}
|
||||
}
|
||||
|
||||
// New returns the Plugin, same as RoutesInfo()
|
||||
func New() *Plugin {
|
||||
return &Plugin{}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ func main(){
|
||||
ts = typescript.DefaultOptions()
|
||||
//
|
||||
|
||||
iris.Plugins().Add(typescript.New(ts)) //or with the default options just: typescript.New()
|
||||
iris.Plugins.Add(typescript.New(ts)) //or with the default options just: typescript.New()
|
||||
|
||||
iris.Get("/", func (ctx *iris.Context){})
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/iris-contrib/npm"
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/config"
|
||||
"github.com/kataras/iris/logger"
|
||||
"github.com/kataras/iris/npm"
|
||||
"github.com/kataras/iris/plugin/editor"
|
||||
"github.com/kataras/iris/utils"
|
||||
)
|
||||
@@ -46,7 +46,7 @@ type (
|
||||
Plugin struct {
|
||||
options Options
|
||||
// taken from Activate
|
||||
pluginContainer iris.IPluginContainer
|
||||
pluginContainer iris.PluginContainer
|
||||
// taken at the PreListen
|
||||
logger *logger.Logger
|
||||
}
|
||||
@@ -106,7 +106,7 @@ func New(_opt ...Options) *Plugin {
|
||||
// implement the IPlugin & IPluginPreListen
|
||||
|
||||
// Activate ...
|
||||
func (t *Plugin) Activate(container iris.IPluginContainer) error {
|
||||
func (t *Plugin) Activate(container iris.PluginContainer) error {
|
||||
t.pluginContainer = container
|
||||
return nil
|
||||
}
|
||||
@@ -122,8 +122,8 @@ func (t *Plugin) GetDescription() string {
|
||||
}
|
||||
|
||||
// PreListen ...
|
||||
func (t *Plugin) PreListen(s *iris.Iris) {
|
||||
t.logger = s.Logger()
|
||||
func (t *Plugin) PreListen(s *iris.Framework) {
|
||||
t.logger = s.Logger
|
||||
t.start()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user