Use pointer receiver more offen
This commit is contained in:
parent
6999b4e728
commit
c7569b5e54
59 changed files with 688 additions and 672 deletions
|
@ -22,7 +22,7 @@ func fixnbsp(s string) string {
|
|||
}
|
||||
|
||||
// GetExercices returns all exercice directories existing in a given theme, considering the given Importer.
|
||||
func GetExercices(i Importer, theme fic.Theme) ([]string, error) {
|
||||
func GetExercices(i Importer, theme *fic.Theme) ([]string, error) {
|
||||
var exercices []string
|
||||
|
||||
if len(theme.Path) == 0 {
|
||||
|
@ -42,12 +42,12 @@ func GetExercices(i Importer, theme fic.Theme) ([]string, error) {
|
|||
return exercices, nil
|
||||
}
|
||||
|
||||
func buildDependancyMap(i Importer, theme fic.Theme) (dmap map[int64]fic.Exercice, err error) {
|
||||
func buildDependancyMap(i Importer, theme *fic.Theme) (dmap map[int64]*fic.Exercice, err error) {
|
||||
var exercices []string
|
||||
if exercices, err = GetExercices(i, theme); err != nil {
|
||||
return
|
||||
} else {
|
||||
dmap = map[int64]fic.Exercice{}
|
||||
dmap = map[int64]*fic.Exercice{}
|
||||
|
||||
for _, edir := range exercices {
|
||||
var eid int
|
||||
|
@ -58,7 +58,7 @@ func buildDependancyMap(i Importer, theme fic.Theme) (dmap map[int64]fic.Exercic
|
|||
continue
|
||||
}
|
||||
|
||||
var e fic.Exercice
|
||||
var e *fic.Exercice
|
||||
e, err = theme.GetExerciceByTitle(ename)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -90,7 +90,7 @@ func parseExerciceDirname(edir string) (eid int, ename string, err error) {
|
|||
}
|
||||
|
||||
// BuildExercice creates an Exercice from a given importer.
|
||||
func BuildExercice(i Importer, theme fic.Theme, epath string, dmap *map[int64]fic.Exercice) (e *fic.Exercice, p ExerciceParams, eid int, edir string, errs []string) {
|
||||
func BuildExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*fic.Exercice) (e *fic.Exercice, p ExerciceParams, eid int, edir string, errs []string) {
|
||||
e = &fic.Exercice{}
|
||||
|
||||
e.Path = epath
|
||||
|
@ -211,7 +211,7 @@ func BuildExercice(i Importer, theme fic.Theme, epath string, dmap *map[int64]fi
|
|||
}
|
||||
|
||||
// SyncExercice imports new or updates existing given exercice.
|
||||
func SyncExercice(i Importer, theme fic.Theme, epath string, dmap *map[int64]fic.Exercice) (e *fic.Exercice, eid int, errs []string) {
|
||||
func SyncExercice(i Importer, theme *fic.Theme, epath string, dmap *map[int64]*fic.Exercice) (e *fic.Exercice, eid int, errs []string) {
|
||||
var err error
|
||||
var edir string
|
||||
var p ExerciceParams
|
||||
|
@ -242,7 +242,7 @@ func SyncExercice(i Importer, theme fic.Theme, epath string, dmap *map[int64]fic
|
|||
}
|
||||
|
||||
// SyncExercices imports new or updates existing exercices, in a given theme.
|
||||
func SyncExercices(i Importer, theme fic.Theme) (errs []string) {
|
||||
func SyncExercices(i Importer, theme *fic.Theme) (errs []string) {
|
||||
if !avoidImporterSync() {
|
||||
if err := i.Sync(); err != nil {
|
||||
errs = append(errs, err.Error())
|
||||
|
@ -260,7 +260,7 @@ func SyncExercices(i Importer, theme fic.Theme) (errs []string) {
|
|||
e, eid, cur_errs := SyncExercice(i, theme, path.Join(theme.Path, edir), &dmap)
|
||||
if e != nil {
|
||||
emap[e.Title] = eid
|
||||
dmap[int64(eid)] = *e
|
||||
dmap[int64(eid)] = e
|
||||
errs = append(errs, cur_errs...)
|
||||
}
|
||||
}
|
||||
|
@ -281,7 +281,7 @@ func SyncExercices(i Importer, theme fic.Theme) (errs []string) {
|
|||
func ApiListRemoteExercices(ps httprouter.Params, _ []byte) (interface{}, error) {
|
||||
theme, errs := BuildTheme(GlobalImporter, ps.ByName("thid"))
|
||||
if theme != nil {
|
||||
return GetExercices(GlobalImporter, *theme)
|
||||
return GetExercices(GlobalImporter, theme)
|
||||
} else {
|
||||
return nil, fmt.Errorf("%q", errs)
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ func ApiListRemoteExercices(ps httprouter.Params, _ []byte) (interface{}, error)
|
|||
func ApiGetRemoteExercice(ps httprouter.Params, _ []byte) (interface{}, error) {
|
||||
theme, errs := BuildTheme(GlobalImporter, ps.ByName("thid"))
|
||||
if theme != nil {
|
||||
exercice, _, _, _, errs := BuildExercice(GlobalImporter, *theme, path.Join(theme.Path, ps.ByName("exid")), nil)
|
||||
exercice, _, _, _, errs := BuildExercice(GlobalImporter, theme, path.Join(theme.Path, ps.ByName("exid")), nil)
|
||||
if exercice != nil {
|
||||
return exercice, nil
|
||||
} else {
|
||||
|
|
Reference in a new issue