mirror of https://github.com/mpolden/echoip
Remove logrus
This commit is contained in:
parent
1efde17791
commit
055496906d
|
@ -1,6 +1,8 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
flags "github.com/jessevdk/go-flags"
|
||||
|
||||
"os"
|
||||
|
@ -8,7 +10,6 @@ import (
|
|||
"github.com/mpolden/ipd/http"
|
||||
"github.com/mpolden/ipd/iputil"
|
||||
"github.com/mpolden/ipd/iputil/database"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -20,26 +21,19 @@ func main() {
|
|||
PortLookup bool `short:"p" long:"port-lookup" description:"Enable port lookup"`
|
||||
Template string `short:"t" long:"template" description:"Path to template" default:"index.html" value-name:"FILE"`
|
||||
IPHeader string `short:"H" long:"trusted-header" description:"Header to trust for remote IP, if present (e.g. X-Real-IP)" value-name:"NAME"`
|
||||
LogLevel string `short:"L" long:"log-level" description:"Log level to use" default:"info" choice:"debug" choice:"info" choice:"warn" choice:"error" choice:"fatal" choice:"panic"`
|
||||
}
|
||||
_, err := flags.ParseArgs(&opts, os.Args)
|
||||
if err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
log := logrus.New()
|
||||
level, err := logrus.ParseLevel(opts.LogLevel)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Level = level
|
||||
|
||||
log := log.New(os.Stderr, "ipd: ", 0)
|
||||
db, err := database.New(opts.CountryDBPath, opts.CityDBPath)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
server := http.New(db, log)
|
||||
server := http.New(db)
|
||||
server.Template = opts.Template
|
||||
server.IPHeader = opts.IPHeader
|
||||
if opts.ReverseLookup {
|
||||
|
|
21
http/http.go
21
http/http.go
|
@ -9,7 +9,6 @@ import (
|
|||
"github.com/mpolden/ipd/iputil"
|
||||
"github.com/mpolden/ipd/iputil/database"
|
||||
"github.com/mpolden/ipd/useragent"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"net"
|
||||
"net/http"
|
||||
|
@ -28,7 +27,6 @@ type Server struct {
|
|||
LookupAddr func(net.IP) ([]string, error)
|
||||
LookupPort func(net.IP, uint64) error
|
||||
db database.Client
|
||||
log *logrus.Logger
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
|
@ -46,8 +44,8 @@ type PortResponse struct {
|
|||
Reachable bool `json:"reachable"`
|
||||
}
|
||||
|
||||
func New(db database.Client, log *logrus.Logger) *Server {
|
||||
return &Server{db: db, log: log}
|
||||
func New(db database.Client) *Server {
|
||||
return &Server{db: db}
|
||||
}
|
||||
|
||||
func ipFromRequest(header string, r *http.Request) (net.IP, error) {
|
||||
|
@ -72,20 +70,11 @@ func (s *Server) newResponse(r *http.Request) (Response, error) {
|
|||
return Response{}, err
|
||||
}
|
||||
ipDecimal := iputil.ToDecimal(ip)
|
||||
country, err := s.db.Country(ip)
|
||||
if err != nil {
|
||||
s.log.Debug(err)
|
||||
}
|
||||
city, err := s.db.City(ip)
|
||||
if err != nil {
|
||||
s.log.Debug(err)
|
||||
}
|
||||
country, _ := s.db.Country(ip)
|
||||
city, _ := s.db.City(ip)
|
||||
var hostnames []string
|
||||
if s.LookupAddr != nil {
|
||||
h, err := s.LookupAddr(ip)
|
||||
if err != nil {
|
||||
s.log.Debug(err)
|
||||
}
|
||||
h, _ := s.LookupAddr(ip)
|
||||
hostnames = h
|
||||
}
|
||||
return Response{
|
||||
|
|
Loading…
Reference in New Issue