ncw / swift

Go language interface to Swift / Openstack Object Storage / Rackspace cloud files (golang)
MIT License
310 stars 107 forks source link

Allow extra headers of HEAD request for container/object requests. #178

Open charz opened 1 year ago

charz commented 1 year ago

Hi team,

I'd like to add headers support for HEAD requests that might help in some case like X-Newest: true (https://github.com/ncw/swift/issues/100) or some custom headers.

Thanks!

charz commented 1 year ago

I'm not sure why go1.17 failed in below,

  Running [/home/runner/golangci-lint-1.49.0-linux-amd64/golangci-lint run --out-format=github-actions] in [] ...
  Error: File is not `goimports`-ed (goimports)
  Error: File is not `goimports`-ed (goimports)
  Error: File is not `goimports`-ed (goimports)
  Error: File is not `goimports`-ed (goimports)
  Error: File is not `goimports`-ed (goimports)
  Error: File is not `goimports`-ed (goimports)

I tried to run golangci-lint looks fine in my end.

➜  charz_ncw_swift git:(add_headers_for_HEAD_container_object) ~/go/bin/golangci-lint run --fix                                         
WARN [runner] The linter 'structcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused. 
WARN [runner] The linter 'varcheck' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused. 
WARN [runner] The linter 'deadcode' is deprecated (since v1.49.0) due to: The owner seems to have abandoned the linter.  Replaced by unused. 

➜  charz_ncw_swift git:(add_headers_for_HEAD_container_object) go version
go version go1.18.3 darwin/arm64
charz commented 1 year ago

Just add two extraheaders for container and object in connection structure. Do you think that make sense?

ncw commented 1 year ago

I'd prefer new functions with extra parameters otherwise you create a global state which will be difficult to share between threads.

charz commented 1 year ago

I'd prefer new functions with extra parameters otherwise you create a global state which will be difficult to share between threads.

Do you mean something likes this?

func (c *Connection) ContainerWithHeaders(ctx context.Context, container string, h Headers) (info Container, headers Headers, err error) 
func (c *Connection) ObjectWithHeaders(ctx context.Context, container string, objectName string, h Headers) (info Object, headers Headers, err error)