Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data GeoDB
- openGeoDB :: FilePath -> IO GeoDB
- openGeoDBBS :: ByteString -> Either String GeoDB
- geoDbLanguages :: GeoDB -> [Text]
- geoDbType :: GeoDB -> Text
- geoDbDescription :: GeoDB -> Maybe Text
- geoDbAddrType :: GeoDB -> GeoIP
- data GeoIP
- data DecodeException = DecodeException String
- findGeoData :: GeoDB -> Text -> IP -> Either String GeoResult
- data GeoResult = GeoResult {
- geoContinent :: Maybe Text
- geoContinentCode :: Maybe Text
- geoCountryISO :: Maybe Text
- geoCountry :: Maybe Text
- geoLocation :: Maybe Location
- geoCity :: Maybe Text
- geoCityConfidence :: Maybe Int
- geoPostalCode :: Maybe Text
- geoAS :: Maybe AS
- geoISP :: Maybe Text
- geoDomain :: Maybe Text
- geoOrganization :: Maybe Text
- geoUserType :: Maybe Text
- geoSubdivisions :: [(Text, Text)]
- data Location = Location {}
- data AS = AS {
- asNumber :: Int
- asOrganization :: Text
- type GeoField = GeoFieldT Void
- data GeoFieldT a
- = DataPointer a
- | DataString !Text
- | DataDouble Double
- | DataInt Int64
- | DataWord Word64
- | DataMap (Map (GeoFieldT a) (GeoFieldT a))
- | DataArray [GeoFieldT a]
- | DataBool Bool
- | DataUnknown Word8 Int64
- rawGeoData :: GeoDB -> IP -> Either String GeoField
- _DataString :: forall a. Prism' (GeoFieldT a) Text
- _DataDouble :: forall a. Prism' (GeoFieldT a) Double
- _DataInt :: forall a. Prism' (GeoFieldT a) Int64
- _DataWord :: forall a. Prism' (GeoFieldT a) Word64
- _DataMap :: forall a. Prism' (GeoFieldT a) (Map (GeoFieldT a) (GeoFieldT a))
- _DataArray :: forall a. Prism' (GeoFieldT a) [GeoFieldT a]
- _DataBool :: forall a. Prism' (GeoFieldT a) Bool
- _DataUnknown :: forall a. Prism' (GeoFieldT a) (Word8, Int64)
- key :: Text -> Traversal' GeoField GeoField
- geoNum :: Num b => Fold GeoField b
Library description
A haskell library for reading MaxMind's GeoIP version 2 files. It supports both IPv4 and IPv6 addresses. When a match is found, it is parsed and a simplified structure is returned. If you want to access other fields than those that are exposed, it is internally possible.
The database is mmapped upon opening, all querying can be later performed purely without IO monad.
Opening the database
openGeoDB :: FilePath -> IO GeoDB Source #
Open database, mmap it into memory, parse header and return a handle for search operations This function may throw DecodeException
openGeoDBBS :: ByteString -> Either String GeoDB Source #
Open database from a bytestring
geoDbLanguages :: GeoDB -> [Text] Source #
Languages supported in database
geoDbType :: GeoDB -> Text Source #
String that indicates the structure of each data record associated with an IP address
geoDbAddrType :: GeoDB -> GeoIP Source #
Type of address (IPv4/IPv6) stored in a database
Address type stored in database
data DecodeException Source #
Instances
Exception DecodeException Source # | |
Defined in Data.GeoIP2 | |
Show DecodeException Source # | |
Defined in Data.GeoIP2 showsPrec :: Int -> DecodeException -> ShowS # show :: DecodeException -> String # showList :: [DecodeException] -> ShowS # |
Querying the database
:: GeoDB | Db handle |
-> Text | Language code (e.g. "en") |
-> IP | IP address to search |
-> Either String GeoResult | Result, if something is found |
Search GeoIP database
Result of a search query
GeoResult | |
|
Location of the IP address
AS | |
|
Internals
DataPointer a | |
DataString !Text | |
DataDouble Double | |
DataInt Int64 | |
DataWord Word64 | |
DataMap (Map (GeoFieldT a) (GeoFieldT a)) | |
DataArray [GeoFieldT a] | |
DataBool Bool | |
DataUnknown Word8 Int64 |
Instances
Show GeoField Source # | |
Serialize GeoField Source # | |
Eq a => Eq (GeoFieldT a) Source # | |
Ord a => Ord (GeoFieldT a) Source # | |
Defined in Data.GeoIP2.Fields |
rawGeoData :: GeoDB -> IP -> Either String GeoField Source #
Search GeoIP database and return complete unparsed data