From 427bdcb381f0d447a8d69553ceb8534b09340d22 Mon Sep 17 00:00:00 2001 From: KatolaZ Date: Sat, 30 Mar 2019 11:31:51 +0000 Subject: first gopher version --- d1pkgweb-query.go | 148 +++++++++--------------------------------------------- 1 file changed, 23 insertions(+), 125 deletions(-) diff --git a/d1pkgweb-query.go b/d1pkgweb-query.go index 72e5ab3..6b2f4b0 100644 --- a/d1pkgweb-query.go +++ b/d1pkgweb-query.go @@ -4,8 +4,8 @@ import ( "bufio" "fmt" "html/template" - "net/http" - "net/http/cgi" + //"net/http" + // "net/http/cgi" "os" "os/exec" "strings" @@ -28,105 +28,19 @@ type ResultPage struct { } var resTempl = ` - - - - - -Devuan Package information - - - - - - - -
- -

Devuan Package information

- - -
-Search Devuan Packages for: in release - - -
- - -

{{.NumResults}} results for "{{.Query}}" in {{.Release}} (in {{.Time}})

- -
- - - -

This site is a cookie-free zone

-
- - -

- Devuan is a registered trademark of the Dyne.org foundation.

-

- Debian is a registered trademark of Software in the Public Interest, Inc. Linux is a registered trademark of Linus Torvalds.

-
- - - - - ` var releaseMap = map[string]string{ @@ -180,29 +94,20 @@ func pipeComands(commands []*exec.Cmd) ([]byte, error) { } -func getResults(req http.Request) (ResultPage, error) { +func getResults() (ResultPage, error) { var res ResultPage var release string - req.ParseForm() - - searchQuery := req.Form["search"] + searchQuery := os.Getenv("X_GOPHER_SEARCH") if len(searchQuery) < 1 { - printError(503, fmt.Sprintf("Something went wrong in parsing query...\r\n%s\r\n", req.Form)) + printError(503, fmt.Sprintf("Something went wrong in parsing query...\r\n")) os.Exit(0) } - res.Query = searchQuery[0] + res.Query = searchQuery QueryTerms := strings.Split(res.Query, " ") - selectedRelease := req.Form["release"] - if len(selectedRelease) < 1 { - release = "any" - } else { - release = selectedRelease[0] - } - - res.Release = release + res.Release = "any" fmt.Printf("QueryTerms: %s\n", QueryTerms) startTime := time.Now() @@ -222,7 +127,7 @@ func getResults(req http.Request) (ResultPage, error) { //if cmdOut, err := exec.Command(cmd, args...).Output(); err != nil { if cmdOut, err := pipeComands(commands); err != nil { - fmt.Printf("error executing command: %s", err) + fmt.Printf("error executing command: %s %s", commands, err) res.Time = fmt.Sprintf("%s", time.Since(startTime)) return res, nil } else { @@ -241,22 +146,15 @@ func printResults(results ResultPage) { return } - fmt.Printf("Status: 200 OK\r\n") - fmt.Printf("Content-Type: text/html\r\n") + //fmt.Printf("Status: 200 OK\r\n") + //fmt.Printf("Content-Type: text/html\r\n") t.Execute(os.Stdout, results) } func main() { - var req *http.Request var err error - req, err = cgi.Request() - if err != nil { - printError(500, "cannot get requested resource"+err.Error()) - return - } - - res, err := getResults(*req) + res, err := getResults() if err != nil { printError(404, fmt.Sprintf("%s", err)) } else { -- cgit v1.2.3