| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- package client
- import (
- "context"
- "fmt"
- "net/http"
- "github.com/porter-dev/porter/internal/models"
- )
- func (c *Client) ListTemplates(
- ctx context.Context,
- ) ([]*models.PorterChartList, error) {
- req, err := http.NewRequest(
- "GET",
- fmt.Sprintf("%s/templates", c.BaseURL),
- nil,
- )
- if err != nil {
- return nil, err
- }
- req = req.WithContext(ctx)
- bodyResp := make([]*models.PorterChartList, 0)
- if httpErr, err := c.sendRequest(req, &bodyResp, true); httpErr != nil || err != nil {
- if httpErr != nil {
- return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
- }
- return nil, err
- }
- return bodyResp, nil
- }
- func (c *Client) GetTemplate(
- ctx context.Context,
- name, version string,
- ) (*models.PorterChartRead, error) {
- req, err := http.NewRequest(
- "GET",
- fmt.Sprintf("%s/templates/%s/%s", c.BaseURL, name, version),
- nil,
- )
- if err != nil {
- return nil, err
- }
- req = req.WithContext(ctx)
- bodyResp := &models.PorterChartRead{}
- if httpErr, err := c.sendRequest(req, &bodyResp, true); httpErr != nil || err != nil {
- if httpErr != nil {
- return nil, fmt.Errorf("code %d, errors %v", httpErr.Code, httpErr.Errors)
- }
- return nil, err
- }
- return bodyResp, nil
- }
|