Split Handler into Handler and APIHandler

This commit is contained in:
2016-07-17 17:03:50 +01:00
parent 5065c3178d
commit bb44578173
6 changed files with 125 additions and 99 deletions

25
web/handler_helpers.go Normal file
View File

@@ -0,0 +1,25 @@
package web
import (
"net/url"
"github.com/qiangxue/fasthttp-routing"
)
func makeURLResponse(c *routing.Context, uid []byte, url []byte) URLResponse {
return URLResponse{
UID: string(uid),
URL: makeShortURL(c, uid),
Target: string(url),
}
}
func makeShortURL(c *routing.Context, uid []byte) string {
shortURL := &url.URL{
Scheme: "http",
Host: string(c.Host()),
Path: "/" + string(uid),
}
return shortURL.String()
}