Rename package

This commit is contained in:
Martin Polden 2018-02-11 11:16:21 +01:00
parent 1fdaa8f9b1
commit 5d43f175d4
4 changed files with 15 additions and 15 deletions

View File

@ -7,7 +7,7 @@ import (
"github.com/mpolden/ipd/http"
"github.com/mpolden/ipd/iputil"
"github.com/mpolden/ipd/iputil/db"
"github.com/mpolden/ipd/iputil/database"
"github.com/sirupsen/logrus"
)
@ -34,9 +34,9 @@ func main() {
}
log.Level = level
ipDb := db.Empty()
db := database.Empty()
if opts.CountryDBPath != "" || opts.CityDBPath != "" {
ipDb, err = db.Open(opts.CountryDBPath, opts.CityDBPath)
db, err = database.New(opts.CountryDBPath, opts.CityDBPath)
if err != nil {
log.Fatal(err)
}
@ -55,7 +55,7 @@ func main() {
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.IPHeader = opts.IPHeader

View File

@ -6,7 +6,7 @@ import (
"html/template"
"github.com/mpolden/ipd/iputil"
"github.com/mpolden/ipd/iputil/db"
"github.com/mpolden/ipd/iputil/database"
"github.com/mpolden/ipd/useragent"
"github.com/sirupsen/logrus"
@ -31,7 +31,7 @@ type Server struct {
IPHeader string
lookupAddr LookupAddr
lookupPort LookupPort
db db.Database
db database.Client
log *logrus.Logger
}
@ -50,7 +50,7 @@ type PortResponse struct {
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}
}

View File

@ -8,7 +8,7 @@ import (
"net/http/httptest"
"testing"
"github.com/mpolden/ipd/iputil/db"
"github.com/mpolden/ipd/iputil/database"
)
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{}
func (t *testDb) Country(net.IP) (db.Country, error) {
return db.Country{Name: "Elbonia", ISO: "EB"}, nil
func (t *testDb) Country(net.IP) (database.Country, error) {
return database.Country{Name: "Elbonia", ISO: "EB"}, nil
}
func (t *testDb) City(net.IP) (string, error) { return "Bornyasherk", nil }
@ -87,7 +87,7 @@ func TestDisabledHandlers(t *testing.T) {
server := testServer()
server.lookupPort = nil
server.lookupAddr = nil
server.db = db.Empty()
server.db = database.Empty()
s := httptest.NewServer(server.Handler())
var tests = []struct {

View File

@ -1,4 +1,4 @@
package db
package database
import (
"net"
@ -6,7 +6,7 @@ import (
geoip2 "github.com/oschwald/geoip2-golang"
)
type Database interface {
type Client interface {
Country(net.IP) (Country, error)
City(net.IP) (string, error)
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) 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
if countryDB != "" {
r, err := geoip2.Open(countryDB)