社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
Binaries源码可以从 这里下载
Tested with go-1.10, go-1.11
go get -v github.com/codeskyblue/gohttpserver
cd $GOPATH/src/github.com/codeskyblue/gohttpserver
go build && ./gohttpserver
或者,从 github 发布包下载。
用8000端口监听所有接口,并启用文件上传
./gohttpserver -r ./ --port 8000 --upload
命令 gohttpserver --help
获取更多用例.
分享当前目录
docker run -it --rm -p 8000:8000 -v $PWD:/app/public --name gohttpserver codeskyblue/gohttpserver
使用http basic auth共享当前目录
docker run -it --rm -p 8000:8000 -v $PWD:/app/public --name gohttpserver
codeskyblue/gohttpserver
--auth-type http --auth-http username:password
使用openid auth共享当前目录。(仅限网易公司工作)
docker run -it --rm -p 8000:8000 -v $PWD:/app/public --name gohttpserver
codeskyblue/gohttpserver
--auth-type openid
要自己构建映像,请将PWD更改为这个repo的根。
cd gohttpserver/
docker build -t codeskyblue/gohttpserver -f docker/Dockerfile .
启用基本http身份验证
$ gohttpserver --auth-type http --auth-http username:password
使用openid验证
$ gohttpserver --auth-type openid --auth-openid https://login.example-hostname.com/openid/
使用 oauth2-proxy
$ gohttpserver --auth-type oauth2-proxy
您可以配置为让http反向代理处理身份验证。
当使用oauth2-proxy时,后端将使用来自请求头“X-Auth-Request-Email”的标识信息作为用户id,并使用“X-Auth-Request-Fullname”作为用户的显示名称。
请自己配置oauth2反向代理。
More about oauth2-proxy.
所有必需的标题列表如下
header | value |
---|---|
X-Auth-Request-Email | userId |
X-Auth-Request-Fullname | user’s display name(urlencoded) |
X-Auth-Request-User | user’s nickname (mostly email prefix) |
允许上传
$ gohttpserver --upload
启用删除和创建文件夹
$ gohttpserver --delete
通过创建’ .ghs添加访问规则。子目录下的yml '文件。一个例子:
---
upload: false
delete: false
users:
- email: "codeskyblue@codeskyblue.com"
delete: true
upload: true
token: 4567gf8asydhf293r23r
在本例中,如果启用了openid auth,并且用户“codeskyblue@codeskyblue.com”已经登录,那么他/她可以删除/上传位于’ .ghs目录下的文件。yml文件出口。
’ token '用于上传。
see upload with curl
例如,在下面的目录层次结构中,用户可以在目录’ foo ‘中删除/上传文件,但在目录’ bar '中不能这样做。
root -
|-- foo
| |-- .ghs.yml
| `-- world.txt
`-- bar
`-- hello.txt
用户可以使用 --conf
指定配置文件名, see example config.yml.
要指定哪些文件是隐藏的,哪些文件是可见的,请将以下行添加到 .ghs.yml
中
accessTables:
- regex: block.file
allow: false
- regex: visual.file
allow: true
这用于启用https的服务器。默认使用< https://plistproxy.herokuapp.com/plist >
./gohttpserver --plistproxy=https://someproxyhost.com/
测试代理是否工作:
$ http POST https://someproxyhost.com/plist < app.plist
{
"key": "18f99211"
}
$ http GET https://someproxyhost.com/plist/18f99211
# show the app.plist content
如果运行在nginx服务器后面的ghs配置了https。plistproxy将自动禁用。
例如,上传一个名为foo.txt
到目录somedir
$ curl -F file=@foo.txt localhost:8000/somedir
{"destination":"somedir/foo.txt","success":true}
# upload with token
$ curl -F file=@foo.txt -F token=12312jlkjafs localhost:8000/somedir
{"destination":"somedir/foo.txt","success":true}
# upload and change filename
$ curl -F file=@foo.txt -F filename=hi.txt localhost:8000/somedir
{"destination":"somedir/hi.txt","success":true}
上传zip文件并解压(解压完成后,zip文件将被删除)
$ curl -F file=@pkg.zip -F unzip=true localhost:8000/somedir
{"success": true}
Note: /:*<>|
are not allowed in filenames.
建议配置,假设您的gohttpserver监听 127.0.0.1:8200
server {
listen 80;
server_name your-domain-name.com;
location / {
proxy_pass http://127.0.0.1:8200; # here need to change
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
client_max_body_size 0; # disable upload limit
}
}
当使用nginx时,gohttpserver应该带 --xheaders
启动.
Refs: http://nginx.org/en/docs/http/ngx_http_core_module.html#client_max_body_size
The search query follows common format rules just like Google. Keywords are seperated with space(s), keywords with prefix -
will be excluded in search results.
hello world
means must contains hello
and world
hello -world
means must contains hello
but not contains world
Depdencies are managed by govendor
go build
./gohttpserver
go generate .
go build -tags vfs
Theme are defined in assets/themes directory. Now only two themes are available, “black” and “green”.
Go Libraries
The old version is hosted at https://github.com/codeskyblue/gohttp
This project is licensed under MIT.
执行拉取代码,执行install,并build项目后,
在/root/go/src/github.com/codeskyblue/gohttpserver/assets/js/dropzone.js
的第1382行加入如下代码
if(files[i].name.endsWith(".zip")){
formData.append('unzip','true');
}
执行拉取代码,在/root/go/src/github.com/codeskyblue/gohttpserver/httpstaticserver.go
文件中,
在import中添加新依赖 os/exec
import(
·
·
·
"os/exec"
·
·
·
)
找到hDelete
方法,将err := os.remove(filepath.Join(s.Root,path))
替换如下代码:
cmd := exec.Command("rm","-rf",filepath.Join(s.Root, path))
err := cmd.Run()
ok~
在/root/go/src/github.com/codeskyblue/gohttpserver/httpstaticserver.go
文件中,
第85行 添加m.HandleFunc("/-/ambari/restart", s.ambariRestart)
–tips 第一个参数是路径 第二个参数是方法
func NewHTTPStaticServer(root string) *HTTPStaticServer {
if root == "" {
root = "./"
}
root = filepath.ToSlash(root)
if !strings.HasSuffix(root, "/") {
root = root + "/"
}
log.Printf("root path: %sn", root)
m := mux.NewRouter()
s := &HTTPStaticServer{
Root: root,
Theme: "black",
m: m,
}
go func() {
time.Sleep(1 * time.Second)
for {
startTime := time.Now()
log.Println("Started making search index")
s.makeIndex()
log.Printf("Completed search index in %v", time.Since(startTime))
//time.Sleep(time.Second * 1)
time.Sleep(time.Minute * 10)
}
}()
// 重启ambari
m.HandleFunc("/-/ambari/restart", s.ambariRestart)
// routers for Apple *.ipa
m.HandleFunc("/-/ipa/plist/{path:.*}", s.hPlist)
m.HandleFunc("/-/ipa/link/{path:.*}", s.hIpaLink)
m.HandleFunc("/{path:.*}", s.hIndex).Methods("GET", "HEAD")
m.HandleFunc("/{path:.*}", s.hUploadOrMkdir).Methods("POST")
m.HandleFunc("/{path:.*}", s.hDelete).Methods("DELETE")
return s
}
然后添加对应的方法:
func (s *HTTPStaticServer) ambariRestart(w http.ResponseWriter, req *http.Request) {
// only can delete file now
cmd := exec.Command("ambari-server","restart")
err := cmd.Run()
if err != nil {
http.Error(w, err.Error(), 500)
return
}
w.Write([]byte("Success"))
}
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!