Documentation ¶
Index ¶
Constants ¶
const ( // Examination Year range MinYear = 13 MaxYear = 29 // Examination Season selections SeasonSpring = "haru" SeasonAutumn = "aki" SeasonAll = "all" // used for QueryRange only. // Question No. MinNo = 1 MaxNo = 80 )
These represents the minimum and maximum query range for the F.E. examination.
const JSONVersion = "1.0.0"
current version for json data structure.
const LeastIntervalTime = 5 * time.Second
the minimum time for request interval.
const VariationCoef = 2
interval time varies plus or minus VariationCoef second.
Variables ¶
var ( // source loacation for F.E. examination. FE = Source{ URL: `http://www.fe-siken.com/kakomon/{{.Year}}_{{.Season}}/q{{.No}}.html`, QueryRange: QueryRange{ MaxYear: 29, MinYear: 13, MaxNo: 80, MinNo: 1, Season: SeasonAll, }, } // source location for A.P. examination. AP = Source{ URL: `http://www.ap-siken.com/kakomon/{{.Year}}_{{.Season}}/q{{.No}}.html`, QueryRange: QueryRange{ MaxYear: 29, MinYear: 13, MaxNo: 80, MinNo: 1, Season: SeasonAll, }, } )
Default Source definitions. You can use these to construct new Getter by:
fe_getter := src.NewGetter(src.FE, src.LeastIntervalTime)
var MaxQueryRange = QueryRange{-1, -1, -1, -1, SeasonAll}
MaxQueryRange indicates the maximum range of query in the source.
Functions ¶
func RandomURL ¶
func RandomURL(qr QueryRange) (string, error)
generate random target URL. randomized range is defined by given QueryRange. use default range if MaxQueryRange is given.
Types ¶
type Getter ¶
type Getter struct {
// contains filtered or unexported fields
}
Getter is a interface for F.E. question and answer from webpage. serial requests are splited by some interval time so that the number of accessing the outer server is reduced.
func NewGetter ¶
return new Getter with question source and intervalTime for server request. it will panic if intervalTime less than LeastIntervalTime.
func (*Getter) Get ¶
Get returns a response, which contains F.E question and its answer selected by Query, from website. This process takes some time. You can cancel it by canceling context.
The interval wait time is inserted between serial calling of this method.
func (*Getter) GetRandom ¶
GetRandom returns a response, which contains F.E question and its answer selected randomly in range QueryRange, from website. This process takes some time. You can cancel it by canceling context.
The interval wait time is inserted between serial calling of this method. use maximum query range if MaxQueryRange is given.
type QueryRange ¶
type QueryRange struct {
MaxYear, MinYear int
MaxNo, MinNo int
Season string // SeasonSpring | SeasonAutumn | SeasonAll
}
QueryRange represents query range for randomly selected.
type Response ¶
type Response struct { Question string `json:"question"` Selections []string `json:"selections"` Answer string `json:"answer"` Explanation string `json:"explanation"` // indicates Question, Selections or Answer contain some image. // the response can not be represented by plain text only. HasImage bool `json:"hasImage"` URL string `json:"url"` // source URL Version string `json:"version"` // version for json data structure }
Response is a result of parsing a web page that have the F.E. question and its answer.
func Get ¶
Get() returns a response, which contains F.E question and its answer selected by Query, from website. This process takes some time. You can cancel it by canceling context.
func GetRandom ¶
func GetRandom(ctx context.Context, qr QueryRange) (Response, error)
GetRandom() returns a response, which is randomly selected F.E question and its answer, from website. This process takes some time. You can cancel it by canceling context. use maximum query range if MaxQueryRange is given.
type Source ¶
type Source struct { URL string // URL template for source server. QueryRange // Acceptable range for query. }
Source is the source definition for getting the questions from the extenal server.
func (Source) Validates ¶
check whether given query has correct value range in the source? nil error means query is valid.
func (Source) ValidatesRange ¶
func (src Source) ValidatesRange(qr QueryRange) error
check whether QueryRange is in correct range in the Source? return nil if query is valid.
func (Source) ValidatesSelf ¶
check whether itself has correct values? return nil if it is valid.