diff options
author | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-09-03 14:55:23 +0200 |
---|---|---|
committer | Gabriel Arakaki Giovanini <mail@gabrielgio.me> | 2023-09-03 14:55:23 +0200 |
commit | 3b21449468a1b20b3ff706fe00a04556a804e627 (patch) | |
tree | 8054ddc0f47f5731aa89ecb65b962da75a56bdaa /main.go | |
parent | 1507d12b6398448c53bdffe18a32018a3ef627e7 (diff) | |
download | apkdoc-3b21449468a1b20b3ff706fe00a04556a804e627.tar.gz apkdoc-3b21449468a1b20b3ff706fe00a04556a804e627.tar.bz2 apkdoc-3b21449468a1b20b3ff706fe00a04556a804e627.zip |
ref: Remove quicktemplate
This is done in preparation to use text-html/template. This will allow
the user to input their own template file
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 48 |
1 files changed, 31 insertions, 17 deletions
@@ -5,28 +5,15 @@ import ( "bufio" "compress/gzip" "errors" + "fmt" "io" "net/http" "os" "git.sr.ht/~gabrielgio/apkdoc/parser" - "git.sr.ht/~gabrielgio/apkdoc/templates" flag "github.com/spf13/pflag" ) -func fechIndex(url string) (io.ReadCloser, error) { - resp, err := http.Get(url) - if err != nil { - return nil, err - } - - if resp.StatusCode != 200 { - return nil, errors.New("Invlid response") - } - - return resp.Body, nil -} - func main() { url := flag.StringP("url", "u", "", "Url to the APKINDEX.tar.gz") output := flag.StringP("output", "o", "index.md", "Output path") @@ -74,10 +61,37 @@ func main() { } } - file, err := os.Create(*output) + outputFile, err := getOutputFile(*output) + if err != nil { + panic("Error openning output file: " + err.Error()) + } + + for _, e := range entries { + fmt.Fprintln(outputFile, e.FomartLink(*repositoryFormat)) + } +} + +func getOutputFile(output string) (*os.File, error) { + if output == "" { + outputFile, err := os.Create(output) + if err != nil { + return nil, err + } + return outputFile, nil + } else { + return os.Stdout, nil + } +} + +func fechIndex(url string) (io.ReadCloser, error) { + resp, err := http.Get(url) if err != nil { - panic("Error opening output file: " + err.Error()) + return nil, err + } + + if resp.StatusCode != 200 { + return nil, errors.New("Invlid response") } - templates.WriteMarkdownTemplate(file, entries, *repositoryFormat) + return resp.Body, nil } |