modified files structure
This commit is contained in:
parent
b831074864
commit
7515cf4344
45
dip.go
45
dip.go
@ -1,45 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
//"io/ioutil"
|
||||
//"os"
|
||||
//"strings"
|
||||
|
||||
"github.com/gobuffalo/packr/v2"
|
||||
"github.com/labstack/echo/v4"
|
||||
//"github.com/markbates/pkger"
|
||||
)
|
||||
|
||||
func main() {
|
||||
e := echo.New()
|
||||
e.HideBanner = true
|
||||
|
||||
var host, port string
|
||||
|
||||
flag.Usage = Usage
|
||||
flag.StringVar(&host, "host", "[::]", "Listen host")
|
||||
flag.StringVar(&port, "port", "8080", "Listen port")
|
||||
flag.Parse()
|
||||
|
||||
templatesbox := packr.New("templates", "./templates")
|
||||
staticbox := packr.New("static", "./static")
|
||||
|
||||
//t := pkger.Dir("/templatefiles")
|
||||
//fmt.Println(t)
|
||||
//test2,_ := t.Open("index.html")
|
||||
//test3,_ := ioutil.ReadAll(test2)
|
||||
//fmt.Println(string(test3))
|
||||
//io.Copy(os.Stdout,test2)
|
||||
|
||||
builtTemplates, _ := BuildTemplates(templatesbox)
|
||||
e.Renderer = builtTemplates
|
||||
|
||||
e.GET("/", Dip)
|
||||
e.GET("/static/*", func(c echo.Context) error {
|
||||
return Static(staticbox, c)
|
||||
})
|
||||
|
||||
e.Logger.Fatal(e.Start(fmt.Sprintf("%s:%s", host, port)))
|
||||
}
|
@ -5,4 +5,4 @@
|
||||
// and any other packr generated files.
|
||||
package main
|
||||
|
||||
import _ "dip/packrd"
|
||||
import _ "git.paulbsd.com/paulbsd/dip/packrd"
|
||||
|
File diff suppressed because one or more lines are too long
21
src/dip.go
Normal file
21
src/dip.go
Normal file
@ -0,0 +1,21 @@
|
||||
package dip
|
||||
|
||||
import (
|
||||
"git.paulbsd.com/paulbsd/dip/src/ip"
|
||||
"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,15 +1,12 @@
|
||||
package main
|
||||
package ip
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/gobuffalo/packr/v2"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/likexian/whois-go"
|
||||
whoisparser "github.com/likexian/whois-parser-go"
|
||||
@ -36,31 +33,6 @@ func (ip *IP) GetIPInfo(c echo.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
}
|
||||
|
||||
// Static ...
|
||||
func Static(box *packr.Box, c echo.Context) (err error) {
|
||||
name := c.Param("*")
|
||||
cnt, _ := box.FindString(name)
|
||||
if strings.HasSuffix(name, ".js") {
|
||||
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJavaScript)
|
||||
} else if strings.HasSuffix(name, ".css") {
|
||||
c.Response().Header().Set(echo.HeaderContentType, "text/css")
|
||||
}
|
||||
return c.String(http.StatusOK, cnt)
|
||||
}
|
||||
|
||||
// CheckIPAddress check if ip is an IP address, return err if there's an error
|
||||
func (ip *IP) CheckIPAddress() (err error) {
|
||||
addr := net.ParseIP(ip.IP)
|
20
src/static.go
Normal file
20
src/static.go
Normal file
@ -0,0 +1,20 @@
|
||||
package static
|
||||
|
||||
import (
|
||||
"github.com/gobuffalo/packr/v2"
|
||||
"github.com/labstack/echo/v4"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Static ...
|
||||
func Static(box *packr.Box, c echo.Context) (err error) {
|
||||
name := c.Param("*")
|
||||
cnt, _ := box.FindString(name)
|
||||
if strings.HasSuffix(name, ".js") {
|
||||
c.Response().Header().Set(echo.HeaderContentType, echo.MIMEApplicationJavaScript)
|
||||
} else if strings.HasSuffix(name, ".css") {
|
||||
c.Response().Header().Set(echo.HeaderContentType, "text/css")
|
||||
}
|
||||
return c.String(http.StatusOK, cnt)
|
||||
}
|
@ -1,13 +1,10 @@
|
||||
package main
|
||||
package templates
|
||||
|
||||
import (
|
||||
//"bytes"
|
||||
//"fmt"
|
||||
"html/template"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
//"github.com/gobuffalo/packr"
|
||||
"github.com/gobuffalo/packr/v2"
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
Loading…
Reference in New Issue
Block a user