Skip to content

Commit

Permalink
Merge pull request #21 from TianTianBigWang/me-main
Browse files Browse the repository at this point in the history
fix embed file path for windows
  • Loading branch information
zc2638 authored Nov 24, 2022
2 parents 8b70bac + 2b72480 commit 120ca5a
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func main() {
currentPath := strings.TrimPrefix(string(ctx.Path()), "/swagger/ui")

if currentPath == "/" || currentPath == "index.html" {
fullName := filepath.Join(asserts.DistDir, "index.html")
fullName := path.Join(asserts.DistDir, "index.html")
fileData, err := asserts.Dist.ReadFile(fullName)
if err != nil {
ctx.Error("index.html read exception", http.StatusInternalServerError)
Expand Down
2 changes: 1 addition & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func main() {
currentPath := strings.TrimPrefix(string(ctx.Path()), "/swagger/ui")

if currentPath == "/" || currentPath == "index.html" {
fullName := filepath.Join(asserts.DistDir, "index.html")
fullName := path.Join(asserts.DistDir, "index.html")
fileData, err := asserts.Dist.ReadFile(fullName)
if err != nil {
ctx.Error("index.html read exception", http.StatusInternalServerError)
Expand Down
3 changes: 1 addition & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"io"
"net/http"
"path"
"path/filepath"
"reflect"
"strings"

Expand Down Expand Up @@ -403,7 +402,7 @@ func UIHandler(prefix, uri string, autoDomain bool) http.Handler {
return
}
if r.URL.Path == "/" || r.URL.Path == "index.html" {
fullName := filepath.Join(asserts.DistDir, "index.html")
fullName := path.Join(asserts.DistDir, "index.html")
fileData, err := asserts.Dist.ReadFile(fullName)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
Expand Down
4 changes: 2 additions & 2 deletions fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package swag
import (
"io/fs"
"net/http"
"path/filepath"
"path"
)

// DirFS returns a http.FileSystem by the specified directory path and FS
Expand All @@ -34,5 +34,5 @@ type dirFS struct {
}

func (f dirFS) Open(name string) (http.File, error) {
return f.fs.Open(filepath.Join(f.dir, name))
return f.fs.Open(path.Join(f.dir, name))
}
4 changes: 2 additions & 2 deletions fs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"io/fs"
"net/http"
"path/filepath"
"path"
"testing"

"github.com/zc2638/swag/asserts"
Expand Down Expand Up @@ -44,7 +44,7 @@ func TestDirFS(t *testing.T) {
}

func Test_dirFS_Open(t *testing.T) {
file, err := http.FS(asserts.Dist).Open(filepath.Join(asserts.DistDir, "index.html"))
file, err := http.FS(asserts.Dist).Open(path.Join(asserts.DistDir, "index.html"))
if err != nil {
t.Errorf("open asserts failed: %v", err)
}
Expand Down

0 comments on commit 120ca5a

Please sign in to comment.