mirror of
https://github.com/fatedier/frp.git
synced 2025-08-04 20:49:04 +00:00
use dep instead of glide
This commit is contained in:
12
vendor/github.com/rakyll/statik/.travis.yml
generated
vendored
12
vendor/github.com/rakyll/statik/.travis.yml
generated
vendored
@@ -1,12 +0,0 @@
|
||||
language: go
|
||||
|
||||
go:
|
||||
- 1.1
|
||||
- 1.2
|
||||
- 1.3
|
||||
- 1.4
|
||||
- tip
|
||||
|
||||
install:
|
||||
- go build -v
|
||||
- ./statik -src=./example/public -dest=./example/
|
40
vendor/github.com/rakyll/statik/README.md
generated
vendored
40
vendor/github.com/rakyll/statik/README.md
generated
vendored
@@ -1,40 +0,0 @@
|
||||
# statik
|
||||
|
||||
[](https://travis-ci.org/rakyll/statik)
|
||||
|
||||
statik allows you to embed a directory of static files into your Go binary to be later served from an http.FileSystem.
|
||||
|
||||
Is this a crazy idea? No, not necessarily. If you're building a tool that has a Web component, you typically want to serve some images, CSS and JavaScript. You like the comfort of distributing a single binary, so you don't want to mess with deploying them elsewhere. If your static files are not large in size and will be browsed by a few people, statik is a solution you are looking for.
|
||||
|
||||
## Usage
|
||||
|
||||
Install the command line tool first.
|
||||
|
||||
go get github.com/rakyll/statik
|
||||
|
||||
statik is a tiny program that reads a directory and generates a source file contains its contents. The generated source file registers the directory contents to be used by statik file system.
|
||||
|
||||
The command below will walk on the public path and generate a package called `statik` under the current working directory.
|
||||
|
||||
$ statik -src=/path/to/your/project/public
|
||||
|
||||
In your program, all your need to do is to import the generated package, initialize a new statik file system and serve.
|
||||
|
||||
~~~ go
|
||||
import (
|
||||
"github.com/rakyll/statik/fs"
|
||||
|
||||
_ "./statik" // TODO: Replace with the absolute import path
|
||||
)
|
||||
|
||||
// ...
|
||||
|
||||
statikFS, _ := fs.New()
|
||||
http.ListenAndServe(":8080", http.FileServer(statikFS))
|
||||
~~~
|
||||
|
||||
Visit http://localhost:8080/path/to/file to see your file.
|
||||
|
||||
There is also a working example under [example](https://github.com/rakyll/statik/tree/master/example) directory, follow the instructions to build and run it.
|
||||
|
||||
Note: The idea and the implementation are hijacked from [camlistore](http://camlistore.org/). I decided to decouple it from its codebase due to the fact I'm actively in need of a similar solution for many of my projects. 
|
11
vendor/github.com/rakyll/statik/example/README.md
generated
vendored
11
vendor/github.com/rakyll/statik/example/README.md
generated
vendored
@@ -1,11 +0,0 @@
|
||||
# How to run?
|
||||
|
||||
Run statik on the root of this example project to generate source code with directory contents.
|
||||
|
||||
$ statik
|
||||
|
||||
Once the <projectPath>/statik package is generated, run the web server:
|
||||
|
||||
$ go run main.go
|
||||
|
||||
Visit [http://localhost:8080/public/hello.txt](http://localhost:8080/public/hello.txt) to see the file.
|
22
vendor/github.com/rakyll/statik/example/main.go
generated
vendored
22
vendor/github.com/rakyll/statik/example/main.go
generated
vendored
@@ -1,22 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
_ "github.com/rakyll/statik/example/statik"
|
||||
"github.com/rakyll/statik/fs"
|
||||
)
|
||||
|
||||
// Before buildling, run `statik -src=./public`
|
||||
// to generate the statik package.
|
||||
// Then, run the main program and visit http://localhost:8080/public/hello.txt
|
||||
func main() {
|
||||
statikFS, err := fs.New()
|
||||
if err != nil {
|
||||
log.Fatalf(err.Error())
|
||||
}
|
||||
|
||||
http.Handle("/public/", http.StripPrefix("/public/", http.FileServer(statikFS)))
|
||||
http.ListenAndServe(":8080", nil)
|
||||
}
|
2
vendor/github.com/rakyll/statik/example/public/hello.txt
generated
vendored
2
vendor/github.com/rakyll/statik/example/public/hello.txt
generated
vendored
@@ -1,2 +0,0 @@
|
||||
Hello World
|
||||
|
BIN
vendor/github.com/rakyll/statik/example/public/img/friends.jpg
generated
vendored
BIN
vendor/github.com/rakyll/statik/example/public/img/friends.jpg
generated
vendored
Binary file not shown.
Before Width: | Height: | Size: 68 KiB |
203
vendor/github.com/rakyll/statik/statik.go
generated
vendored
203
vendor/github.com/rakyll/statik/statik.go
generated
vendored
@@ -1,203 +0,0 @@
|
||||
// Copyright 2014 Google Inc. All Rights Reserved.
|
||||
//
|
||||
// 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 contains a program that generates code to register
|
||||
// a directory and its contents as zip data for statik file system.
|
||||
package main
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
namePackage = "statik"
|
||||
nameSourceFile = "statik.go"
|
||||
)
|
||||
|
||||
var (
|
||||
flagSrc = flag.String("src", path.Join(".", "public"), "The path of the source directory.")
|
||||
flagDest = flag.String("dest", ".", "The destination path of the generated package.")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
file, err := generateSource(*flagSrc)
|
||||
if err != nil {
|
||||
exitWithError(err)
|
||||
}
|
||||
|
||||
destDir := path.Join(*flagDest, namePackage)
|
||||
err = os.MkdirAll(destDir, 0755)
|
||||
if err != nil {
|
||||
exitWithError(err)
|
||||
}
|
||||
|
||||
err = rename(file.Name(), path.Join(destDir, nameSourceFile))
|
||||
if err != nil {
|
||||
exitWithError(err)
|
||||
}
|
||||
}
|
||||
|
||||
// rename tries to os.Rename, but fall backs to copying from src
|
||||
// to dest and unlink the source if os.Rename fails.
|
||||
func rename(src, dest string) error {
|
||||
// Try to rename generated source.
|
||||
if err := os.Rename(src, dest); err == nil {
|
||||
return nil
|
||||
}
|
||||
// If the rename failed (might do so due to temporary file residing on a
|
||||
// different device), try to copy byte by byte.
|
||||
rc, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
rc.Close()
|
||||
os.Remove(src) // ignore the error, source is in tmp.
|
||||
}()
|
||||
|
||||
if _, err = os.Stat(dest); !os.IsNotExist(err) {
|
||||
return fmt.Errorf("file %q already exists", dest)
|
||||
}
|
||||
|
||||
wc, err := os.Create(dest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer wc.Close()
|
||||
|
||||
if _, err = io.Copy(wc, rc); err != nil {
|
||||
// Delete remains of failed copy attempt.
|
||||
os.Remove(dest)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Walks on the source path and generates source code
|
||||
// that contains source directory's contents as zip contents.
|
||||
// Generates source registers generated zip contents data to
|
||||
// be read by the statik/fs HTTP file system.
|
||||
func generateSource(srcPath string) (file *os.File, err error) {
|
||||
var (
|
||||
buffer bytes.Buffer
|
||||
zipWriter io.Writer
|
||||
)
|
||||
|
||||
zipWriter = &buffer
|
||||
f, err := ioutil.TempFile("", namePackage)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
zipWriter = io.MultiWriter(zipWriter, f)
|
||||
defer f.Close()
|
||||
|
||||
w := zip.NewWriter(zipWriter)
|
||||
if err = filepath.Walk(srcPath, func(path string, fi os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Ignore directories and hidden files.
|
||||
// No entry is needed for directories in a zip file.
|
||||
// Each file is represented with a path, no directory
|
||||
// entities are required to build the hierarchy.
|
||||
if fi.IsDir() || strings.HasPrefix(fi.Name(), ".") {
|
||||
return nil
|
||||
}
|
||||
relPath, err := filepath.Rel(srcPath, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
b, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fHeader, err := zip.FileInfoHeader(fi)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fHeader.Name = filepath.ToSlash(relPath)
|
||||
f, err := w.CreateHeader(fHeader)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = f.Write(b)
|
||||
return err
|
||||
}); err != nil {
|
||||
return
|
||||
}
|
||||
if err = w.Close(); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// then embed it as a quoted string
|
||||
var qb bytes.Buffer
|
||||
fmt.Fprintf(&qb, `package %s
|
||||
|
||||
import (
|
||||
"github.com/rakyll/statik/fs"
|
||||
)
|
||||
|
||||
func init() {
|
||||
data := "`, namePackage)
|
||||
FprintZipData(&qb, buffer.Bytes())
|
||||
fmt.Fprint(&qb, `"
|
||||
fs.Register(data)
|
||||
}
|
||||
`)
|
||||
|
||||
if err = ioutil.WriteFile(f.Name(), qb.Bytes(), 0644); err != nil {
|
||||
return
|
||||
}
|
||||
return f, nil
|
||||
}
|
||||
|
||||
// Converts zip binary contents to a string literal.
|
||||
func FprintZipData(dest *bytes.Buffer, zipData []byte) {
|
||||
for _, b := range zipData {
|
||||
if b == '\n' {
|
||||
dest.WriteString(`\n`)
|
||||
continue
|
||||
}
|
||||
if b == '\\' {
|
||||
dest.WriteString(`\\`)
|
||||
continue
|
||||
}
|
||||
if b == '"' {
|
||||
dest.WriteString(`\"`)
|
||||
continue
|
||||
}
|
||||
if (b >= 32 && b <= 126) || b == '\t' {
|
||||
dest.WriteByte(b)
|
||||
continue
|
||||
}
|
||||
fmt.Fprintf(dest, "\\x%02x", b)
|
||||
}
|
||||
}
|
||||
|
||||
// Prints out the error message and exists with a non-success signal.
|
||||
func exitWithError(err error) {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
Reference in New Issue
Block a user