mirror of
https://github.com/komodorio/helm-dashboard.git
synced 2026-03-24 11:48:04 +00:00
Start working on web server (#2)
* Start working on web server * Some restructure * Serving static works * Fix linter complaint * Enable local dev * Static files served fine * Tidy
This commit is contained in:
43
main.go
43
main.go
@@ -1,10 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/komodorio/helm-dashboard/pkg/dashboard"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/toqueteos/webbrowser"
|
||||
_ "k8s.io/client-go/plugin/pkg/client/auth" //required for auth
|
||||
"net/http"
|
||||
"os"
|
||||
)
|
||||
|
||||
@@ -15,25 +15,36 @@ var (
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.Infof("Helm Dashboard by Komodor, version %s (%s @ %s)", version, commit, date)
|
||||
setupLogging()
|
||||
|
||||
if len(os.Args) > 1 {
|
||||
// TODO: proper command-line parsing
|
||||
if len(os.Args) > 1 { // dirty thing to allow --help to work
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
go func() {
|
||||
// TODO: if it's already running - just open the tab, check that it's another instance of us via API
|
||||
err := webbrowser.Open("http://localhost:8080")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
address, webServerDone := dashboard.StartServer()
|
||||
|
||||
panic(http.ListenAndServe(":8080", http.FileServer(http.Dir("/tmp"))))
|
||||
/* v := cmd.NewRootCmd(os.Stdout, os.Args[1:])
|
||||
if err := v.Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
if os.Getenv("HD_NOBROWSER") == "" {
|
||||
log.Infof("Opening web UI: %s", address)
|
||||
err := webbrowser.Open(address)
|
||||
if err != nil {
|
||||
log.Warnf("Failed to open Web browser for URL: %s", err)
|
||||
}
|
||||
} else {
|
||||
log.Infof("Access web UI at: %s", address)
|
||||
}
|
||||
|
||||
*/
|
||||
<-webServerDone
|
||||
log.Infof("Done.")
|
||||
}
|
||||
|
||||
func setupLogging() {
|
||||
if os.Getenv("DEBUG") == "" {
|
||||
log.SetLevel(log.InfoLevel)
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
} else {
|
||||
log.SetLevel(log.DebugLevel)
|
||||
gin.SetMode(gin.DebugMode)
|
||||
}
|
||||
log.Infof("Helm Dashboard by Komodor, version %s (%s @ %s)", version, commit, date)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user