mirror of
https://github.com/kataras/iris.git
synced 2025-12-23 21:07:03 +00:00
update iriscontrol - no new feature added but now listens to the parent host https://github.com/kataras/iris/issues/191
This commit is contained in:
79
plugin/iriscontrol/plugin.go
Normal file
79
plugin/iriscontrol/plugin.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package iriscontrol
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
"github.com/kataras/iris/utils"
|
||||
)
|
||||
|
||||
// Name "Iris Control"
|
||||
const Name = "Iris Control"
|
||||
|
||||
var (
|
||||
assetsURL = "https://github.com/iris-contrib/iris-control-assets/archive/master.zip"
|
||||
assetsUnzipname = "iris-control-assets"
|
||||
assetsPath = ""
|
||||
)
|
||||
|
||||
// init just sets the assetsPath
|
||||
func init() {
|
||||
homepath := ""
|
||||
if runtime.GOOS == "windows" {
|
||||
homepath = os.Getenv("HOMEDRIVE") + os.Getenv("HOMEPATH")
|
||||
} else {
|
||||
homepath = os.Getenv("HOME")
|
||||
}
|
||||
assetsPath = homepath + utils.PathSeparator + ".iris" + utils.PathSeparator + "iris-control-assets" + utils.PathSeparator
|
||||
}
|
||||
|
||||
func installAssets() {
|
||||
|
||||
if !utils.DirectoryExists(assetsPath) {
|
||||
errMsg := "\nProblem while downloading the assets from the internet for the first time. Trace: %s"
|
||||
|
||||
installedDir, err := utils.Install(assetsURL, assetsPath)
|
||||
if err != nil {
|
||||
panic(errMsg)
|
||||
}
|
||||
|
||||
err = utils.CopyDir(installedDir, assetsPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// try to remove the unzipped folder
|
||||
utils.RemoveFile(installedDir[0 : len(installedDir)-1])
|
||||
}
|
||||
}
|
||||
|
||||
// New creates & returns a new iris control plugin
|
||||
// receives two parameters
|
||||
// first is the authenticated users which should be able to access the control panel
|
||||
// second is the PORT which the iris control panel should be listened & served to
|
||||
func New(port int, users map[string]string) IrisControl {
|
||||
return &iriscontrol{port: port, users: users}
|
||||
}
|
||||
|
||||
// PreListen registers the iriscontrol plugin
|
||||
func (i *iriscontrol) PreListen(s *iris.Framework) {
|
||||
installAssets()
|
||||
i.listen(s)
|
||||
}
|
||||
|
||||
// GetName returns the name of the plugin
|
||||
func (i *iriscontrol) GetName() string {
|
||||
return Name
|
||||
}
|
||||
|
||||
// GetDescription returns the description of the plugin
|
||||
func (i *iriscontrol) GetDescription() string {
|
||||
return Name + " is just a web interface which gives you control of your Iris.\n"
|
||||
}
|
||||
|
||||
// PreClose any clean-up
|
||||
// temporary is empty because all resources are cleaned graceful by the iris' station
|
||||
func (i *iriscontrol) PreClose(s *iris.Framework) {
|
||||
s.Logger.Infof("Main server terminated")
|
||||
}
|
||||
Reference in New Issue
Block a user