I am trying to decrypt a string that contains the variables of my structure. I want my variables in my string to be replaced by the correct value after decryption.
My result is that I get the string with the variables and not replaced by their value.
How to do that ?
Here is my code.
type (
Test struct {
Login string `form:"login"`
Email string `form:"email"`
Age string `form:"age"`
})
Inside my function
tst:= Test{}
textToEncrypt :=
"login:tst.Login;email:tst.Email;timestampunix:1563804616"
textEncrypted := service.EncryptText(textToEncrypt, keysToEncrypt)
After he encrypt, I have an encrypt string, until here it's OK.
When I call my Decrypt Function, he return the string like above , but I want the value of the variable inside the string, the value of the variable struct?
It's possible?
As stated there are not any functions in the standard library to parse your format. It seems that you use semicolons and colons as a delimiter for this format. With that in mind we can create custom code to parse through it.
splitString = strings.Split(str, ";")
example.Login = GetLastIndex(splitString[0])
example.Email = GetLastIndex(splitString[1])
example.Age = GetLastIndex(splitString[2])
func GetLastIndex(str string) string {
return str[strings.LastIndex(str, ":")+1:]
}
Playground example: https://play.golang.org/p/UTrazkQ5EI-