url-builder.go 899 B

12345678910111213141516171819202122232425262728
  1. package azuremonitor
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. // URLBuilder builds the URL for calling the Azure Monitor API
  7. type URLBuilder struct {
  8. ResourceGroup string
  9. MetricDefinition string
  10. ResourceName string
  11. }
  12. // Build checks the metric definition property to see which form of the url
  13. // should be returned
  14. func (ub *URLBuilder) Build() string {
  15. if strings.Count(ub.MetricDefinition, "/") > 1 {
  16. rn := strings.Split(ub.ResourceName, "/")
  17. lastIndex := strings.LastIndex(ub.MetricDefinition, "/")
  18. service := ub.MetricDefinition[lastIndex+1:]
  19. md := ub.MetricDefinition[0:lastIndex]
  20. return fmt.Sprintf("resourceGroups/%s/providers/%s/%s/%s/%s/providers/microsoft.insights/metrics", ub.ResourceGroup, md, rn[0], service, rn[1])
  21. }
  22. return fmt.Sprintf("resourceGroups/%s/providers/%s/%s/providers/microsoft.insights/metrics", ub.ResourceGroup, ub.MetricDefinition, ub.ResourceName)
  23. }