added "next page" button
This commit is contained in:
parent
8da8999802
commit
6fe3685f92
5 changed files with 77 additions and 26 deletions
10
main.go
10
main.go
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// LanguageOption represents a language option for search
|
||||
|
@ -80,12 +81,19 @@ func main() {
|
|||
|
||||
func handleSearch(w http.ResponseWriter, r *http.Request) {
|
||||
var query, safe, lang, searchType string
|
||||
var page int
|
||||
|
||||
if r.Method == "GET" {
|
||||
query = r.URL.Query().Get("q")
|
||||
safe = r.URL.Query().Get("safe")
|
||||
lang = r.URL.Query().Get("lang")
|
||||
searchType = r.URL.Query().Get("t")
|
||||
pageStr := r.URL.Query().Get("p")
|
||||
var err error
|
||||
page, err = strconv.Atoi(pageStr)
|
||||
if err != nil || page < 1 {
|
||||
page = 1 // Default to page 1 if no valid page is specified
|
||||
}
|
||||
} else if r.Method == "POST" {
|
||||
query = r.FormValue("q")
|
||||
safe = r.FormValue("safe")
|
||||
|
@ -102,7 +110,7 @@ func handleSearch(w http.ResponseWriter, r *http.Request) {
|
|||
case "text":
|
||||
handleTextSearch(w, r, query, safe, lang) // Handles fetching and rendering text search results
|
||||
case "image":
|
||||
handleImageSearch(w, r, query) // Handles fetching and rendering image search results
|
||||
handleImageSearch(w, query, safe, lang, page) // Adjusted: Pass *http.Request to match the function signature
|
||||
default:
|
||||
http.ServeFile(w, r, "static/search.html")
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue