quran-go

Read Qur'an right in the terminal.
git clone http://git.hanabi.in/repos/quran-go.git
Log | Files | Refs | README | LICENSE

check-verse-range.go (861B)


      1 package utils
      2 
      3 import (
      4 	"fmt"
      5 
      6 	f "git.hanabi.in/gitbox/quran-go/src/fetch"
      7 	t "git.hanabi.in/gitbox/quran-go/src/types"
      8 )
      9 
     10 // Check if chapter verse are within range, returns last verse of the chapter, and error if any,
     11 func CheckVerseRange(chapterID t.Chap, verse1, verse2 t.Verse) (lastVerse t.Verse, err error) {
     12 
     13 	res, err := isValidChapRange(chapterID)
     14 	if err != nil {
     15 		return lastVerse, err
     16 	}
     17 
     18 	if res == false {
     19 		err = fmt.Errorf("Chapter %d is out of range.\n", chapterID)
     20 		return lastVerse, err
     21 	}
     22 
     23 	chapDetails, err := f.ChapterDetails(chapterID)
     24 	if err != nil {
     25 		return lastVerse, err
     26 	}
     27 
     28 	if lastVerse = t.Verse(chapDetails.VersesCount); verse2 > lastVerse {
     29 		err = fmt.Errorf("Verse for the chapter %d is out of range.  That chapter has verses only till %d.\n", chapterID, lastVerse)
     30 		return lastVerse, err
     31 	}
     32 
     33 	return lastVerse, err
     34 
     35 }