2019-02-20 01:10:18 +02:00
|
|
|
package drivers
|
|
|
|
|
|
|
|
import "github.com/MontFerret/ferret/pkg/runtime/core"
|
|
|
|
|
|
|
|
var (
|
2019-09-30 20:00:13 +02:00
|
|
|
HTTPResponseType = core.NewType("HTTPResponse")
|
2019-08-04 23:25:47 +02:00
|
|
|
HTTPHeaderType = core.NewType("HTTPHeaders")
|
2019-03-16 01:59:05 +02:00
|
|
|
HTTPCookieType = core.NewType("HTTPCookie")
|
2019-02-20 01:10:18 +02:00
|
|
|
HTMLElementType = core.NewType("HTMLElement")
|
|
|
|
HTMLDocumentType = core.NewType("HTMLDocument")
|
2019-06-19 23:58:56 +02:00
|
|
|
HTMLPageType = core.NewType("HTMLPageType")
|
2019-02-20 01:10:18 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Comparison table of builtin types
|
|
|
|
var typeComparisonTable = map[core.Type]uint64{
|
2019-03-16 01:59:05 +02:00
|
|
|
HTTPHeaderType: 0,
|
|
|
|
HTTPCookieType: 1,
|
|
|
|
HTMLElementType: 2,
|
|
|
|
HTMLDocumentType: 3,
|
2019-06-19 23:58:56 +02:00
|
|
|
HTMLPageType: 4,
|
2019-02-20 01:10:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func Compare(first, second core.Type) int64 {
|
|
|
|
f, ok := typeComparisonTable[first]
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
s, ok := typeComparisonTable[second]
|
|
|
|
|
|
|
|
if !ok {
|
|
|
|
return -1
|
|
|
|
}
|
|
|
|
|
|
|
|
if f == s {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
if f > s {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1
|
|
|
|
}
|