From 231038af6680f3e81fb9518c8ea05d7aaf41155d Mon Sep 17 00:00:00 2001 From: Tom Haile Date: Mon, 20 Nov 2023 15:20:45 -0700 Subject: [PATCH] reduce dup code and user flixkit's get flix file given a url --- internal/super/flix.go | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/internal/super/flix.go b/internal/super/flix.go index 0a444c9f8..786955240 100644 --- a/internal/super/flix.go +++ b/internal/super/flix.go @@ -23,8 +23,6 @@ import ( "encoding/hex" "encoding/json" "fmt" - "io" - "net/http" "net/url" "os" "path/filepath" @@ -319,22 +317,11 @@ func getTemplate(state *flowkit.State, flixService flixkit.FlixService, flixQuer return nil, fmt.Errorf("could not parse flix from file %s: %w", flixQuery, err) } case flixUrl: - resp, err := http.Get(flixQuery) + flixString, err := flixkit.FetchFlixWithContext(ctx, flixQuery) if err != nil { return nil, fmt.Errorf("could not parse flix from url %s: %w", flixQuery, err) } - defer resp.Body.Close() - - if resp.StatusCode != http.StatusOK { - return nil, fmt.Errorf("server returned non-200 status code %w", resp.StatusCode) - } - - body, err := io.ReadAll(resp.Body) - if err != nil { - return nil, err - } - - template, err = flixkit.ParseFlix(string(body)) + template, err = flixkit.ParseFlix(flixString) if err != nil { return nil, fmt.Errorf("could not parse flix from url %s: %w", flixQuery, err) }