Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 65 lines (57 sloc) 1.425 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
/*
* Original author: Stiletto <blasux@blasux.ru>
*
* This program is free software. It comes without any warranty, to
* the extent permitted by applicable law. You can redistribute it
* and/or modify it under the terms of the Do What The Fuck You Want
* To Public License, Version 2, as published by Sam Hocevar. See
* http://sam.zoy.org/wtfpl/COPYING for more details. */

package geoip

/*
#include <stdio.h>
#include <errno.h>
#include <GeoIP.h>

//typedef GeoIP* GeoIP_pnt
*/
import "C"
import (
    "unsafe"
)

type GeoIP struct {
    gi *C.GeoIP
}

func GeoIP_Open(base string) (*GeoIP) {
    cbase := C.CString(base)
    gi := C.GeoIP_open(cbase, C.GEOIP_STANDARD | C.GEOIP_CHECK_CACHE);
    C.free(unsafe.Pointer(cbase))
    if (gi==nil) {
return nil
    }
    return &GeoIP{gi}
}

func (gi *GeoIP) GetCountry(ip string) (*string) {
    if (gi==nil) {
return nil
    }
    cip := C.CString(ip)
    ccountry := C.GeoIP_country_code_by_addr(gi.gi,cip)
    C.free(unsafe.Pointer(cip))
    if (ccountry!=nil) {
        rets := C.GoString(ccountry)
        return &rets
    }
    return nil
}

/*func (gi *GeoIP) GetCountry_v6(ip string) (*string) {
if (gi==nil) {
return nil
}
cip := C.CString(ip)
ccountry := C.GeoIP_country_code_by_addr_v6(gi.gi,cip)
C.free(unsafe.Pointer(cip))
if (ccountry!=nil) {
rets := C.GoString(ccountry)
return &rets
}
return nil
}*/
Something went wrong with that request. Please try again.