Skip to content

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

Closed

Description

@0xc0d

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.

Activity

  1. added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on Jul 15, 2021
  2. self-assigned this
    on Aug 13, 2021
  3. BrennaEpp commented on Aug 13, 2021

    @BrennaEpp
    Contributor

    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

Metadata

Metadata

Labels

api: storageIssues related to the Cloud Storage API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions