Rearranged some variable initializations
This commit is contained in:
parent
9e05a12fd7
commit
79331096a9
|
@ -10,7 +10,7 @@ import (
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Version = "0.8.1"
|
var Version = "0.8.2"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(versionCmd)
|
rootCmd.AddCommand(versionCmd)
|
||||||
|
|
17
cmd/web.go
17
cmd/web.go
|
@ -60,9 +60,7 @@ func serveHtml(w http.ResponseWriter, r http.Request, filePath string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func serveStaticFile(w http.ResponseWriter, r http.Request, paths []string) error {
|
func serveStaticFile(w http.ResponseWriter, r http.Request, paths []string) error {
|
||||||
request := r.RequestURI
|
prefixedFilePath, err := url.QueryUnescape(r.RequestURI)
|
||||||
|
|
||||||
prefixedFilePath, err := url.QueryUnescape(request)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -129,9 +127,6 @@ func serveStaticFileHandler(paths []string) http.HandlerFunc {
|
||||||
|
|
||||||
func serveHtmlHandler(paths []string) http.HandlerFunc {
|
func serveHtmlHandler(paths []string) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var filePath string
|
|
||||||
var err error
|
|
||||||
|
|
||||||
refererUri := refererToUri(r.Referer())
|
refererUri := refererToUri(r.Referer())
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
|
@ -141,13 +136,13 @@ func serveHtmlHandler(paths []string) http.HandlerFunc {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
filePath, err = getNextFile(query)
|
filePath, err := getNextFile(query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if filePath == "" {
|
if filePath == "" {
|
||||||
filePath, err = pickFile(paths)
|
filePath, err := pickFile(paths)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -161,7 +156,7 @@ func serveHtmlHandler(paths []string) http.HandlerFunc {
|
||||||
newUrl := r.URL.Host + filePath
|
newUrl := r.URL.Host + filePath
|
||||||
http.Redirect(w, r, newUrl, http.StatusSeeOther)
|
http.Redirect(w, r, newUrl, http.StatusSeeOther)
|
||||||
case r.RequestURI == "/" && Successive && refererUri == "":
|
case r.RequestURI == "/" && Successive && refererUri == "":
|
||||||
filePath, err = pickFile(paths)
|
filePath, err := pickFile(paths)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -174,7 +169,7 @@ func serveHtmlHandler(paths []string) http.HandlerFunc {
|
||||||
newUrl := r.URL.Host + filePath
|
newUrl := r.URL.Host + filePath
|
||||||
http.Redirect(w, r, newUrl, http.StatusSeeOther)
|
http.Redirect(w, r, newUrl, http.StatusSeeOther)
|
||||||
case r.RequestURI == "/":
|
case r.RequestURI == "/":
|
||||||
filePath, err = pickFile(paths)
|
filePath, err := pickFile(paths)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
@ -191,7 +186,6 @@ func serveHtmlHandler(paths []string) http.HandlerFunc {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !isImage {
|
if !isImage {
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
}
|
}
|
||||||
|
@ -215,6 +209,7 @@ func ServePage(args []string) {
|
||||||
for _, i := range paths {
|
for _, i := range paths {
|
||||||
fmt.Println("Paths: " + i)
|
fmt.Println("Paths: " + i)
|
||||||
}
|
}
|
||||||
|
|
||||||
http.HandleFunc("/", serveHtmlHandler(paths))
|
http.HandleFunc("/", serveHtmlHandler(paths))
|
||||||
http.Handle(PREFIX+"/", http.StripPrefix(PREFIX, serveStaticFileHandler(paths)))
|
http.Handle(PREFIX+"/", http.StripPrefix(PREFIX, serveStaticFileHandler(paths)))
|
||||||
http.HandleFunc("/favicon.ico", doNothing)
|
http.HandleFunc("/favicon.ico", doNothing)
|
||||||
|
|
Loading…
Reference in New Issue