1

I want to get the query arguments from RequestURI in golang. The URL is like that: http://localhost:3000/add-ebay?authToken=AgAAAA**AQAAAA**aAAAAA**6d8JWQ**nY+sHZ2PrBmdj6wVnY+sEZ2...

And my code is followings:

func CreateEbayProfile(ctx *fasthttp.RequestCtx) {

    log.Println( ctx.QueryArgs().Peek("authToken"))
               ....
}

The result is that:

AgAAAA**AQAAAA**aAAAAA**6d8JWQ**nY sHZ2PrBmdj6wVnY sEZ2...

But I want to result like that:

AgAAAA**AQAAAA**aAAAAA**6d8JWQ**nY+sHZ2PrBmdj6wVnY+sEZ2...

How can I get the correct result? And why this is happening?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Alakey
  • 21
  • 6

1 Answers1

0

You can simply use strings.Replace to replace a character with another one.

package main

import (
    "fmt"
    "strings"
)

func main() {
    s := "AgAAAA**AQAAAA**aAAAAA**6d8JWQ**nY sHZ2PrBmdj6wVnY sEZ2...";
    conv := strings.Replace(s, " ", "+", -1)

    fmt.Println(conv) //AgAAAA**AQAAAA**aAAAAA**6d8JWQ**nY+sHZ2PrBmdj6wVnY+sEZ2...

}

Here you can find a Playground reproducing this code.

AndreaM16
  • 3,917
  • 4
  • 35
  • 74
  • I think your answer is not good solution. I have to encode url. This is best solution, I think. Anyway I appreciate your help.AndreaM – Alakey May 04 '17 at 03:20