github.com/akamai/AkamaiOPEN-edgegrid-golang/v8@v8.1.0/pkg/appsec/failover_hostnames.go (about)

     1  package appsec
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  	"net/http"
     7  )
     8  
     9  type (
    10  	// The FailoverHostnames interface supports retrieving the failover hostnames in a configuration.
    11  	FailoverHostnames interface {
    12  		// GetFailoverHostnames returns a list of the failover hostnames in a configuration.
    13  		//
    14  		// See: https://techdocs.akamai.com/application-security/reference/get-failover-hostnames
    15  		GetFailoverHostnames(ctx context.Context, params GetFailoverHostnamesRequest) (*GetFailoverHostnamesResponse, error)
    16  	}
    17  
    18  	// GetFailoverHostnamesRequest is used to retrieve the failover hostnames for a configuration.
    19  	GetFailoverHostnamesRequest struct {
    20  		ConfigID int `json:"-"`
    21  	}
    22  
    23  	// GetFailoverHostnamesResponse is returned from a call to GetFailoverHostnames.
    24  	GetFailoverHostnamesResponse struct {
    25  		ConfigID      int `json:"-"`
    26  		ConfigVersion int `json:"-"`
    27  		HostnameList  []struct {
    28  			Hostname string `json:"hostname"`
    29  		} `json:"hostnameList"`
    30  	}
    31  )
    32  
    33  func (p *appsec) GetFailoverHostnames(ctx context.Context, params GetFailoverHostnamesRequest) (*GetFailoverHostnamesResponse, error) {
    34  	logger := p.Log(ctx)
    35  	logger.Debug("GetFailoverHostnames")
    36  
    37  	uri := fmt.Sprintf(
    38  		"/appsec/v1/configs/%d/failover-hostnames",
    39  		params.ConfigID,
    40  	)
    41  
    42  	req, err := http.NewRequestWithContext(ctx, http.MethodGet, uri, nil)
    43  	if err != nil {
    44  		return nil, fmt.Errorf("failed to create GetFailoverHostnames request: %w", err)
    45  	}
    46  
    47  	var result GetFailoverHostnamesResponse
    48  	resp, err := p.Exec(req, &result)
    49  	if err != nil {
    50  		return nil, fmt.Errorf("get failover hostnames request failed: %w", err)
    51  	}
    52  	if resp.StatusCode != http.StatusOK {
    53  		return nil, p.Error(resp)
    54  	}
    55  
    56  	return &result, nil
    57  }