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

Support for parsing json in ObjectNames() #181

Open
yheonhochoi opened this issue May 17, 2023 · 0 comments · May be fixed by #182
Open

Support for parsing json in ObjectNames() #181

yheonhochoi opened this issue May 17, 2023 · 0 comments · May be fixed by #182

Comments

@yheonhochoi
Copy link

yheonhochoi commented May 17, 2023

Now the swifth client assumes ObjectNames are plain for the response and only calls readLines().

The default value of swift is plain, but there are cases where format=json is used, and support for this case is needed.

How about change readJson() or readLines() depending on "Contect-Type" like below?

// ObjectNames returns a slice of names of objects in a given container.
func (c *Connection) ObjectNames(ctx context.Context, container string, opts *ObjectsOpts) ([]string, error) {
	v, h := opts.parse()
	resp, _, err := c.storage(ctx, RequestOpts{
		Container:  container,
		Operation:  "GET",
		Parameters: v,
		ErrorMap:   ContainerErrorMap,
		Headers:    h,
	})
	if err != nil {
		return nil, err
	}
	if resp.Header.Get("Content-Type") == "application/json" {
		var objects []Object
		err := readJson(resp, &objects)

		var names []string
		for _, obj := range objects {
			names = append(names, obj.Name)
		}

		return names, err
	} else {
		return readLines(resp)
	}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant