Remove orphan func
This commit is contained in:
parent
9e34e7d39b
commit
31b9690d74
37
handlers.go
37
handlers.go
|
@ -1,14 +1,11 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
"github.com/labstack/echo"
|
||||
)
|
||||
|
||||
|
@ -153,40 +150,6 @@ func validateUUID(next echo.HandlerFunc, params ...string) echo.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
// makeAttribsBlob takes a list of keys and values and creates
|
||||
// a JSON map out of them.
|
||||
func makeAttribsBlob(keys []string, vals []string) ([]byte, bool) {
|
||||
attribs := make(map[string]interface{})
|
||||
for i, key := range keys {
|
||||
var (
|
||||
s = vals[i]
|
||||
val interface{}
|
||||
)
|
||||
|
||||
// Try to detect common JSON types.
|
||||
if govalidator.IsFloat(s) {
|
||||
val, _ = strconv.ParseFloat(s, 64)
|
||||
} else if govalidator.IsInt(s) {
|
||||
val, _ = strconv.ParseInt(s, 10, 64)
|
||||
} else {
|
||||
ls := strings.ToLower(s)
|
||||
if ls == "true" || ls == "false" {
|
||||
val, _ = strconv.ParseBool(ls)
|
||||
} else {
|
||||
// It's a string.
|
||||
val = s
|
||||
}
|
||||
}
|
||||
attribs[key] = val
|
||||
}
|
||||
|
||||
if len(attribs) > 0 {
|
||||
j, _ := json.Marshal(attribs)
|
||||
return j, true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// getPagination takes form values and extracts pagination values from it.
|
||||
func getPagination(q url.Values) pagination {
|
||||
var (
|
||||
|
|
|
@ -19,6 +19,7 @@ type Queries struct {
|
|||
GetSubscriber *sqlx.Stmt `query:"get-subscriber"`
|
||||
GetSubscribersByEmails *sqlx.Stmt `query:"get-subscribers-by-emails"`
|
||||
GetSubscriberLists *sqlx.Stmt `query:"get-subscriber-lists"`
|
||||
SubscriberExists *sqlx.Stmt `query:"subscriber-exists"`
|
||||
UpdateSubscriber *sqlx.Stmt `query:"update-subscriber"`
|
||||
BlacklistSubscribers *sqlx.Stmt `query:"blacklist-subscribers"`
|
||||
AddSubscribersToLists *sqlx.Stmt `query:"add-subscribers-to-lists"`
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
-- Get a single subscriber by id or UUID.
|
||||
SELECT * FROM subscribers WHERE CASE WHEN $1 > 0 THEN id = $1 ELSE uuid = $2 END;
|
||||
|
||||
-- name: subscriber-exists
|
||||
-- Check if a subscriber exists by id or UUID.
|
||||
SELECT exists (SELECT true FROM subscribers WHERE CASE WHEN $1 > 0 THEN id = $1 ELSE uuid = $2 END);
|
||||
|
||||
-- name: get-subscribers-by-emails
|
||||
-- Get subscribers by emails.
|
||||
SELECT * FROM subscribers WHERE email=ANY($1);
|
||||
|
|
Loading…
Reference in New Issue