|
| 1 | +package plumbing |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "log" |
| 6 | + "net/http" |
| 7 | + "net/http/httptest" |
| 8 | + "strings" |
| 9 | + |
| 10 | + "github.com/go-openapi/runtime" |
| 11 | + httptransport "github.com/go-openapi/runtime/client" |
| 12 | + "github.com/go-openapi/strfmt" |
| 13 | + "github.com/netlify/open-api/go/plumbing/operations" |
| 14 | +) |
| 15 | + |
| 16 | +func Example() { |
| 17 | + server := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { |
| 18 | + rw.Header().Set("Content-Type", "application/json; charset=utf-8") |
| 19 | + rw.Write([]byte(`{ "name": "Pets of Netlify" }`)) |
| 20 | + })) |
| 21 | + defer server.Close() |
| 22 | + host := strings.ReplaceAll(server.URL, "http://", "") |
| 23 | + |
| 24 | + // Create the API client |
| 25 | + // For Netlify's production API use DefaultHost, DefaultBasePath, DefaultSchemes |
| 26 | + transport := httptransport.New(host, DefaultBasePath, []string{"http"}) |
| 27 | + client := New(transport, strfmt.Default) |
| 28 | + |
| 29 | + // Prepare the API token |
| 30 | + authInfo := runtime.ClientAuthInfoWriterFunc(func(r runtime.ClientRequest, _ strfmt.Registry) error { |
| 31 | + r.SetHeaderParam("User-Agent", "Your app") |
| 32 | + r.SetHeaderParam("Authorization", "Bearer your_netlify_api_token") |
| 33 | + return nil |
| 34 | + }) |
| 35 | + |
| 36 | + // Make a request |
| 37 | + params := operations.NewGetSiteParams() |
| 38 | + params.SiteID = "123" |
| 39 | + res, err := client.Operations.GetSite(params, authInfo) |
| 40 | + if err != nil { |
| 41 | + log.Fatal(err) |
| 42 | + } |
| 43 | + fmt.Println(res.Payload.Name) |
| 44 | + // Output: Pets of Netlify |
| 45 | +} |
0 commit comments