Skip to content

Commit f538b26

Browse files
authored
Merge pull request #3 from tomtwinkle/fix/include-go-files
Fixes to embed Go files
2 parents 7e05519 + c4dddda commit f538b26

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ package main
22

33
import (
44
"context"
5+
"embed"
56
"fmt"
67

78
"github.com/sqlc-dev/plugin-sdk-go/codegen"
89
"github.com/sqlc-dev/plugin-sdk-go/plugin"
910
)
1011

12+
//go:embed templates/*
13+
var templates embed.FS
14+
1115
const (
1216
generateFileName = "bulk.sql.go"
1317

parser.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ import (
55
"go/ast"
66
"go/parser"
77
"go/token"
8-
"os"
98
)
109

1110
// parseGoCode parses a Go source file and extracts the code of a specific function by its name.
1211
// It returns the function code as a byte slice or an error if the function is not found.
1312
func parseGoCode(sourceFile string, targetFuncName string) ([]byte, error) {
14-
srcBytes, err := os.ReadFile(sourceFile)
13+
srcBytes, err := templates.ReadFile(sourceFile)
1514
if err != nil {
1615
return nil, err
1716
}

template.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bufio"
55
"bytes"
66
"context"
7-
"embed"
87
"fmt"
98
"go/format"
109
"strconv"
@@ -14,9 +13,6 @@ import (
1413
"github.com/sqlc-dev/plugin-sdk-go/sdk"
1514
)
1615

17-
//go:embed templates/*
18-
var templates embed.FS
19-
2016
func executeTemplate(
2117
_ context.Context, templateName string, data any,
2218
) ([]byte, error) {

0 commit comments

Comments
 (0)