Skip to content

Commit

Permalink
fix: code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jskelin authored and warber committed Jul 23, 2024
1 parent 0fb5b69 commit cecc5fc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 25 deletions.
16 changes: 16 additions & 0 deletions api/multipart_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* @license
* Copyright 2024 Dynatrace LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package api_test

import (
Expand Down
30 changes: 5 additions & 25 deletions clients/documents/documents.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,7 @@ func NewClient(client *rest.Client) *Client {
// Response contains the API response
type Response struct {
api.Response
documentMetadata
}

type documentMetadata struct {
ID string `json:"id"`
ExternalID string `json:"externalId"`
Actor string `json:"actor"`
Owner string `json:"owner"`
Name string `json:"name"`
Type string `json:"type"`
Version int `json:"version"`
IsPrivate bool `json:"isPrivate"`
}

func unmarshallMetadata(b []byte) (documentMetadata, error) {
var m documentMetadata
if err := json.Unmarshal(b, &m); err != nil {
return documentMetadata{}, err
}

return m, nil
Metadata
}

// ListResponse is a list of API Responses
Expand Down Expand Up @@ -230,8 +210,8 @@ func (c Client) Create(ctx context.Context, name string, isPrivate bool, externa
return api.Response{}, err
}

var md documentMetadata
if md, err = unmarshallMetadata(resp.Data); err != nil {
var md Metadata
if md, err = UnmarshallMetadata(resp.Data); err != nil {
return api.Response{}, err
}

Expand All @@ -257,7 +237,7 @@ func (c Client) Update(ctx context.Context, id string, name string, isPrivate bo
}

part, _ := resp.GetPartWithName("metadata")
md, err := unmarshallMetadata(part.Content)
md, err := UnmarshallMetadata(part.Content)
if err != nil {
return api.Response{}, err
}
Expand All @@ -283,7 +263,7 @@ func (c Client) Delete(ctx context.Context, id string) (api.Response, error) {
}

part, _ := resp.GetPartWithName("metadata")
md, err := unmarshallMetadata(part.Content)
md, err := UnmarshallMetadata(part.Content)
if err != nil {
return api.Response{}, err
}
Expand Down
39 changes: 39 additions & 0 deletions clients/documents/metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* @license
* Copyright 2023 Dynatrace LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package documents

import "encoding/json"

type Metadata struct {
ID string `json:"id"`
ExternalID string `json:"externalId"`
Actor string `json:"actor"`
Owner string `json:"owner"`
Name string `json:"name"`
Type string `json:"type"`
Version int `json:"version"`
IsPrivate bool `json:"isPrivate"`
}

func UnmarshallMetadata(b []byte) (Metadata, error) {
var m Metadata
if err := json.Unmarshal(b, &m); err != nil {
return Metadata{}, err
}

return m, nil
}

0 comments on commit cecc5fc

Please sign in to comment.