1 Star 0 Fork 0

node/frp

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
assets.go 1.73 KB
一键复制 编辑 原始数据 按行查看 历史
node 提交于 2024-10-01 21:37 +08:00 . 仓库修改名称
// Copyright 2016 fatedier, fatedier@gmail.com
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package assets
//go:generate statik -src=./static
//go:generate go fmt statik/statik.go
import (
"io/ioutil"
"net/http"
"os"
"path"
"github.com/rakyll/statik/fs"
_ "gitee.com/oscliaoxin/frp/src/assets/statik"
)
var (
// store static files in memory by statik
FileSystem http.FileSystem
// if prefix is not empty, we get file content from disk
prefixPath string
)
// if path is empty, load assets in memory
// or set FileSystem using disk files
func Load(path string) (err error) {
prefixPath = path
if prefixPath != "" {
FileSystem = http.Dir(prefixPath)
return nil
} else {
FileSystem, err = fs.New()
}
return err
}
func ReadFile(file string) (content string, err error) {
if prefixPath == "" {
file, err := FileSystem.Open(path.Join("/", file))
if err != nil {
return content, err
}
buf, err := ioutil.ReadAll(file)
if err != nil {
return content, err
}
content = string(buf)
} else {
file, err := os.Open(path.Join(prefixPath, file))
if err != nil {
return content, err
}
buf, err := ioutil.ReadAll(file)
if err != nil {
return content, err
}
content = string(buf)
}
return content, err
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/oscliaoxin/frp.git
git@gitee.com:oscliaoxin/frp.git
oscliaoxin
frp
frp
bd20790c1033

搜索帮助