Write docs!

This commit is contained in:
nemunaire 2018-03-09 19:07:08 +01:00
commit bcc598ebd5
37 changed files with 478 additions and 188 deletions

View file

@ -14,7 +14,6 @@ import (
"github.com/julienschmidt/httprouter"
)
type DispatchFunction func(httprouter.Params, []byte) (interface{}, error)
func apiHandler(f DispatchFunction) func(http.ResponseWriter, *http.Request, httprouter.Params) {
@ -82,8 +81,8 @@ func apiHandler(f DispatchFunction) func(http.ResponseWriter, *http.Request, htt
}
}
func teamPublicHandler(f func(*fic.Team,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func teamPublicHandler(f func(*fic.Team, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if tid, err := strconv.ParseInt(string(ps.ByName("tid")), 10, 64); err != nil {
return nil, err
} else if tid == 0 {
@ -96,8 +95,8 @@ func teamPublicHandler(f func(*fic.Team,[]byte) (interface{}, error)) func (http
}
}
func teamHandler(f func(fic.Team,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func teamHandler(f func(fic.Team, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if tid, err := strconv.ParseInt(string(ps.ByName("tid")), 10, 64); err != nil {
return nil, err
} else if team, err := fic.GetTeam(tid); err != nil {
@ -108,8 +107,8 @@ func teamHandler(f func(fic.Team,[]byte) (interface{}, error)) func (httprouter.
}
}
func themeHandler(f func(fic.Theme,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func themeHandler(f func(fic.Theme, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if thid, err := strconv.Atoi(string(ps.ByName("thid"))); err != nil {
return nil, err
} else if theme, err := fic.GetTheme(thid); err != nil {
@ -120,8 +119,8 @@ func themeHandler(f func(fic.Theme,[]byte) (interface{}, error)) func (httproute
}
}
func exerciceHandler(f func(fic.Exercice,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func exerciceHandler(f func(fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if eid, err := strconv.Atoi(string(ps.ByName("eid"))); err != nil {
return nil, err
} else if exercice, err := fic.GetExercice(int64(eid)); err != nil {
@ -132,27 +131,27 @@ func exerciceHandler(f func(fic.Exercice,[]byte) (interface{}, error)) func (htt
}
}
func themedExerciceHandler(f func(fic.Theme,fic.Exercice,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func themedExerciceHandler(f func(fic.Theme, fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
var theme fic.Theme
var exercice fic.Exercice
themeHandler(func (th fic.Theme, _[]byte) (interface{}, error) {
themeHandler(func(th fic.Theme, _ []byte) (interface{}, error) {
theme = th
return nil,nil
return nil, nil
})(ps, body)
exerciceHandler(func (ex fic.Exercice, _[]byte) (interface{}, error) {
exerciceHandler(func(ex fic.Exercice, _ []byte) (interface{}, error) {
exercice = ex
return nil,nil
return nil, nil
})(ps, body)
return f(theme, exercice, body)
}
}
func hintHandler(f func(fic.EHint,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func hintHandler(f func(fic.EHint, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if hid, err := strconv.Atoi(string(ps.ByName("hid"))); err != nil {
return nil, err
} else if hint, err := fic.GetHint(int64(hid)); err != nil {
@ -163,12 +162,12 @@ func hintHandler(f func(fic.EHint,[]byte) (interface{}, error)) func (httprouter
}
}
func keyHandler(f func(fic.Key,fic.Exercice,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func keyHandler(f func(fic.Key, fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
var exercice fic.Exercice
exerciceHandler(func (ex fic.Exercice, _[]byte) (interface{}, error) {
exerciceHandler(func(ex fic.Exercice, _ []byte) (interface{}, error) {
exercice = ex
return nil,nil
return nil, nil
})(ps, body)
if kid, err := strconv.Atoi(string(ps.ByName("kid"))); err != nil {
@ -177,7 +176,7 @@ func keyHandler(f func(fic.Key,fic.Exercice,[]byte) (interface{}, error)) func (
return nil, err
} else {
for _, key := range keys {
if (key.Id == int64(kid)) {
if key.Id == int64(kid) {
return f(key, exercice, body)
}
}
@ -186,12 +185,12 @@ func keyHandler(f func(fic.Key,fic.Exercice,[]byte) (interface{}, error)) func (
}
}
func quizHandler(f func(fic.MCQ,fic.Exercice,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func quizHandler(f func(fic.MCQ, fic.Exercice, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
var exercice fic.Exercice
exerciceHandler(func (ex fic.Exercice, _[]byte) (interface{}, error) {
exerciceHandler(func(ex fic.Exercice, _ []byte) (interface{}, error) {
exercice = ex
return nil,nil
return nil, nil
})(ps, body)
if qid, err := strconv.Atoi(string(ps.ByName("qid"))); err != nil {
@ -200,7 +199,7 @@ func quizHandler(f func(fic.MCQ,fic.Exercice,[]byte) (interface{}, error)) func
return nil, err
} else {
for _, mcq := range mcqs {
if (mcq.Id == int64(qid)) {
if mcq.Id == int64(qid) {
return f(mcq, exercice, body)
}
}
@ -209,12 +208,12 @@ func quizHandler(f func(fic.MCQ,fic.Exercice,[]byte) (interface{}, error)) func
}
}
func exerciceFileHandler(f func(fic.EFile,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func exerciceFileHandler(f func(fic.EFile, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
var exercice fic.Exercice
exerciceHandler(func (ex fic.Exercice, _[]byte) (interface{}, error) {
exerciceHandler(func(ex fic.Exercice, _ []byte) (interface{}, error) {
exercice = ex
return nil,nil
return nil, nil
})(ps, body)
if fid, err := strconv.Atoi(string(ps.ByName("fid"))); err != nil {
@ -223,7 +222,7 @@ func exerciceFileHandler(f func(fic.EFile,[]byte) (interface{}, error)) func (ht
return nil, err
} else {
for _, file := range files {
if (file.Id == int64(fid)) {
if file.Id == int64(fid) {
return f(file, body)
}
}
@ -232,8 +231,8 @@ func exerciceFileHandler(f func(fic.EFile,[]byte) (interface{}, error)) func (ht
}
}
func eventHandler(f func(fic.Event,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func eventHandler(f func(fic.Event, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if evid, err := strconv.Atoi(string(ps.ByName("evid"))); err != nil {
return nil, err
} else if event, err := fic.GetEvent(evid); err != nil {
@ -244,8 +243,8 @@ func eventHandler(f func(fic.Event,[]byte) (interface{}, error)) func (httproute
}
}
func claimHandler(f func(fic.Claim,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func claimHandler(f func(fic.Claim, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if cid, err := strconv.Atoi(string(ps.ByName("cid"))); err != nil {
return nil, err
} else if claim, err := fic.GetClaim(cid); err != nil {
@ -256,8 +255,8 @@ func claimHandler(f func(fic.Claim,[]byte) (interface{}, error)) func (httproute
}
}
func claimAssigneeHandler(f func(fic.ClaimAssignee,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func claimAssigneeHandler(f func(fic.ClaimAssignee, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if aid, err := strconv.Atoi(string(ps.ByName("aid"))); err != nil {
return nil, err
} else if assignee, err := fic.GetAssignee(int64(aid)); err != nil {
@ -268,8 +267,8 @@ func claimAssigneeHandler(f func(fic.ClaimAssignee,[]byte) (interface{}, error))
}
}
func fileHandler(f func(fic.EFile,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func fileHandler(f func(fic.EFile, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if fileid, err := strconv.Atoi(string(ps.ByName("fileid"))); err != nil {
return nil, err
} else if file, err := fic.GetFile(fileid); err != nil {
@ -280,8 +279,8 @@ func fileHandler(f func(fic.EFile,[]byte) (interface{}, error)) func (httprouter
}
}
func certificateHandler(f func(fic.Certificate,[]byte) (interface{}, error)) func (httprouter.Params,[]byte) (interface{}, error) {
return func (ps httprouter.Params, body []byte) (interface{}, error) {
func certificateHandler(f func(fic.Certificate, []byte) (interface{}, error)) func(httprouter.Params, []byte) (interface{}, error) {
return func(ps httprouter.Params, body []byte) (interface{}, error) {
if certid, err := strconv.ParseUint(string(ps.ByName("certid")), 10, 64); err != nil {
return nil, err
} else if cert, err := fic.GetCertificate(certid); err != nil {