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