Fix new app creation bug #32

This commit is contained in:
Vikram Rangnekar 2020-01-14 23:16:55 -05:00
parent 3f5727c22b
commit d4dca86267
8 changed files with 23 additions and 16 deletions

View File

@ -64,7 +64,7 @@ func Filter(w *bytes.Buffer, b []byte, keys []string) error {
state = expectKeyClose state = expectKeyClose
s = i s = i
case state == expectKeyClose && b[i] == '"': case state == expectKeyClose && (b[i-1] != '\\' && b[i] == '"'):
state = expectColon state = expectColon
k = b[(s + 1):i] k = b[(s + 1):i]
@ -74,7 +74,7 @@ func Filter(w *bytes.Buffer, b []byte, keys []string) error {
case state == expectValue && b[i] == '"': case state == expectValue && b[i] == '"':
state = expectString state = expectString
case state == expectString && b[i] == '"': case state == expectString && (b[i-1] != '\\' && b[i] == '"'):
e = i e = i
case state == expectValue && b[i] == '[': case state == expectValue && b[i] == '[':

View File

@ -66,7 +66,7 @@ func Get(b []byte, keys [][]byte) []Field {
state = expectKeyClose state = expectKeyClose
s = i s = i
case state == expectKeyClose && b[i] == '"': case state == expectKeyClose && (b[i-1] != '\\' && b[i] == '"'):
state = expectColon state = expectColon
k = b[(s + 1):i] k = b[(s + 1):i]
@ -77,7 +77,7 @@ func Get(b []byte, keys [][]byte) []Field {
state = expectString state = expectString
s = i s = i
case state == expectString && b[i] == '"': case state == expectString && (b[i-1] != '\\' && b[i] == '"'):
e = i e = i
case state == expectValue && b[i] == '[': case state == expectValue && b[i] == '[':

View File

@ -13,12 +13,12 @@ var (
"users": [ "users": [
{ {
"id": 1, "id": 1,
"full_name": "Sidney Stroman", "full_name": "'Sidney Stroman'",
"email": "user0@demo.com", "email": "user0@demo.com",
"__twitter_id": "2048666903444506956", "__twitter_id": "2048666903444506956",
"embed": { "embed": {
"id": 8, "id": 8,
"full_name": "Caroll Orn Sr.", "full_name": "Caroll Orn Sr's",
"email": "joannarau@hegmann.io", "email": "joannarau@hegmann.io",
"__twitter_id": "ABC123" "__twitter_id": "ABC123"
"more": [{ "more": [{
@ -37,7 +37,7 @@ var (
"id": 3, "id": 3,
"full_name": "Kenna Cassin", "full_name": "Kenna Cassin",
"email": "user2@demo.com", "email": "user2@demo.com",
"__twitter_id": { "name": "hello", "address": { "work": "1 infinity loop" } } "__twitter_id": { "name": "\"hellos\"", "address": { "work": "1 infinity loop" } }
}, },
{ {
"id": 4, "id": 4,
@ -171,7 +171,7 @@ func TestGet(t *testing.T) {
{[]byte("__twitter_id"), {[]byte("__twitter_id"),
[]byte(`[{ "name": "hello" }, { "name": "world"}]`)}, []byte(`[{ "name": "hello" }, { "name": "world"}]`)},
{[]byte("__twitter_id"), {[]byte("__twitter_id"),
[]byte(`{ "name": "hello", "address": { "work": "1 infinity loop" } }`), []byte(`{ "name": "\"hellos\"", "address": { "work": "1 infinity loop" } }`),
}, },
{[]byte("__twitter_id"), []byte(`1234567890`)}, {[]byte("__twitter_id"), []byte(`1234567890`)},
{[]byte("__twitter_id"), []byte(`1.23E`)}, {[]byte("__twitter_id"), []byte(`1.23E`)},

View File

@ -47,7 +47,7 @@ func Keys(b []byte) [][]byte {
state = expectKeyClose state = expectKeyClose
s = i s = i
case state == expectKeyClose && b[i] == '"': case state == expectKeyClose && (b[i-1] != '\\' && b[i] == '"'):
state = expectColon state = expectColon
k = b[(s + 1):i] k = b[(s + 1):i]
@ -58,7 +58,7 @@ func Keys(b []byte) [][]byte {
state = expectString state = expectString
s = i s = i
case state == expectString && b[i] == '"': case state == expectString && (b[i-1] != '\\' && b[i] == '"'):
e = i e = i
case state == expectValue && b[i] == '{': case state == expectValue && b[i] == '{':

View File

@ -52,7 +52,7 @@ func Replace(w *bytes.Buffer, b []byte, from, to []Field) error {
state = expectKeyClose state = expectKeyClose
s = i s = i
case state == expectKeyClose && b[i] == '"': case state == expectKeyClose && (b[i-1] != '\\' && b[i] == '"'):
state = expectColon state = expectColon
if _, err := h.Write(b[(s + 1):i]); err != nil { if _, err := h.Write(b[(s + 1):i]); err != nil {
return err return err
@ -66,7 +66,7 @@ func Replace(w *bytes.Buffer, b []byte, from, to []Field) error {
state = expectString state = expectString
s = i s = i
case state == expectString && b[i] == '"': case state == expectString && (b[i-1] != '\\' && b[i] == '"'):
e = i e = i
case state == expectValue && b[i] == '[': case state == expectValue && b[i] == '[':

View File

@ -27,7 +27,7 @@ func Strip(b []byte, path [][]byte) []byte {
state = expectKeyClose state = expectKeyClose
s = i s = i
case state == expectKeyClose && b[i] == '"': case state == expectKeyClose && (b[i-1] != '\\' && b[i] == '"'):
state = expectColon state = expectColon
if pi == len(path) { if pi == len(path) {
pi = 0 pi = 0
@ -44,7 +44,7 @@ func Strip(b []byte, path [][]byte) []byte {
state = expectString state = expectString
s = i s = i
case state == expectString && b[i] == '"': case state == expectString && (b[i-1] != '\\' && b[i] == '"'):
e = i e = i
case state == expectValue && b[i] == '[': case state == expectValue && b[i] == '[':

View File

@ -33,7 +33,12 @@ func argMap(ctx context.Context, vars []byte) func(w io.Writer, tag string) (int
return 0, errors.New("query requires variable $user_role") return 0, errors.New("query requires variable $user_role")
} }
fmt.Println("1>", tag)
fmt.Println("2>", string(vars))
fields := jsn.Get(vars, [][]byte{[]byte(tag)}) fields := jsn.Get(vars, [][]byte{[]byte(tag)})
fmt.Println("2.1>", fields)
if len(fields) == 0 { if len(fields) == 0 {
return 0, nil return 0, nil
} }
@ -42,6 +47,8 @@ func argMap(ctx context.Context, vars []byte) func(w io.Writer, tag string) (int
fields[0].Value = v[1 : len(v)-1] fields[0].Value = v[1 : len(v)-1]
} }
fmt.Println("3>", string(fields[0].Value))
return w.Write(escQuote(fields[0].Value)) return w.Write(escQuote(fields[0].Value))
} }
} }

View File

@ -90,8 +90,8 @@ func cmdNew(cmd *cobra.Command, args []string) {
return os.Mkdir(p, os.ModePerm) return os.Mkdir(p, os.ModePerm)
}) })
ifNotExists(path.Join(appMigrationsPath, "100_init.sql"), func(p string) error { ifNotExists(path.Join(appMigrationsPath, "0_init.sql"), func(p string) error {
if v, err := tmpl.get("100_init.sql"); err == nil { if v, err := tmpl.get("0_init.sql"); err == nil {
return ioutil.WriteFile(p, v, 0644) return ioutil.WriteFile(p, v, 0644)
} else { } else {
return err return err