-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
46 lines (41 loc) · 1009 Bytes
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package miracle
import (
"encoding/json"
"os"
)
// openJsonFile opens a local json file with the given name
func openJsonFile(n string) ([]byte, error) {
bytes, err := os.ReadFile(n)
if err != nil {
return nil, err
}
return bytes, nil
}
// unmarshalSurahInfoJson unmarshal the ./data/surah.json file
func unmarshalSurahInfoJson(b []byte) (*[]SurahInfo, error) {
var suar *[]SurahInfo
err := json.Unmarshal(b, &suar)
if err != nil {
return nil, err
}
return suar, nil
}
// unmarshalSurahJson unmarshal the ./data/surah/surah_X.json file
// (or ./data/translation/en/en_translation_1.json in case of en)
func unmarshalSurahJson(b []byte) (*Surah, error) {
var surah *Surah
err := json.Unmarshal(b, &surah)
if err != nil {
return nil, err
}
return surah, nil
}
// unmarshalJuzInfoJson unmarshal the ./data/juz.json file
func unmarshalJuzInfoJson(b []byte) (*[]Juz, error) {
var ajzaa *[]Juz
err := json.Unmarshal(b, &ajzaa)
if err != nil {
return nil, err
}
return ajzaa, nil
}