NewClient returns a client for the given host. All communication will be performed over SSL unless the host is localhost.
(host string, client *http.Client)
| 37 | // NewClient returns a client for the given host. All communication will |
| 38 | // be performed over SSL unless the host is localhost. |
| 39 | func NewClient(host string, client *http.Client) (*Client, error) { |
| 40 | // Add an appcfg header to outgoing requests. |
| 41 | wrapClient := new(http.Client) |
| 42 | *wrapClient = *client |
| 43 | t := client.Transport |
| 44 | if t == nil { |
| 45 | t = http.DefaultTransport |
| 46 | } |
| 47 | wrapClient.Transport = &headerAddingRoundTripper{t} |
| 48 | |
| 49 | url := url.URL{ |
| 50 | Scheme: "https", |
| 51 | Host: host, |
| 52 | Path: "/_ah/remote_api", |
| 53 | } |
| 54 | if host == "localhost" || strings.HasPrefix(host, "localhost:") { |
| 55 | url.Scheme = "http" |
| 56 | } |
| 57 | u := url.String() |
| 58 | appID, err := getAppID(wrapClient, u) |
| 59 | if err != nil { |
| 60 | return nil, fmt.Errorf("unable to contact server: %v", err) |
| 61 | } |
| 62 | return &Client{ |
| 63 | hc: wrapClient, |
| 64 | url: u, |
| 65 | appID: appID, |
| 66 | }, nil |
| 67 | } |
| 68 | |
| 69 | // NewContext returns a copy of parent that will cause App Engine API |
| 70 | // calls to be sent to the client's remote host. |
searching dependent graphs…