edgio-go-sdk

internal/utils

This package package holds some utility functions that are used to outsource some common logic from other packages to avoid repetition/ease testing.

utils.GetHttpJsonResult(httpClient *http.Client, request *http.Request, token string) (map[string]any, error)

This function has mainly three related goals:

  1. Process http requests;
  2. treat HTTP errors in a standardized way, and;
  3. Process and decode returned json data from the endpoints.
type resultType struct { Id string }
var result = resultType{ Id: `json:"id"` }

httpClient := &http.Client{}
request, _ := http.NewRequest(http.MethodGet, client.GetServiceURL(common.URLParams{ Path: "some-org-id" }), nil)

result, err := utils.GetHttpJsonResult(httpClient, request, "some-access-token")

utils.GetHttpJsonResult Mandatory Params

utils.GetHttpJsonResult Optional Params & Default Values

There is no optional parameters for that function

back to the main README

utils.FilterList[T common.Filterable](params common.FilterListParams[T]) []T

Filters the list of items (haystack) by the given needle. Returns a list of items that contain the needle in their name, key or slug, depending on the entity type (Property, Environment, Variable), or an empty list if no items match the needle.

haystack := []common.Variable{
  {Key: "nope"},
  {Key: "not-this"},
  {Key: "this-variable"},
}

filteredProperties := utils.FilterList[common.Variable](
  common.FilterListParams[common.Variable]{Needle: "this-variable", Haystack: haystack},
)

fmt.Println(filteredProperties) // [{ Key: "this-variable" }]

utils.FilterList Mandatory Params

utils.FilterList Optional Params

This func has no optional params.

utils.PrepareJSONBody(body common.HTTPBody) (io.Reader, error)

This function prepares the body body for a HTTP request based on the provided struct.

  someBody, _ := org.PatchBody{Name: "Some New Name"} // '{"name": "Some New Name"}'

utils.PrepareJSONBody Mandatory Params

utils.PrepareJSONBody Optional Params & Default Values

There is no optional parameters for that function

back to the main README