move api package to sub folder

This commit is contained in:
Samuel Lorch 2021-08-30 14:00:05 +02:00
parent ff29c83d56
commit ff1be787f2
23 changed files with 61 additions and 61 deletions

49
api/resource_types.go Normal file
View file

@ -0,0 +1,49 @@
package api
import (
"context"
"encoding/json"
)
//ResourceType is the Type of a Resource
type ResourceType struct {
ID string `json:"id,omitempty"`
Slug string `json:"slug,omitempty"`
Description string `json:"description,omitempty"`
Definition json.RawMessage `json:"definition,omitempty"`
Created *Time `json:"created,omitempty"`
Modified *Time `json:"modified,omitempty"`
}
type GetResourceTypesOptions struct {
}
// GetResourceTypes gets all Passbolt Resource Types
func (c *Client) GetResourceTypes(ctx context.Context, opts *GetResourceTypesOptions) ([]ResourceType, error) {
msg, err := c.DoCustomRequest(ctx, "GET", "/resource-types.json", "v2", nil, opts)
if err != nil {
return nil, err
}
var types []ResourceType
err = json.Unmarshal(msg.Body, &types)
if err != nil {
return nil, err
}
return types, nil
}
// GetResourceType gets a Passbolt Type
func (c *Client) GetResourceType(ctx context.Context, typeID string) (*ResourceType, error) {
msg, err := c.DoCustomRequest(ctx, "GET", "/resource-types/"+typeID+".json", "v2", nil, nil)
if err != nil {
return nil, err
}
var rType ResourceType
err = json.Unmarshal(msg.Body, &rType)
if err != nil {
return nil, err
}
return &rType, nil
}