26 Star 102 Fork 24

codeskyblue / gohttpserver

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
utils.go 932 Bytes
一键复制 编辑 原始数据 按行查看 历史
codeskyblue 提交于 2016-07-31 10:19 . add auto tag version support
package main
import (
"fmt"
"net/http"
"os"
"strconv"
"strings"
)
func formatSize(file os.FileInfo) string {
if file.IsDir() {
return "-"
}
size := file.Size()
switch {
case size > 1024*1024:
return fmt.Sprintf("%.1f MB", float64(size)/1024/1024)
case size > 1024:
return fmt.Sprintf("%.1f KB", float64(size)/1024)
default:
return strconv.Itoa(int(size)) + " B"
}
return ""
}
func getRealIP(req *http.Request) string {
xip := req.Header.Get("X-Real-IP")
if xip == "" {
xip = strings.Split(req.RemoteAddr, ":")[0]
}
return xip
}
func SublimeContains(s, substr string) bool {
rs, rsubstr := []rune(s), []rune(substr)
if len(rsubstr) > len(rs) {
return false
}
var ok = true
var i, j = 0, 0
for ; i < len(rsubstr); i++ {
found := -1
for ; j < len(rs); j++ {
if rsubstr[i] == rs[j] {
found = j
break
}
}
if found == -1 {
ok = false
break
}
j += 1
}
return ok
}
Go
1
https://gitee.com/shxsun/gohttpserver.git
git@gitee.com:shxsun/gohttpserver.git
shxsun
gohttpserver
gohttpserver
master

搜索帮助