1 Star 0 Fork 0

张先森 / srv

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

srv: Serve content through http(s)

中文

Gopher.png

Install

$ go install -u github.com/jamesbee/srv

Usage

Show usage

$ srv help up
Bring up http(s) server.

Usage:
  srv up [flags]

Flags:
  -i, --dir string        Default url for current working dir, e.g. /pwd (default "pwd")
  -e, --exclude strings   Exclude those dirs, e.g. ".git,.idea" (default [.git])
  -h, --help              Show this message
      --host string       Server listen host (default "127.0.0.1")
  -m, --markdown          Enable markdown parse (default true)
  -p, --port int          Server listen port (default 3000)
  -c, --tls-cert string   TLS Cert path, e.g. ./cert.pem
  -t, --tls-enable        Enable TLS
  -k, --tls-key string    TLS Key path, e.g. ./cert.key

Global Flags:
      --config string   config file (default is $HOME/.srv.yaml)
  -d, --debug           Enable debug output.
      --viper           use Viper for configuration (default true)

Serve immediately

Type srv up and serve current working dir on http://127.0.0.1:3000.

You can always visit /index or /index.html to get all mapped routes (only if you are not serving your custom index.html file).

e.g.

$ cd server && srv up

Visit http://localhost:3000/server and you will get:

Files

Serve markdown

srv parse mark down files to html by default, you can disable this feature by passing srv up -m false

$ srv up README.md

Screenshot.png

Serve File

If srv up receive a single file as argument, then no rotue info page whould generate, it'll serve that file at /, /index, /index.html, /{FILE_NAME}.html at the sametime.

#    `curl 127.0.0.1:8080`
# OR `curl 127.0.0.1:8080/index.html`
# OR `curl 127.0.0.1:8080/foo.html`
$ srv -p 8080 up foo.html

If multiple file (e.g. srv up foo.html bar.html) or directory has been passed to srv up, then /, /index, /index.html would be routes info, and serve content individually at request path that names after the file like /foo.html, /path/to/bar.html.

$ srv up main.go README.md
⇨ http server started on 127.0.0.1:3000

Screenshot_2.png

Serve Mixed

You can always serve file alone side with directories.

#    `curl 127.0.0.1:3000`
#    `curl 127.0.0.1:3000/foo.html`
# OR `curl 127.0.0.1:3000/www`
# OR `curl 127.0.0.1:3000/www/foo.html`
$ srv up foo.html www/
The MIT License (MIT) Copyright (c) 2020 James Bacon Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

通过 http(s) 调试本地文件(夹) 展开 收起
Go
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Go
1
https://gitee.com/bejames/srv.git
git@gitee.com:bejames/srv.git
bejames
srv
srv
master

搜索帮助