qa: New service to handle QA testing by students
This commit is contained in:
parent
a0155c6deb
commit
a237936feb
37 changed files with 1476 additions and 0 deletions
66
qa/static.go
Normal file
66
qa/static.go
Normal file
|
@ -0,0 +1,66 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"srs.epita.fr/fic-server/qa/api"
|
||||
|
||||
"github.com/julienschmidt/httprouter"
|
||||
)
|
||||
|
||||
var BaseURL = "/"
|
||||
|
||||
var indexTmpl []byte
|
||||
|
||||
func getIndexHtml(w io.Writer) {
|
||||
if len(indexTmpl) == 0 {
|
||||
if file, err := os.Open(path.Join(StaticDir, "index.html")); err != nil {
|
||||
log.Println("Unable to open index.html: ", err)
|
||||
} else {
|
||||
defer file.Close()
|
||||
|
||||
if indexTmpl, err = ioutil.ReadAll(file); err != nil {
|
||||
log.Println("Cannot read whole index.html: ", err)
|
||||
} else {
|
||||
indexTmpl = bytes.Replace(indexTmpl, []byte("{{.urlbase}}"), []byte(path.Clean(path.Join(BaseURL+"/", "nuke"))[:len(path.Clean(path.Join(BaseURL+"/", "nuke")))-4]), -1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
w.Write(indexTmpl)
|
||||
}
|
||||
|
||||
func init() {
|
||||
api.Router().GET("/", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
getIndexHtml(w)
|
||||
})
|
||||
|
||||
api.Router().GET("/exercices/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
getIndexHtml(w)
|
||||
})
|
||||
api.Router().GET("/themes/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
getIndexHtml(w)
|
||||
})
|
||||
|
||||
api.Router().GET("/css/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, r.URL.Path))
|
||||
})
|
||||
api.Router().GET("/fonts/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, r.URL.Path))
|
||||
})
|
||||
api.Router().GET("/img/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, r.URL.Path))
|
||||
})
|
||||
api.Router().GET("/js/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, r.URL.Path))
|
||||
})
|
||||
api.Router().GET("/views/*_", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
http.ServeFile(w, r, path.Join(StaticDir, r.URL.Path))
|
||||
})
|
||||
}
|
Reference in a new issue