forked from fatedier/frp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
assets: use statik to compile static files into binary files
- Loading branch information
Showing
24 changed files
with
474 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2016 fatedier, [email protected] | ||
// | ||
// 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" | ||
|
||
_ "github.com/fatedier/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 | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file not shown.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.