mirror of
https://github.com/aclindsa/moneygo.git
synced 2024-12-27 07:52:28 -05:00
37 lines
747 B
Go
37 lines
747 B
Go
package handlers
|
|
|
|
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)
|
|
}
|
|
|
|
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...)
|
|
}
|
|
|
|
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
|
|
}
|