mirror of https://github.com/mpolden/echoip
Rename package
This commit is contained in:
parent
1fdaa8f9b1
commit
5d43f175d4
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/mpolden/ipd/http"
|
"github.com/mpolden/ipd/http"
|
||||||
"github.com/mpolden/ipd/iputil"
|
"github.com/mpolden/ipd/iputil"
|
||||||
"github.com/mpolden/ipd/iputil/db"
|
"github.com/mpolden/ipd/iputil/database"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -34,9 +34,9 @@ func main() {
|
||||||
}
|
}
|
||||||
log.Level = level
|
log.Level = level
|
||||||
|
|
||||||
ipDb := db.Empty()
|
db := database.Empty()
|
||||||
if opts.CountryDBPath != "" || opts.CityDBPath != "" {
|
if opts.CountryDBPath != "" || opts.CityDBPath != "" {
|
||||||
ipDb, err = db.Open(opts.CountryDBPath, opts.CityDBPath)
|
db, err = database.New(opts.CountryDBPath, opts.CityDBPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ func main() {
|
||||||
log.Printf("Trusting header %s to contain correct remote IP", opts.IPHeader)
|
log.Printf("Trusting header %s to contain correct remote IP", opts.IPHeader)
|
||||||
}
|
}
|
||||||
|
|
||||||
server := http.New(ipDb, lookupAddr, lookupPort, log)
|
server := http.New(db, lookupAddr, lookupPort, log)
|
||||||
server.Template = opts.Template
|
server.Template = opts.Template
|
||||||
server.IPHeader = opts.IPHeader
|
server.IPHeader = opts.IPHeader
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"html/template"
|
"html/template"
|
||||||
|
|
||||||
"github.com/mpolden/ipd/iputil"
|
"github.com/mpolden/ipd/iputil"
|
||||||
"github.com/mpolden/ipd/iputil/db"
|
"github.com/mpolden/ipd/iputil/database"
|
||||||
"github.com/mpolden/ipd/useragent"
|
"github.com/mpolden/ipd/useragent"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ type Server struct {
|
||||||
IPHeader string
|
IPHeader string
|
||||||
lookupAddr LookupAddr
|
lookupAddr LookupAddr
|
||||||
lookupPort LookupPort
|
lookupPort LookupPort
|
||||||
db db.Database
|
db database.Client
|
||||||
log *logrus.Logger
|
log *logrus.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ type PortResponse struct {
|
||||||
Reachable bool `json:"reachable"`
|
Reachable bool `json:"reachable"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(db db.Database, lookupAddr LookupAddr, lookupPort LookupPort, log *logrus.Logger) *Server {
|
func New(db database.Client, lookupAddr LookupAddr, lookupPort LookupPort, log *logrus.Logger) *Server {
|
||||||
return &Server{lookupAddr: lookupAddr, lookupPort: lookupPort, db: db, log: log}
|
return &Server{lookupAddr: lookupAddr, lookupPort: lookupPort, db: db, log: log}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import (
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/mpolden/ipd/iputil/db"
|
"github.com/mpolden/ipd/iputil/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
func lookupAddr(net.IP) ([]string, error) { return []string{"localhost"}, nil }
|
func lookupAddr(net.IP) ([]string, error) { return []string{"localhost"}, nil }
|
||||||
|
@ -16,8 +16,8 @@ func lookupPort(net.IP, uint64) error { return nil }
|
||||||
|
|
||||||
type testDb struct{}
|
type testDb struct{}
|
||||||
|
|
||||||
func (t *testDb) Country(net.IP) (db.Country, error) {
|
func (t *testDb) Country(net.IP) (database.Country, error) {
|
||||||
return db.Country{Name: "Elbonia", ISO: "EB"}, nil
|
return database.Country{Name: "Elbonia", ISO: "EB"}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *testDb) City(net.IP) (string, error) { return "Bornyasherk", nil }
|
func (t *testDb) City(net.IP) (string, error) { return "Bornyasherk", nil }
|
||||||
|
@ -87,7 +87,7 @@ func TestDisabledHandlers(t *testing.T) {
|
||||||
server := testServer()
|
server := testServer()
|
||||||
server.lookupPort = nil
|
server.lookupPort = nil
|
||||||
server.lookupAddr = nil
|
server.lookupAddr = nil
|
||||||
server.db = db.Empty()
|
server.db = database.Empty()
|
||||||
s := httptest.NewServer(server.Handler())
|
s := httptest.NewServer(server.Handler())
|
||||||
|
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package db
|
package database
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
@ -6,7 +6,7 @@ import (
|
||||||
geoip2 "github.com/oschwald/geoip2-golang"
|
geoip2 "github.com/oschwald/geoip2-golang"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Database interface {
|
type Client interface {
|
||||||
Country(net.IP) (Country, error)
|
Country(net.IP) (Country, error)
|
||||||
City(net.IP) (string, error)
|
City(net.IP) (string, error)
|
||||||
IsEmpty() bool
|
IsEmpty() bool
|
||||||
|
@ -28,9 +28,9 @@ func (d *empty) Country(ip net.IP) (Country, error) { return Country{}, nil }
|
||||||
func (d *empty) City(ip net.IP) (string, error) { return "", nil }
|
func (d *empty) City(ip net.IP) (string, error) { return "", nil }
|
||||||
func (d *empty) IsEmpty() bool { return true }
|
func (d *empty) IsEmpty() bool { return true }
|
||||||
|
|
||||||
func Empty() Database { return &empty{} }
|
func Empty() Client { return &empty{} }
|
||||||
|
|
||||||
func Open(countryDB, cityDB string) (Database, error) {
|
func New(countryDB, cityDB string) (Client, error) {
|
||||||
var country, city *geoip2.Reader
|
var country, city *geoip2.Reader
|
||||||
if countryDB != "" {
|
if countryDB != "" {
|
||||||
r, err := geoip2.Open(countryDB)
|
r, err := geoip2.Open(countryDB)
|
Loading…
Reference in New Issue