Skip to content

Commit

Permalink
fix: Fix read embed file on windows env
Browse files Browse the repository at this point in the history
  • Loading branch information
LyricTian committed Jan 19, 2024
1 parent 3e48b95 commit e4be9cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
10 changes: 5 additions & 5 deletions internal/actions/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,20 @@ func (a *GenerateAction) run(ctx context.Context, data []*schema.S) error {
return a.execWireAndSwag(ctx)
}

func (a *GenerateAction) getGoTplFile(pkgName, tplType string) string {
pkgName = fmt.Sprintf("%s.go.tpl", pkgName)
func (a *GenerateAction) getGoTplFile(tplName, tplType string) string {
tplName = fmt.Sprintf("%s.go.tpl", tplName)
if tplType == "" && a.cfg.TplType != "" {
tplType = a.cfg.TplType
}

if tplType != "" {
p := filepath.Join(tplType, pkgName)
p := filepath.Join(tplType, tplName)
if ok, _ := utils.ExistsFile(p); ok {
return p
}
return filepath.Join("default", pkgName)
return filepath.Join("default", tplName)
}
return pkgName
return tplName
}

func (a GenerateAction) getAbsPath(file string) (string, error) {
Expand Down
8 changes: 7 additions & 1 deletion internal/tfs/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package tfs
import (
"embed"
"path/filepath"
"runtime"
"strings"
)

var efsIns embed.FS
Expand All @@ -23,7 +25,11 @@ func NewEmbedFS() FS {
}

func (fs *embedFS) ReadFile(name string) ([]byte, error) {
return efsIns.ReadFile(filepath.Join("tpls", name))
fullname := filepath.Join("tpls", name)
if runtime.GOOS == "windows" {
fullname = strings.ReplaceAll(fullname, "\\", "/")
}
return efsIns.ReadFile(fullname)
}

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

0 comments on commit e4be9cc

Please sign in to comment.