Skip to content

TODO to implement Port-Based Filtering in getProxies Route Function #47

Description

@Mehul-Kumar-27

There is a TODO mentioned at riotpot/pkg/api/proxy.go in the getProxies route function which requires implementing functionality to filter proxies based on their ports.

I would like to work on this and plan to implement it in the following manner:

  • First I would be changing the path in the proxiesRoutes like below :
proxiesRoutes = []Route{
		// GET and POST proxies
		NewRoute("/getProxies/:port", "GET", getProxies),
		NewRoute("", "POST", createProxy),
	}
  • Then the getProxies function would look like this -:
func getProxies(ctx *gin.Context) {
	// Get the port parameter as a string
	portStr := ctx.Param("port")
	// Check if a port is provided
	if portStr != "all" {
		// Convert the port string to an integer
		port, err := strconv.Atoi(portStr)
		if err != nil {
			// Handle the error, for example, return a bad request response
			ctx.JSON(http.StatusBadRequest, gin.H{"error": "Invalid port"})
			return
		}

		casted := []GetProxy{}

		// Iterate through the proxies registered
		for _, px := range proxy.Proxies.GetProxies() {
			// Serialize the proxy
			pr := NewProxy(px)
			// Append the proxy to the casted if the port matches
			if port == pr.Port {
				casted = append(casted, *pr)
			}
		}

		// Set the header and transform the struct to JSON format
		ctx.JSON(http.StatusOK, casted)
	} else {
		// No port provided, return all proxies
		allProxies := []GetProxy{}

		// Iterate through the proxies registered
		for _, px := range proxy.Proxies.GetProxies() {
			// Serialize the proxy
			pr := NewProxy(px)
			// Append the proxy to allProxies
			allProxies = append(allProxies, *pr)
		}

		// Set the header and transform the struct to JSON format
		ctx.JSON(http.StatusOK, allProxies)
	}
}

@RicYaben , sir, could you please provide your views on this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions