Skip to content

Instantly share code, notes, and snippets.

@nikolaydubina
Created November 7, 2024 15:08
Show Gist options
  • Save nikolaydubina/f472708bb9c614e1737bea9d0257b73f to your computer and use it in GitHub Desktop.
Save nikolaydubina/f472708bb9c614e1737bea9d0257b73f to your computer and use it in GitHub Desktop.
package main
import (
"encoding/base64"
"encoding/json"
"fmt"
)
type X struct {
B []byte `json:"b"`
}
func main() {
s := []byte("hello world")
x := X{
B: make([]byte, base64.StdEncoding.EncodedLen(len(s))),
}
base64.StdEncoding.Encode(x.B, s)
message, _ := json.Marshal(x)
var y X
json.Unmarshal(message, &y)
fmt.Println(string(x.B), string(y.B), string(x.B) == string(y.B))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment