admin/api: use gorilla/mux instead of Go router
This commit is contained in:
parent
3e74f5f9ef
commit
173dafa69e
18 changed files with 643 additions and 720 deletions
|
@ -10,29 +10,26 @@ import (
|
|||
"path/filepath"
|
||||
"text/template"
|
||||
|
||||
"srs.epita.fr/fic-server/admin/api"
|
||||
"srs.epita.fr/fic-server/libfic"
|
||||
)
|
||||
|
||||
var PKIDir string
|
||||
var SubmissionDir string
|
||||
var BaseURL string
|
||||
var CloudDAVBase string
|
||||
var CloudUsername string
|
||||
var CloudPassword string
|
||||
var StaticDir string
|
||||
|
||||
func main() {
|
||||
var bind = flag.String("bind", "127.0.0.1:8081", "Bind port/socket")
|
||||
var dsn = flag.String("dsn", "fic:fic@/fic", "DSN to connect to the MySQL server")
|
||||
flag.StringVar(&BaseURL, "baseurl", "/", "URL prepended to each URL")
|
||||
var baseURL = flag.String("baseurl", "/", "URL prepended to each URL")
|
||||
flag.StringVar(&SubmissionDir, "submission", "./submissions/", "Base directory where save submissions")
|
||||
flag.StringVar(&PKIDir, "pki", "./pki/", "Base directory where found PKI scripts")
|
||||
flag.StringVar(&StaticDir, "static", "./htdocs-admin/", "Directory containing static files")
|
||||
flag.StringVar(&fic.FilesDir, "files", "./FILES/", "Base directory where found challenges files, local part")
|
||||
flag.StringVar(&CloudDAVBase, "clouddav", "https://srs.epita.fr/owncloud/remote.php/webdav/FIC 2016",
|
||||
flag.StringVar(&api.CloudDAVBase, "clouddav", "https://srs.epita.fr/owncloud/remote.php/webdav/FIC 2016",
|
||||
"Base directory where found challenges files, cloud part")
|
||||
flag.StringVar(&CloudUsername, "clouduser", "fic", "Username used to sync")
|
||||
flag.StringVar(&CloudPassword, "cloudpass", "", "Password used to sync")
|
||||
flag.StringVar(&api.CloudUsername, "clouduser", "fic", "Username used to sync")
|
||||
flag.StringVar(&api.CloudPassword, "cloudpass", "", "Password used to sync")
|
||||
flag.Parse()
|
||||
|
||||
log.SetPrefix("[admin] ")
|
||||
|
@ -78,15 +75,8 @@ func main() {
|
|||
|
||||
os.Chdir(PKIDir)
|
||||
|
||||
log.Println("Registering handlers...")
|
||||
mux := http.NewServeMux()
|
||||
mux.Handle(path.Join(BaseURL, "api") + "/", http.StripPrefix(path.Join(BaseURL, "api"), ApiHandler()))
|
||||
mux.Handle(path.Join(BaseURL, "teams") + "/", http.StripPrefix(BaseURL, StaticHandler(staticDir)))
|
||||
mux.Handle(path.Join(BaseURL, "themes") + "/", http.StripPrefix(BaseURL, StaticHandler(staticDir)))
|
||||
mux.Handle(BaseURL, http.StripPrefix(BaseURL, http.FileServer(http.Dir(staticDir))))
|
||||
|
||||
log.Println(fmt.Sprintf("Ready, listening on %s", *bind))
|
||||
if err := http.ListenAndServe(*bind, mux); err != nil {
|
||||
if err := http.ListenAndServe(*bind, http.StripPrefix(*baseURL, api.Router())); err != nil {
|
||||
log.Fatal("Unable to listen and serve: ", err)
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue