Skip to content

Commit e4be9cc

Browse files
committed
fix: Fix read embed file on windows env
1 parent 3e48b95 commit e4be9cc

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

internal/actions/generate.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,20 +129,20 @@ func (a *GenerateAction) run(ctx context.Context, data []*schema.S) error {
129129
return a.execWireAndSwag(ctx)
130130
}
131131

132-
func (a *GenerateAction) getGoTplFile(pkgName, tplType string) string {
133-
pkgName = fmt.Sprintf("%s.go.tpl", pkgName)
132+
func (a *GenerateAction) getGoTplFile(tplName, tplType string) string {
133+
tplName = fmt.Sprintf("%s.go.tpl", tplName)
134134
if tplType == "" && a.cfg.TplType != "" {
135135
tplType = a.cfg.TplType
136136
}
137137

138138
if tplType != "" {
139-
p := filepath.Join(tplType, pkgName)
139+
p := filepath.Join(tplType, tplName)
140140
if ok, _ := utils.ExistsFile(p); ok {
141141
return p
142142
}
143-
return filepath.Join("default", pkgName)
143+
return filepath.Join("default", tplName)
144144
}
145-
return pkgName
145+
return tplName
146146
}
147147

148148
func (a GenerateAction) getAbsPath(file string) (string, error) {

internal/tfs/embed.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package tfs
33
import (
44
"embed"
55
"path/filepath"
6+
"runtime"
7+
"strings"
68
)
79

810
var efsIns embed.FS
@@ -23,7 +25,11 @@ func NewEmbedFS() FS {
2325
}
2426

2527
func (fs *embedFS) ReadFile(name string) ([]byte, error) {
26-
return efsIns.ReadFile(filepath.Join("tpls", name))
28+
fullname := filepath.Join("tpls", name)
29+
if runtime.GOOS == "windows" {
30+
fullname = strings.ReplaceAll(fullname, "\\", "/")
31+
}
32+
return efsIns.ReadFile(fullname)
2733
}
2834

2935
func (fs *embedFS) ParseTpl(name string, data interface{}) ([]byte, error) {

0 commit comments

Comments
 (0)