github.com/1and1/oneandone-cloudserver-sdk-go@v1.4.1/logs.go (about)

     1  package oneandone
     2  
     3  import (
     4  	"net/http"
     5  	"time"
     6  )
     7  
     8  type Log struct {
     9  	ApiPtr
    10  	idField
    11  	typeField
    12  	SiteId    string    `json:"site_id,omitempty"`
    13  	StartDate string    `json:"start_date,omitempty"`
    14  	EndDate   string    `json:"end_date,omitempty"`
    15  	Action    string    `json:"action,omitempty"`
    16  	Duration  int       `json:"duration"`
    17  	Status    *Status   `json:"Status,omitempty"`
    18  	Resource  *Identity `json:"resource,omitempty"`
    19  	User      *Identity `json:"user,omitempty"`
    20  }
    21  
    22  // GET /logs
    23  func (api *API) ListLogs(period string, sd *time.Time, ed *time.Time, args ...interface{}) ([]Log, error) {
    24  	result := []Log{}
    25  	url, err := processQueryParamsExt(createUrl(api, logPathSegment), period, sd, ed, args...)
    26  	if err != nil {
    27  		return nil, err
    28  	}
    29  	err = api.Client.Get(url, &result, http.StatusOK)
    30  	if err != nil {
    31  		return nil, err
    32  	}
    33  	for index, _ := range result {
    34  		result[index].api = api
    35  	}
    36  	return result, nil
    37  }
    38  
    39  // GET /logs/{id}
    40  func (api *API) GetLog(log_id string) (*Log, error) {
    41  	result := new(Log)
    42  	url := createUrl(api, logPathSegment, log_id)
    43  	err := api.Client.Get(url, &result, http.StatusOK)
    44  	if err != nil {
    45  		return nil, err
    46  	}
    47  	result.api = api
    48  	return result, nil
    49  }