tree: 8bd95a037f7b54ffea1eb15e27cc13937a878671
  1. about.go
  2. asn.go
  3. cachegroup.go
  4. cdn.go
  5. cdn_domains.go
  6. cdnfederations.go
  7. coordinate.go
  8. crconfig.go
  9. deliveryservice.go
  10. deliveryservice_endpoints.go
  11. deliveryservice_request_comments.go
  12. deliveryservice_requests.go
  13. deliveryserviceserver.go
  14. division.go
  15. dsuser.go
  16. endpoints.go
  17. hardware.go
  18. origin.go
  19. parameter.go
  20. phys_location.go
  21. ping.go
  22. profile.go
  23. profile_parameter.go
  24. README.md
  25. region.go
  26. role.go
  27. server.go
  28. session.go
  29. staticdnsentry.go
  30. stats_summary.go
  31. status.go
  32. steeringtarget.go
  33. tenant.go
  34. tenant_endpoints.go
  35. traffic_monitor.go
  36. type.go
  37. update.go
  38. user.go
  39. 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)
	}
}