tree: 70a00f40af4df279184dcbccdcda7def7f0dae17 [path history] [tgz]
  1. about.go
  2. acme.go
  3. api_capability.go
  4. asn.go
  5. async_status.go
  6. cachegroup.go
  7. capability.go
  8. cdn.go
  9. cdn_dnssec.go
  10. cdn_domains.go
  11. cdn_lock.go
  12. cdn_notifications.go
  13. cdnfederations.go
  14. coordinate.go
  15. crconfig.go
  16. deliveryservice.go
  17. deliveryservice_regexes.go
  18. deliveryservice_request_comments.go
  19. deliveryservice_requests.go
  20. deliveryservices_required_capabilities.go
  21. deliveryserviceserver.go
  22. division.go
  23. endpoints.go
  24. federation.go
  25. federation_federation_resolver.go
  26. federation_resolver.go
  27. iso.go
  28. job.go
  29. log.go
  30. origin.go
  31. parameter.go
  32. phys_location.go
  33. ping.go
  34. profile.go
  35. profile_parameter.go
  36. README.md
  37. region.go
  38. role.go
  39. server.go
  40. server_server_capabilities.go
  41. server_update_status.go
  42. servercapability.go
  43. servercheck.go
  44. servercheckextensions.go
  45. serviceCategory.go
  46. session.go
  47. staticdnsentry.go
  48. stats_summary.go
  49. status.go
  50. steering.go
  51. steeringtarget.go
  52. tenant.go
  53. topology.go
  54. topology_queue_updates.go
  55. traffic_monitor.go
  56. traffic_stats.go
  57. type.go
  58. user.go
  59. vault.go
traffic_ops/v4-client/README.md

Traffic Ops Go Client

Unstable

The version of the Traffic Ops API for which this client was made is unstable, meaning that breaking changes to it - and to this client - can occur at any time. Use at your own peril!

Getting Started

  1. Obtain the latest version of the library

go get github.com/apache/trafficcontrol/traffic_ops/v4-client

  1. Get a basic TO session started and fetch a list of CDNs
package main

import (
	"fmt"
	"os"
	"time"

	"github.com/apache/trafficcontrol/lib/go-tc"
	toclient "github.com/apache/trafficcontrol/traffic_ops/v4-client"
)

const TOURL = "http://localhost"
const TOUser = "user"
const TOPassword = "password"
const AllowInsecureConnections = true
const UserAgent = "MySampleApp"
const UseClientCache = false
const TrafficOpsRequestTimeout = time.Second * time.Duration(10)

func main() {
	session, remoteaddr, err := toclient.LoginWithAgent(
		TOURL,
		TOUser,
		TOPassword,
		AllowInsecureConnections,
		UserAgent,
		UseClientCache,
		TrafficOpsRequestTimeout)
	if err != nil {
		fmt.Printf("An error occurred while logging in:\n\t%v\n", err)
		os.Exit(1)
	}
	fmt.Println("Connected to: " + remoteaddr.String())
	var cdns []tc.CDN
	cdns, _, err = session.GetCDNs(nil)
	if err != nil {
		fmt.Printf("An error occurred while getting cdns:\n\t%v\n", err)
		os.Exit(1)
	}
	for _, cdn := range cdns {
		fmt.Println(cdn.Name)
	}
}