tree: 5498defd0cda3738a0f49c8c20b3830e66eed652 [path history] [tgz]
  1. about.go
  2. asn.go
  3. atsconfig.go
  4. cachegroup.go
  5. cachegroup_parameters.go
  6. cdn.go
  7. cdn_domains.go
  8. cdnfederations.go
  9. coordinate.go
  10. crconfig.go
  11. deliveryservice.go
  12. deliveryservice_endpoints.go
  13. deliveryservice_request_comments.go
  14. deliveryservice_requests.go
  15. deliveryservices_required_capabilities.go
  16. deliveryserviceserver.go
  17. division.go
  18. dsuser.go
  19. endpoints.go
  20. federation.go
  21. federation_resolver.go
  22. hardware.go
  23. iso.go
  24. job.go
  25. log.go
  26. origin.go
  27. parameter.go
  28. phys_location.go
  29. ping.go
  30. profile.go
  31. profile_parameter.go
  32. README.md
  33. region.go
  34. role.go
  35. server.go
  36. server_server_capabilities.go
  37. server_update_status.go
  38. servercapability.go
  39. servercheck.go
  40. serversstatus.go
  41. session.go
  42. staticdnsentry.go
  43. stats_summary.go
  44. status.go
  45. steering.go
  46. steeringtarget.go
  47. tenant.go
  48. tenant_endpoints.go
  49. toextension.go
  50. traffic_monitor.go
  51. traffic_stats.go
  52. type.go
  53. update.go
  54. user.go
  55. util.go
traffic_ops/client/README.md

TO Client Library Golang

Getting Started

  1. Obtain the latest version of the library

go get github.com/apache/trafficcontrol/traffic_ops/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/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 []v13.CDN
	cdns, _, err = session.GetCDNs()
	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)
	}
}