4 Star 13 Fork 4

xuri/aurora

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 2.62 KB
一键复制 编辑 原始数据 按行查看 历史
//go:generate statik -src=./public
// Copyright 2016 - 2021 The aurora Authors. All rights reserved. Use of this
// source code is governed by a MIT license that can be found in the LICENSE
// file.
//
// The aurora is a web-based beanstalkd queue server console written in Go
// and works on macOS, Linux and Windows machines. Main idea behind using Go
// for backend development is to utilize ability of the compiler to produce
// zero-dependency binaries for multiple platforms. aurora was created as an
// attempt to build very simple and portable application to work with local or
// remote beanstalkd server.
//
// See https://xuri.me/aurora for more information about aurora.
package main
import (
"fmt"
"net/http"
"os"
"os/signal"
"runtime"
"strings"
"syscall"
"github.com/rakyll/statik/fs"
_ "github.com/xuri/aurora/statik"
)
// main function defines the entry point for the program if read config file or
// init failed, the application will be exit.
func main() {
parseFlags()
err := readConf()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
statikFS, err := fs.New()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
http.FileServer(statikFS)
// handle static files include HTML, CSS and JavaScripts.
http.Handle("/", http.StripPrefix("/", http.FileServer(statikFS)))
http.HandleFunc("/public", basicAuth(handlerMain))
http.HandleFunc("/index", basicAuth(handlerServerList))
http.HandleFunc("/serversRemove", basicAuth(serversRemove))
http.HandleFunc("/server", basicAuth(handlerServer))
http.HandleFunc("/tube", basicAuth(handlerTube))
http.HandleFunc("/sample", basicAuth(handlerSample))
http.HandleFunc("/statistics", basicAuth(handlerStatistics))
go func() {
err = http.ListenAndServe(pubConf.Listen, nil)
if err != nil {
fmt.Println("Cant start server:", err)
os.Exit(1)
}
}()
go statistic()
openPage()
handleSignals()
}
// openPage function can be open system default browser automatic.
func openPage() {
url := fmt.Sprintf("http://%v", pubConf.Listen)
fmt.Println("To view beanstalkd console open", url, "in browser")
if !pubConf.OpenPage.Enabled {
return
}
var err error
switch runtime.GOOS {
case "linux", "freebsd", "openbsd", "netbsd":
err = runCmd("xdg-open", url)
case "darwin":
err = runCmd("open", url)
case "windows":
r := strings.NewReplacer("&", "^&")
err = runCmd("cmd", "/c", "start", r.Replace(url))
default:
err = fmt.Errorf("unsupported platform")
}
if err != nil {
fmt.Println(err)
}
}
// handleSignals handle kill signal.
func handleSignals() {
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)
<-c
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/xurime/aurora.git
git@gitee.com:xurime/aurora.git
xurime
aurora
aurora
master

搜索帮助

A270a887 8829481 3d7a4017 8829481