mirror of
https://github.com/hamburghammer/gohttpserver.git
synced 2025-03-14 23:35:57 +01:00
support binary standalone now
This commit is contained in:
parent
cbbd084646
commit
acf2d2b467
6 changed files with 59 additions and 8 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -24,3 +24,4 @@ _testmain.go
|
|||
*.prof
|
||||
|
||||
gohttpserver
|
||||
bindata_assetfs.go
|
||||
|
|
18
README.md
18
README.md
|
@ -9,7 +9,7 @@ If using go1.5, ensure you set GO15VENDOREXPERIMENT=1
|
|||
## Features
|
||||
1. [x] Support QRCode code generate
|
||||
1. [x] Breadcrumb path quick change
|
||||
1. [ ] All assets package to Standalone binary
|
||||
1. [x] All assets package to Standalone binary
|
||||
1. [x] Different file type different icon
|
||||
1. [ ] Support show or hide hidden files
|
||||
1. [ ] Upload support
|
||||
|
@ -47,13 +47,25 @@ Listen port 8000 on all interface
|
|||
## Developer Guide
|
||||
Depdencies are managed by godep
|
||||
|
||||
```
|
||||
```sh
|
||||
go get -v github.com/tools/godep
|
||||
go get github.com/jteeuwen/go-bindata/...
|
||||
go get github.com/elazarl/go-bindata-assetfs/...
|
||||
```
|
||||
|
||||
Reference Web sites
|
||||
## How to build single binary release
|
||||
```sh
|
||||
go-bindata-assetfs -tags bindata res/...
|
||||
go build -tags bindata
|
||||
```
|
||||
|
||||
That's all. ^_^
|
||||
|
||||
## Reference Web sites
|
||||
|
||||
* <https://vuejs.org.cn/>
|
||||
* Icon from <http://www.easyicon.net/558394-file_explorer_icon.html>
|
||||
* <https://github.com/elazarl/go-bindata-assetfs>
|
||||
|
||||
## LICENSE
|
||||
This project is under license [MIT](LICENSE)
|
||||
|
|
|
@ -2,7 +2,6 @@ package main
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
|
@ -41,10 +40,11 @@ func (s *HTTPStaticServer) hIndex(w http.ResponseWriter, r *http.Request) {
|
|||
relPath := filepath.Join(s.Root, path)
|
||||
finfo, err := os.Stat(relPath)
|
||||
if err == nil && finfo.IsDir() {
|
||||
indexPath := filepath.Join("./res", "index.tmpl.html")
|
||||
t := template.New("index").Delims("[[", "]]")
|
||||
tmpl := template.Must(t.ParseFiles(indexPath))
|
||||
tmpl.ExecuteTemplate(w, "index.tmpl.html", nil)
|
||||
// indexPath := filepath.Join("./res", "index.tmpl.html")
|
||||
// t := template.New("index").Delims("[[", "]]")
|
||||
// tmpl := template.Must(t.ParseFiles(indexPath))
|
||||
// tmpl.ExecuteTemplate(w, "index.tmpl.html", nil)
|
||||
tmpl.Execute(w, nil)
|
||||
} else {
|
||||
http.ServeFile(w, r, relPath)
|
||||
}
|
||||
|
|
3
main.go
3
main.go
|
@ -50,6 +50,9 @@ func main() {
|
|||
}
|
||||
|
||||
http.Handle("/", hdlr)
|
||||
|
||||
// indexContent, _ := Asset("res/index.tmpl.html")
|
||||
// log.Println(string(indexContent))
|
||||
log.Printf("Listening on addr: %s\n", strconv.Quote(gcfg.Addr))
|
||||
|
||||
var err error
|
||||
|
|
17
res_bindata.go
Normal file
17
res_bindata.go
Normal file
|
@ -0,0 +1,17 @@
|
|||
// +build bindata
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var tmpl *template.Template
|
||||
|
||||
func init() {
|
||||
http.Handle("/-/res/", http.StripPrefix("/-/res/", http.FileServer(assetFS())))
|
||||
|
||||
indexContent, _ := Asset("res/index.tmpl.html")
|
||||
tmpl = template.Must(template.New("t").Delims("[[", "]]").Parse(string(indexContent)))
|
||||
}
|
18
res_nobindata.go
Normal file
18
res_nobindata.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
// +build !bindata
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
var tmpl *template.Template
|
||||
|
||||
func init() {
|
||||
http.Handle("/-/res/", http.StripPrefix("/-/res/", http.FileServer(http.Dir("./res"))))
|
||||
|
||||
indexContent, _ := ioutil.ReadFile("./res/index.tmpl.html")
|
||||
tmpl = template.Must(template.New("t").Delims("[[", "]]").Parse(string(indexContent)))
|
||||
}
|
Loading…
Add table
Reference in a new issue