refactoring. remove global state, use new logging, config functions
This commit is contained in:
17
init/conf/config.go
Normal file
17
init/conf/config.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package conf
|
||||
|
||||
type PixelWebConfig struct {
|
||||
APIURLExternal string `toml:"api_url_external"`
|
||||
APIURLInternal string `toml:"api_url_internal"`
|
||||
StaticResourceDir string `toml:"static_resource_dir"`
|
||||
TemplateDir string `toml:"template_dir"`
|
||||
DebugMode bool `toml:"debug_mode"`
|
||||
}
|
||||
|
||||
const DefaultConfig = `# Pixeldrain Web UI server configuration
|
||||
|
||||
api_url_external = "https://sia.pixeldrain.com/api" # Used in the web browser, should be a full URL. Not ending with a slash
|
||||
api_url_internal = "http://127.0.0.1:8080/api" # Used for internal API requests to the pixeldrain server, not visible to users
|
||||
static_resource_dir = "res/static"
|
||||
template_dir = "res/template"
|
||||
debug_mode = false`
|
37
init/init.go
37
init/init.go
@@ -1,36 +1,31 @@
|
||||
package init
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"fornaxian.com/pixeldrain-web/conf"
|
||||
"fornaxian.com/pixeldrain-web/log"
|
||||
"fornaxian.com/pixeldrain-web/init/conf"
|
||||
"fornaxian.com/pixeldrain-web/webcontroller"
|
||||
"fornaxian.com/pixeldrain-web/webcontroller/templates"
|
||||
"github.com/Fornaxian/config"
|
||||
"github.com/Fornaxian/log"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
// Init initializes the Pixeldrain Web UI controllers
|
||||
func Init(r *httprouter.Router, prefix string) {
|
||||
log.Init()
|
||||
log.Info("Starting web UI server (PID %v)", os.Getpid())
|
||||
conf.Init()
|
||||
|
||||
templates.ParseTemplates()
|
||||
var webconf = &conf.PixelWebConfig{}
|
||||
var _, err = config.New(
|
||||
conf.DefaultConfig,
|
||||
"",
|
||||
"pdwebconf.toml",
|
||||
webconf,
|
||||
true,
|
||||
)
|
||||
if err != nil {
|
||||
log.Error("Failed to load config file: %s", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Serve static files
|
||||
r.ServeFiles(prefix+"/res/*filepath", http.Dir(conf.StaticResourceDir()+"/res"))
|
||||
|
||||
r.GET(prefix+"/", webcontroller.ServeHome)
|
||||
r.GET(prefix+"/favicon.ico", webcontroller.ServeFavicon)
|
||||
r.GET(prefix+"/global.css", webcontroller.GlobalCSSHandler)
|
||||
r.GET(prefix+"/api", webcontroller.ServeAPIDoc)
|
||||
r.GET(prefix+"/history", webcontroller.ServeHistory)
|
||||
r.GET(prefix+"/u/:id", webcontroller.ServeFileViewer)
|
||||
r.GET(prefix+"/u/:id/preview", webcontroller.ServeFilePreview)
|
||||
r.GET(prefix+"/l/:id", webcontroller.ServeListViewer)
|
||||
r.GET(prefix+"/t", webcontroller.ServePaste)
|
||||
|
||||
r.NotFound = http.HandlerFunc(webcontroller.ServeNotFound)
|
||||
webcontroller.New(r, prefix, webconf)
|
||||
}
|
||||
|
Reference in New Issue
Block a user