Get URL params

This commit is contained in:
Araozu 2024-05-08 07:39:04 -05:00
parent eaabbafed6
commit 4a4e5830f6

19
main.go
View File

@ -5,6 +5,7 @@ import (
"fmt"
"log"
"net/http"
"net/url"
"os"
"github.com/gorilla/mux"
@ -46,7 +47,23 @@ func main() {
}
func Register(writer http.ResponseWriter, request *http.Request) {
username := "ga"
requestUrl := request.URL
params, err := url.ParseQuery(requestUrl.RawQuery)
if err != nil {
fmt.Printf("Error parsing URL parameters: %s\n", err)
writer.WriteHeader(http.StatusInternalServerError)
fmt.Printf("{\"error\": \"%s\"}", err)
return
}
usernameArr, ok := params["username"]
if !ok {
fmt.Printf("Error parsing URL parameters: %s\n", err)
writer.WriteHeader(http.StatusInternalServerError)
fmt.Printf("{\"error\": \"%s\"}", err)
return
}
username := usernameArr[0]
uid := cuid2.Generate()