# README
Traffic Ops Go Client
Getting Started
- Obtain the latest version of the library
go get github.com/apache/trafficcontrol/v8/traffic_ops/v4-client
- Get a basic TO session started and fetch a list of CDNs
package main
import (
"fmt"
"os"
"time"
"github.com/apache/trafficcontrol/v8/lib/go-tc"
toclient "github.com/apache/trafficcontrol/v8/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)
}
}
# Functions
Login authenticates with Traffic Ops and returns the client object.
LoginWithAgent creates a new authenticated session with a Traffic Ops server.
LoginWithToken functions identically to LoginWithAgent, but uses token-based authentication rather than a username/password pair.
LogoutWithAgent constructs an authenticated Session - exactly like LoginWithAgent - and then immediately calls the '/logout' API endpoint to end the session.
NewNoAuthSession returns a new Session without logging in.
NewRequestOptions returns a RequestOptions object with initialized, empty Header and QueryParameters.
NewSession constructs a new, unauthenticated Session using the provided information.
# Constants
Supported query string parameter names.
Supported query string parameter names.
# Structs
Options is the options to configure the creation of the Client.
OuterResponse is the most basic type of a Traffic Ops API response, containing some kind of JSON-encoded 'response' object.
PingResponse is the type of a response from Traffic Ops to a requestt made to its /ping API endpoint.
RequestOptions is the set of options commonly available to pass to methods of a Session.
Session is a Traffic Ops client.
# Type aliases
UserCurrentResponseV4 is an alias to avoid client breaking changes.