You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does this issue reproduce with the latest release?
Yes, and works fine with 1.16
What operating system and processor architecture are you using (go env)?
go env Output
$ go env
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\gollaha\AppData\Local\go-build
set GOENV=C:\Users\gollaha\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\gollaha\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=
set GOOS=windows
set GOPATH=C:\Users\gollaha\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.20.2
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=0
set GOMOD=C:\Users\gollaha\Code\personal\rex\rex-cli\go.mod
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=C:\Users\gollaha\AppData\Local\Temp\go-build1860088289=/tmp/go-build -gno-record-gcc-switches
What did you do?
I am trying to convert a struct to base64 string with the following code:
The output should be eyJvdXQiOiJIZWxsbyBXb3JsZCEifQo=
What did you see instead?
Instead, I get eyJvdXQiOiJIZWxsbyBXb3JsZCEi
The reason this is happening is because of the placement of defer encoder.Close(), if you move encoder.Close() after err block in EncodeBase64 it outputs the correct string.
The text was updated successfully, but these errors were encountered:
akshaybabloo
changed the title
encoding/base64:
encoding/base64: shows wrong output
Apr 3, 2023
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, and works fine with 1.16
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I am trying to convert a struct to base64 string with the following code:
Go Play link - https://go.dev/play/p/3liPKR7H0DG <- this shows wrong output
https://go.dev/play/p/r9sXiRSXrwp <- This shows the correct output
What did you expect to see?
The output should be
eyJvdXQiOiJIZWxsbyBXb3JsZCEifQo=
What did you see instead?
Instead, I get
eyJvdXQiOiJIZWxsbyBXb3JsZCEi
The reason this is happening is because of the placement of
defer encoder.Close()
, if you moveencoder.Close()
aftererr
block inEncodeBase64
it outputs the correct string.The text was updated successfully, but these errors were encountered: