Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storage: empty readHost when STORAGE_EMULATOR_HOST is set to host:port #4444

Closed
0xc0d opened this issue Jul 15, 2021 · 1 comment · Fixed by #4616
Closed

Storage: empty readHost when STORAGE_EMULATOR_HOST is set to host:port #4444

0xc0d opened this issue Jul 15, 2021 · 1 comment · Fixed by #4616
Assignees
Labels
api: storage Issues related to the Cloud Storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@0xc0d
Copy link

0xc0d commented Jul 15, 2021

Client

Storage

Environment

Darwin Kernel Version 20.5.0

Go Environment

$ go version

go version go1.16 darwin/amd64

$ go env

GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOOS="darwin"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOVCS=""
GOVERSION="go1.16"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/_r/pyfmdgr15fz3_x7hhfk7gb3r0000gp/T/go-build2794454919=/tmp/go-build -gno-record-gcc-switches -fno-common"

Code

package main

func main() {
	os.Setenv("STORAGE_EMULATOR_HOST", "localhost:4444")
	client, err := storage.NewClient(ctx)
	if err != nil {
		log.Fatal(err)
	}

	r, err := client.Bucket("bucket").Object("object").NewReader(context.TODO())
	if err != nil {
		log.Fatal(err)
	}
}

Expected behavior

return a reader to the object.

Actual behavior

Fatal with error: http: no Host in request URL,
URL: http:///bucket/object

Additional context

I believe this happens after this call. since WithEndpoint and WithDefaultEndpoint have different behaviour inside this function. There might be a modification there.

@0xc0d 0xc0d added the triage me I really want to be triaged. label Jul 15, 2021
@product-auto-label product-auto-label bot added the api: storage Issues related to the Cloud Storage API. label Jul 15, 2021
@unforced unforced added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Jul 15, 2021
@yoshi-automation yoshi-automation removed the triage me I really want to be triaged. label Jul 20, 2021
@BrennaEpp BrennaEpp self-assigned this Aug 13, 2021
@BrennaEpp
Copy link
Contributor

BrennaEpp commented Aug 13, 2021

Hi @0xc0d, to use an emulator with the Go Storage Client you must set STORAGE_EMULATOR_HOST and manually supply the endpoint to the client as such:

client, err := storage.NewClient(context.Background(), option.WithEndpoint(EMULATOR_HOST+"/storage/v1/"))

However, I have linked a PR that will allow your code to work - the emulator will be set as the default endpoint for you. I added a test case for this as well. Please reopen if you continue having this issue once that is merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
5 participants