2019-02-19 18:10:18 -05:00
|
|
|
package drivers
|
|
|
|
|
|
|
|
import "github.com/MontFerret/ferret/pkg/runtime/core"
|
|
|
|
|
|
|
|
var (
|
2019-09-30 21:00:13 +03:00
|
|
|
HTTPResponseType = core.NewType("HTTPResponse")
|
2019-08-04 17:25:47 -04:00
|
|
|
HTTPHeaderType = core.NewType("HTTPHeaders")
|
2019-03-15 19:59:05 -04:00
|
|
|
HTTPCookieType = core.NewType("HTTPCookie")
|
2019-02-19 18:10:18 -05:00
|
|
|
HTMLElementType = core.NewType("HTMLElement")
|
|
|
|
HTMLDocumentType = core.NewType("HTMLDocument")
|
2019-06-19 17:58:56 -04:00
|
|
|
HTMLPageType = core.NewType("HTMLPageType")
|
2019-02-19 18:10:18 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// Comparison table of builtin types
|
|
|
|
var typeComparisonTable = map[core.Type]uint64{
|
2019-03-15 19:59:05 -04:00
|
|
|
HTTPHeaderType: 0,
|
|
|
|
HTTPCookieType: 1,
|
|
|
|
HTMLElementType: 2,
|
|
|
|
HTMLDocumentType: 3,
|
2019-06-19 17:58:56 -04:00
|
|
|
HTMLPageType: 4,
|
2019-02-19 18:10:18 -05: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
|
|
|
|
}
|