前几天看了个帖子有人在问有没有 临时网上放 json 的网盘并且能直连访问的 用于测试. 加之这两天学了 golang 于是就写了这么个小项目

项目

logo.png

项目地址
还有很多功能可以完善,感兴趣的朋友可以去扩展
例如 权限、统计、协同、等等(学完 go 可以用来练练手项目很小很容易修改)

用途

前端页面测试,json 测试,临时网盘

子域名访问实现

域名:tempyun.com
文件:a.txt
通过主域名访问路径如下:
http://tempyun.com/service/files/{用户名}/a.txt

实现访问路径:
http://{用户名}.tempyun.com/a.txt

实现:
将域名泛解析到服务器 ip *.tempyun.com 192.168.1.1

通过过滤器将子域名(用户名)提取

服务代理访问路径并返回

func Ymfilter() {
	var Filter = func(ctx *context.Context) {
		doamin := beego.AppConfig.String("doamin")
		if ctx.Input.Host() != doamin {
			req := httplib.Get(strings.Replace(ctx.Input.Site(), ctx.Input.Host(), doamin, -1) + ":" + strconv.Itoa(ctx.Input.Port()) + "/" + strings.Replace(ctx.Input.Host(), "."+doamin, "", -1) + ctx.Input.URL())
			bytes, _ := req.Bytes()
			ctx.ResponseWriter.Write(bytes)
		}
	}
	beego.InsertFilter("/*", beego.BeforeRouter, Filter)
}