Skip to content

Commit

Permalink
Remove orphan func
Browse files Browse the repository at this point in the history
  • Loading branch information
knadh committed Jul 21, 2019
1 parent 9e34e7d commit 31b9690
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 37 deletions.
37 changes: 0 additions & 37 deletions handlers.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package main

import (
"encoding/json"
"net/http"
"net/url"
"regexp"
"strconv"
"strings"

"github.com/asaskevich/govalidator"
"github.com/labstack/echo"
)

Expand Down Expand Up @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
4 changes: 4 additions & 0 deletions queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 31b9690

Please sign in to comment.