dewrich closed pull request #2264: Add more documentation about the TO Client Libraries URL: https://github.com/apache/incubator-trafficcontrol/pull/2264
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/docs/source/api/traffic_ops_api.rst b/docs/source/api/traffic_ops_api.rst index 2ae61d3cc..0ced0ae2d 100644 --- a/docs/source/api/traffic_ops_api.rst +++ b/docs/source/api/traffic_ops_api.rst @@ -190,3 +190,7 @@ The 3 most common errors returned by Traffic Ops are: The rest of the API documentation will only document the ``200 OK`` case, where no errors have occured. +TrafficOps Native Client Libraries +---------------------------------- + +TrafficOps client libraries are available in both Golang and Python. You can read more about them at https://github.com/apache/incubator-trafficcontrol/tree/master/traffic_control/clients diff --git a/traffic_control/clients/README.md b/traffic_control/clients/README.md new file mode 100644 index 000000000..ec091b4f8 --- /dev/null +++ b/traffic_control/clients/README.md @@ -0,0 +1,18 @@ +#TrafficOps Native Client Libraries + +There are two client libraries supported: + +##Python +* Supported TO API Versions + * 1.1 + * 1.2 +* Documentation + * https://github.com/apache/incubator-trafficcontrol/tree/master/traffic_control/clients/python/trafficops + +##Golang +###TO API v1.2 _(Deprecated)_ +* Documentation + * https://github.com/apache/incubator-trafficcontrol/tree/master/traffic_ops/client +###TO API v1.3 +* Documentation + * https://github.com/apache/incubator-trafficcontrol/tree/master/traffic_ops/client/v13 diff --git a/traffic_ops/client/README.md b/traffic_ops/client/README.md new file mode 100644 index 000000000..8303b1e5f --- /dev/null +++ b/traffic_ops/client/README.md @@ -0,0 +1,54 @@ +#TO Client Library Golang +_This version of the SDK is deprecated in favor of the newer [TO API v1.3 Client Library](https://github.com/apache/incubator-trafficcontrol/tree/master/traffic_ops/client/v13)_ + +##Getting Started +1. Obtain the latest version of the library + +`go get github.com/apache/incubator-trafficcontrol/traffic_ops/client` + +2. Get a basic TO session started and fetch a list of CDNs +```go +package main + +import ( + "fmt" + "os" + "time" + + "github.com/apache/incubator-trafficcontrol/lib/go-tc/v13" + toclient "github.com/apache/incubator-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) + } +} +``` diff --git a/traffic_ops/client/v13/README.md b/traffic_ops/client/v13/README.md new file mode 100644 index 000000000..ea2e147bf --- /dev/null +++ b/traffic_ops/client/v13/README.md @@ -0,0 +1,53 @@ +#TO Client Library Golang + +##Getting Started +1. Obtain the latest version of the library + +`go get github.com/apache/incubator-trafficcontrol/traffic_ops/client/v13` + +2. Get a basic TO session started and fetch a list of CDNs +```go +package main + +import ( + "fmt" + "os" + "time" + + "github.com/apache/incubator-trafficcontrol/lib/go-tc/v13" + toclient "github.com/apache/incubator-trafficcontrol/traffic_ops/client/v13" +) + +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) + } +} +``` ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services