ShadowEditor/server/server/map_path.go
2020-05-09 21:32:15 +08:00

26 lines
694 B
Go

// Copyright 2017-2020 The ShadowEditor Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
//
// For more information, please visit: https://github.com/tengge1/ShadowEditor
// You can also visit: https://gitee.com/tengge1/ShadowEditor
package server
import (
"path/filepath"
"strings"
)
// MapPath convert a relative path to physical absolute path.
func MapPath(path string) string {
if !strings.HasPrefix(path, "/") {
path = "/" + path
}
if path == "/" {
path = "/index.html"
}
path = filepath.Join(Config.Path.PublicDir, path)
return strings.ReplaceAll(path, "/", string(filepath.Separator))
}