github.com/fastly/go-fastly/v6@v6.8.0/fastly/dictionary_info.go (about)

     1  package fastly
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  )
     7  
     8  // DictionaryInfo represents a dictionary metadata response from the Fastly API.
     9  type DictionaryInfo struct {
    10  	// LastUpdated is the Time-stamp (GMT) when the dictionary was last updated.
    11  	LastUpdated *time.Time `mapstructure:"last_updated"`
    12  
    13  	// Digest is the hash of the dictionary content.
    14  	Digest string `mapstructure:"digest"`
    15  
    16  	// ItemCount is the number of items belonging to the dictionary.
    17  	ItemCount int `mapstructure:"item_count"`
    18  }
    19  
    20  // GetDictionaryInfoInput is used as input to the GetDictionary function.
    21  type GetDictionaryInfoInput struct {
    22  	// ServiceID is the ID of the service Dictionary belongs to (required).
    23  	ServiceID string
    24  
    25  	// ServiceVersion is the specific configuration version (required).
    26  	ServiceVersion int
    27  
    28  	// ID is the alphanumeric string identifying a dictionary.
    29  	ID string
    30  }
    31  
    32  // GetDictionaryInfo gets the dictionary metadata with the given parameters.
    33  func (c *Client) GetDictionaryInfo(i *GetDictionaryInfoInput) (*DictionaryInfo, error) {
    34  	if i.ServiceID == "" {
    35  		return nil, ErrMissingServiceID
    36  	}
    37  
    38  	if i.ServiceVersion == 0 {
    39  		return nil, ErrMissingServiceVersion
    40  	}
    41  
    42  	if i.ID == "" {
    43  		return nil, ErrMissingID
    44  	}
    45  
    46  	path := fmt.Sprintf("/service/%s/version/%d/dictionary/%s/info", i.ServiceID, i.ServiceVersion, i.ID)
    47  	resp, err := c.Get(path, nil)
    48  	if err != nil {
    49  		return nil, err
    50  	}
    51  	defer resp.Body.Close()
    52  
    53  	var b *DictionaryInfo
    54  	if err := decodeBodyMap(resp.Body, &b); err != nil {
    55  		return nil, err
    56  	}
    57  	return b, nil
    58  }