How do I get the current url with query string

How many levels of authorization do you need? You mentioned 2 levels.

To get the current URL with query string in Golang, you can use the Request.URL field of the *http.Request struct. This field will contain the full URL of the request, including the query string.

For example, the following code will get the current URL with query string:

package main

import (
    "fmt"
    "net/http"
)

func main() {
    request, err := http.NewRequest("GET", "/", nil)
    if err != nil {
        fmt.Println(err)
        return
    }

    url := request.URL
    fmt.Println(url.String())
}

This code will first create a new http.Request object. Then, it will get the URL field of the request object and print it to the console.

The output of the code will be the full URL of the request, including the query string.

If you want to parse the URL and get the page URL values, you can use the ParseQuery() function. This function will parse the query string and return a map of key-value pairs.

I have played with this now. Basically reading scroll position by using Javascript and letting Go fetch next 100 rows from the database. Totally 25,000 records in the database :slight_smile:

Any improvement suggestions are welcome.

In your Golang handler function that receives the *http.Request object, you can access the current URL with the following line of code:

GocurrentURL := r.URL.String()

This will give you a string containing the complete URL, including the path and query string.
capcut

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.