updated dip structure
This commit is contained in:
parent
cb908eb194
commit
a507ba6b68
@ -3,9 +3,12 @@ package main
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"git.paulbsd.com/paulbsd/dip/packrd"
|
||||
"git.paulbsd.com/paulbsd/dip/src"
|
||||
//packrd "git.paulbsd.com/paulbsd/dip/packrd"
|
||||
"git.paulbsd.com/paulbsd/dip/src/ip"
|
||||
"git.paulbsd.com/paulbsd/dip/src/static"
|
||||
"git.paulbsd.com/paulbsd/dip/src/templates"
|
||||
"github.com/gobuffalo/packr/v2"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
@ -16,7 +19,7 @@ func main() {
|
||||
|
||||
var host, port string
|
||||
|
||||
flag.Usage = dip.Usage
|
||||
flag.Usage = Usage
|
||||
flag.StringVar(&host, "host", "[::]", "Listen host")
|
||||
flag.StringVar(&port, "port", "8080", "Listen port")
|
||||
flag.Parse()
|
||||
@ -27,10 +30,16 @@ func main() {
|
||||
builtTemplates, _ := templates.BuildTemplates(templatesbox)
|
||||
e.Renderer = builtTemplates
|
||||
|
||||
e.GET("/", dip.Dip)
|
||||
e.GET("/", ip.Dip)
|
||||
e.GET("/static/*", func(c echo.Context) error {
|
||||
return static.Static(staticbox, c)
|
||||
})
|
||||
|
||||
e.Logger.Fatal(e.Start(fmt.Sprintf("%s:%s", host, port)))
|
||||
}
|
||||
|
||||
// Usage displays possible arguments
|
||||
func Usage() {
|
||||
flag.PrintDefaults()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
package dip
|
||||
|
||||
import (
|
||||
"git.paulbsd.com/paulbsd/dip/src"
|
||||
"github.com/labstack/echo/v4"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Dip returns webpage
|
||||
func Dip(c echo.Context) (err error) {
|
||||
var ip IP
|
||||
|
||||
ip.GetIPInfo(c)
|
||||
|
||||
if strings.Contains(c.Request().Header.Get(echo.HeaderAccept), echo.MIMETextHTML) {
|
||||
return c.Render(http.StatusOK, "index.html", ip)
|
||||
} else {
|
||||
return c.JSON(http.StatusOK, ip)
|
||||
}
|
||||
}
|
@ -1,11 +1,11 @@
|
||||
package ip
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/likexian/whois-go"
|
||||
@ -65,10 +65,17 @@ func (ip *IP) GetWhois() (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Usage displays possible arguments
|
||||
func Usage() {
|
||||
flag.PrintDefaults()
|
||||
os.Exit(1)
|
||||
// Dip returns webpage
|
||||
func Dip(c echo.Context) (err error) {
|
||||
var ip IP
|
||||
|
||||
ip.GetIPInfo(c)
|
||||
|
||||
if strings.Contains(c.Request().Header.Get(echo.HeaderAccept), echo.MIMETextHTML) {
|
||||
return c.Render(http.StatusOK, "index.html", ip)
|
||||
} else {
|
||||
return c.JSON(http.StatusOK, ip)
|
||||
}
|
||||
}
|
||||
|
||||
// IP defines dip main struct
|
Loading…
Reference in New Issue
Block a user