2017-10-04 19:35:59 -04:00
|
|
|
package handlers
|
2015-06-25 22:36:58 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func GetURLID(url string) (int64, error) {
|
|
|
|
pieces := strings.Split(strings.Trim(url, "/"), "/")
|
|
|
|
return strconv.ParseInt(pieces[len(pieces)-1], 10, 0)
|
|
|
|
}
|
|
|
|
|
2015-07-11 08:58:36 -04:00
|
|
|
func GetURLPieces(url string, format string, a ...interface{}) (int, error) {
|
|
|
|
url = strings.Replace(url, "/", " ", -1)
|
|
|
|
format = strings.Replace(format, "/", " ", -1)
|
|
|
|
return fmt.Sscanf(url, format, a...)
|
|
|
|
}
|
|
|
|
|
2017-10-14 14:20:50 -04:00
|
|
|
type ResponseWrapper struct {
|
|
|
|
Code int
|
|
|
|
Writer ResponseWriterWriter
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r ResponseWrapper) Write(w http.ResponseWriter) error {
|
|
|
|
w.WriteHeader(r.Code)
|
|
|
|
return r.Writer.Write(w)
|
|
|
|
}
|
|
|
|
|
|
|
|
type SuccessWriter struct{}
|
|
|
|
|
|
|
|
func (s SuccessWriter) Write(w http.ResponseWriter) error {
|
|
|
|
fmt.Fprint(w, "{}")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-06-25 22:36:58 -04:00
|
|
|
func WriteSuccess(w http.ResponseWriter) {
|
|
|
|
fmt.Fprint(w, "{}")
|
|
|
|
}
|