1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/xurime-aurora

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
main.go 2.6 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
xuri Отправлено 24.07.2021 10:13 a935e08
//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
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/xurime-aurora.git
git@api.gitlife.ru:oschina-mirror/xurime-aurora.git
oschina-mirror
xurime-aurora
xurime-aurora
master