Skip to content

Support for parsing json in ObjectNames() #181

Open
@yheonhochoi

Description

@yheonhochoi

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)
	}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions