| 349 | } |
| 350 | |
| 351 | func fetchTemplate(ctx context.Context, deps Deps, templateID string) (FetchResult, error) { |
| 352 | parsedID, err := uuid.Parse(templateID) |
| 353 | if err != nil { |
| 354 | return FetchResult{}, xerrors.Errorf("invalid template ID, must be a valid UUID: %w", err) |
| 355 | } |
| 356 | template, err := deps.coderClient.Template(ctx, parsedID) |
| 357 | if err != nil { |
| 358 | return FetchResult{}, err |
| 359 | } |
| 360 | templateJSON, err := json.Marshal(template) |
| 361 | if err != nil { |
| 362 | return FetchResult{}, xerrors.Errorf("failed to marshal template: %w", err) |
| 363 | } |
| 364 | return FetchResult{ |
| 365 | ID: template.ID.String(), |
| 366 | Title: template.DisplayName, |
| 367 | Text: string(templateJSON), |
| 368 | URL: fmt.Sprintf("%s/templates/%s/%s", deps.ServerURL(), template.OrganizationName, template.Name), |
| 369 | }, nil |
| 370 | } |
| 371 | |
| 372 | type FetchArgs struct { |
| 373 | ID string `json:"id"` |