File size: 716 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main

import (
	"archive/zip"
	"fmt"
	"path/filepath"
	"runtime"
)

func getSqlc(version, output string) error {
	url := fmt.Sprintf("https://github.com/kyleconroy/sqlc/releases/download/v%s/sqlc_%s_%s_%s.zip",
		version, version, runtime.GOOS, runtime.GOARCH,
	)
	fd, n, err := fetchFile(url)
	if err != nil {
		return fmt.Errorf("fetch: %w", err)
	}
	defer fd.Close()

	name := "sqlc"
	if runtime.GOOS == "windows" {
		name += ".exe"
	}

	outDir := filepath.Dir(output)
	z, err := zip.NewReader(fd, n)
	if err != nil {
		return fmt.Errorf("unzip: %w", err)
	}

	err = extractFromZip(z, name, filepath.Join(outDir, name), true)
	if err != nil {
		return fmt.Errorf("extract bin: %w", err)
	}

	return nil
}