admin: Read challenge.json from imported directory
This commit is contained in:
parent
560110ba5e
commit
8ed9415c68
3 changed files with 21 additions and 13 deletions
|
@ -3,6 +3,7 @@ package settings
|
|||
import (
|
||||
"encoding/json"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ChallengeFile is the expected name of the file containing the challenge infos.
|
||||
|
@ -28,20 +29,15 @@ type ChallengeInfo struct {
|
|||
}
|
||||
|
||||
// ReadChallenge parses the file at the given location.
|
||||
func ReadChallengeInfo(path string) (*ChallengeInfo, error) {
|
||||
func ReadChallengeInfo(content string) (*ChallengeInfo, error) {
|
||||
var s ChallengeInfo
|
||||
if fd, err := os.Open(path); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
defer fd.Close()
|
||||
jdec := json.NewDecoder(fd)
|
||||
jdec := json.NewDecoder(strings.NewReader(content))
|
||||
|
||||
if err := jdec.Decode(&s); err != nil {
|
||||
return &s, err
|
||||
}
|
||||
|
||||
return &s, nil
|
||||
if err := jdec.Decode(&s); err != nil {
|
||||
return &s, err
|
||||
}
|
||||
|
||||
return &s, nil
|
||||
}
|
||||
|
||||
// SaveChallenge saves challenge at the given location.
|
||||
|
|
Reference in a new issue