-
Notifications
You must be signed in to change notification settings - Fork 4
/
dash_views.go
832 lines (773 loc) · 19.1 KB
/
dash_views.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
package korm
import (
"bytes"
"encoding/csv"
"encoding/json"
"errors"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
"strconv"
"strings"
"time"
"github.com/kamalshkeir/aes"
"github.com/kamalshkeir/argon"
"github.com/kamalshkeir/ksmux"
"github.com/kamalshkeir/lg"
)
func reverseSlice[T any](slice []T) []T {
new := make([]T, 0, len(slice))
for i := len(slice) - 1; i >= 0; i-- {
new = append(new, slice[i])
}
return new
}
var LogsView = func(c *ksmux.Context) {
d := map[string]any{
"admin_path": adminPathNameGroup,
"static_url": staticUrl,
"secure": ksmux.IsTLS,
}
if v := lg.GetLogs(); v != nil {
d["logs"] = reverseSlice[string](v.Slice)
}
c.Html("admin/logs.html", d)
}
var IndexView = func(c *ksmux.Context) {
allTables := GetAllTables(defaultDB)
c.Html("admin/admin_index.html", map[string]any{
"admin_path": adminPathNameGroup,
"static_url": staticUrl,
"tables": allTables,
})
}
var LoginView = func(c *ksmux.Context) {
c.Html("admin/admin_login.html", map[string]any{
"admin_path": adminPathNameGroup,
"static_url": staticUrl,
})
}
var LoginPOSTView = func(c *ksmux.Context) {
requestData := c.BodyJson()
email := requestData["email"]
passRequest := requestData["password"]
data, err := Table("users").Database(defaultDB).Where("email = ?", email).One()
if err != nil {
c.Status(500).Json(map[string]any{
"error": err.Error(),
})
return
}
if data["email"] == "" || data["email"] == nil {
c.Status(http.StatusNotFound).Json(map[string]any{
"error": "User doesn not Exist",
})
return
}
if data["is_admin"] == int64(0) || data["is_admin"] == 0 || data["is_admin"] == false {
c.Status(http.StatusForbidden).Json(map[string]any{
"error": "Not Allowed to access this page",
})
return
}
if passDB, ok := data["password"].(string); ok {
if pp, ok := passRequest.(string); ok {
if !argon.Match(passDB, pp) {
c.Status(http.StatusForbidden).Json(map[string]any{
"error": "Wrong Password",
})
return
} else {
if uuid, ok := data["uuid"].(string); ok {
uuid, err = aes.Encrypt(uuid)
lg.CheckError(err)
c.SetCookie("session", uuid)
c.Json(map[string]any{
"success": "U Are Logged In",
})
return
}
}
}
}
}
var LogoutView = func(c *ksmux.Context) {
c.DeleteCookie("session")
c.Status(http.StatusTemporaryRedirect).Redirect("/")
}
var AllModelsGet = func(c *ksmux.Context) {
model := c.Param("model")
if model == "" {
c.Json(map[string]any{
"error": "Error: No model given in params",
})
return
}
dbMem, _ := GetMemoryDatabase(defaultDB)
if dbMem == nil {
lg.ErrorC("unable to find db in mem", "db", defaultDB)
dbMem = &databases[0]
}
idString := "id"
var t *TableEntity
for i, tt := range dbMem.Tables {
if tt.Name == model {
idString = tt.Pk
t = &dbMem.Tables[i]
}
}
rows, err := Table(model).Database(defaultDB).OrderBy("-" + idString).Limit(paginationPer).Page(1).All()
if err != nil {
rows, err = Table(model).Database(defaultDB).All()
if err != nil {
// usualy should not use error string because it divulge infkormation, but here only admin use it, so no worry
if err != ErrNoData {
c.Status(404).Error("Unable to find this model")
return
}
}
}
dbCols, cols := GetAllColumnsTypes(model)
mmfkeys := map[string][]any{}
if t != nil {
for _, fkey := range t.Fkeys {
spFrom := strings.Split(fkey.FromTableField, ".")
if len(spFrom) == 2 {
spTo := strings.Split(fkey.ToTableField, ".")
if len(spTo) == 2 {
q := "select " + spTo[1] + " from " + spTo[0] + " order by " + spTo[1]
mm := []map[string]any{}
err := To(&mm).Query(q)
if !lg.CheckError(err) {
ress := []any{}
for _, res := range mm {
ress = append(ress, res[spTo[1]])
}
if len(ress) > 0 {
mmfkeys[spFrom[1]] = ress
}
} else {
lg.ErrorC("error:", "q", q, "spTo", spTo)
}
}
}
}
} else {
idString = cols[0]
}
if dbMem != nil {
data := map[string]any{
"dbType": dbMem.Dialect,
"model_name": model,
"rows": rows,
"dbcolumns": dbCols,
"pk": idString,
"fkeys": mmfkeys,
"columnsOrdered": cols,
}
if t != nil {
data["columns"] = t.ModelTypes
} else {
data["columns"] = dbCols
}
data["admin_path"] = adminPathNameGroup
data["static_url"] = staticUrl
c.Html("admin/admin_all_models.html", data)
} else {
lg.ErrorC("table not found", "table", model)
c.Status(404).Error("Unable to find this model")
}
}
var AllModelsSearch = func(c *ksmux.Context) {
model := c.Param("model")
if model == "" {
c.Json(map[string]any{
"error": "Error: No model given in params",
})
return
}
body := c.BodyJson()
blder := Table(model).Database(defaultDB)
if query, ok := body["query"]; ok {
if v, ok := query.(string); ok {
if v != "" {
blder.Where(v)
}
} else {
c.Json(map[string]any{
"error": "Error: No query given in body",
})
return
}
}
oB := ""
t, err := GetMemoryTable(model, defaultDB)
if lg.CheckError(err) {
c.Json(map[string]any{
"error": err,
})
return
}
if orderby, ok := body["orderby"]; ok {
if v, ok := orderby.(string); ok && v != "" {
oB = v
} else {
oB = "-" + t.Pk
}
} else {
oB = "-" + t.Pk
}
blder.OrderBy(oB)
if v, ok := body["page_num"]; ok && v != "" {
if page, ok := v.(string); !ok {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": "expecting page_num to be a sring",
})
return
} else {
pagenum, err := strconv.Atoi(page)
if err == nil {
blder.Limit(paginationPer).Page(pagenum)
} else {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": err.Error(),
})
return
}
}
} else {
blder.Limit(paginationPer).Page(1)
}
data, err := blder.All()
if err != nil {
c.Json(map[string]any{
"error": err.Error(),
})
return
}
c.Json(map[string]any{
"rows": data,
"cols": t.Columns,
"types": t.ModelTypes,
})
}
var DeleteRowPost = func(c *ksmux.Context) {
data := c.BodyJson()
if data["mission"] == "delete_row" {
if model, ok := data["model_name"]; ok {
if mm, ok := model.(string); ok {
idString := "id"
t, _ := GetMemoryTable(mm, defaultDB)
if t.Pk != "" && t.Pk != "id" {
idString = t.Pk
}
modelDB, err := Table(mm).Database(defaultDB).Where(idString+" = ?", data["id"]).One()
if lg.CheckError(err) {
lg.ErrorC("data received DeleteRowPost", "data", data)
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": err.Error(),
})
return
}
if val, ok := modelDB["image"]; ok {
if vv, ok := val.(string); ok && vv != "" {
_ = c.DeleteFile(vv)
}
}
if idS, ok := data["id"].(string); ok {
_, err = Table(mm).Database(defaultDB).Where(idString+" = ?", idS).Delete()
if err != nil {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": err.Error(),
})
} else {
c.Json(map[string]any{
"success": "Done !",
"id": data["id"],
})
return
}
}
} else {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": "expecting model_name to be string",
})
return
}
} else {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": "no model_name found in request body",
})
return
}
}
}
var CreateModelView = func(c *ksmux.Context) {
parseErr := c.Request.ParseMultipartForm(int64(ksmux.MultipartSize))
if parseErr != nil {
lg.ErrorC(parseErr.Error())
return
}
data := c.Request.Form
defer func() {
err := c.Request.MultipartForm.RemoveAll()
lg.CheckError(err)
}()
model := data["table"][0]
m := map[string]any{}
for key, val := range data {
switch key {
case "table":
continue
case "uuid":
if v := m[key]; v == "" {
m[key] = GenerateUUID()
} else {
m[key] = val[0]
}
case "password":
hash, _ := argon.Hash(val[0])
m[key] = hash
case "email":
if !IsValidEmail(val[0]) {
c.Json(map[string]any{
"error": "email not valid",
})
return
}
m[key] = val[0]
default:
if key != "" && val[0] != "" && val[0] != "null" {
m[key] = val[0]
}
}
}
_, err := Table(model).Database(defaultDB).Insert(m)
if err != nil {
lg.ErrorC("CreateModelView error", "err", err)
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": err.Error(),
})
return
}
c.Json(map[string]any{
"success": "Done !",
})
}
var SingleModelGet = func(c *ksmux.Context) {
model := c.Param("model")
if model == "" {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": "param model not defined",
})
return
}
id := c.Param("id")
if id == "" {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": "param id not defined",
})
return
}
idString := "id"
t, _ := GetMemoryTable(model, defaultDB)
if t.Pk != "" && t.Pk != "id" {
idString = t.Pk
}
modelRow, err := Table(model).Database(defaultDB).Where(idString+" = ?", id).One()
if lg.CheckError(err) {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": err.Error(),
})
return
}
dbCols, colsOrdered := GetAllColumnsTypes(model)
mmfkeys := map[string][]any{}
for _, fkey := range t.Fkeys {
spFrom := strings.Split(fkey.FromTableField, ".")
if len(spFrom) == 2 {
spTo := strings.Split(fkey.ToTableField, ".")
if len(spTo) == 2 {
q := "select " + spTo[1] + " from " + spTo[0] + " order by " + spTo[1]
mm, err := Table(spTo[0]).Database(defaultDB).QueryM(q)
if !lg.CheckError(err) {
ress := []any{}
for _, res := range mm {
ress = append(ress, res[spTo[1]])
}
if len(ress) > 0 {
mmfkeys[spFrom[1]] = ress
}
}
}
}
}
c.Html("admin/admin_single_model.html", map[string]any{
"admin_path": adminPathNameGroup,
"static_url": staticUrl,
"model": modelRow,
"model_name": model,
"id": id,
"fkeys": mmfkeys,
"columns": t.ModelTypes,
"dbcolumns": dbCols,
"pk": t.Pk,
"columnsOrdered": colsOrdered,
})
}
var UpdateRowPost = func(c *ksmux.Context) {
// parse the fkorm and get data values + files
data, files := c.ParseMultipartForm()
id := data["row_id"][0]
idString := "id"
t, _ := GetMemoryTable(data["table"][0], defaultDB)
if t.Pk != "" && t.Pk != "id" {
idString = t.Pk
}
err := handleFilesUpload(files, data["table"][0], id, c, idString)
if err != nil {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": err.Error(),
})
return
}
modelDB, err := Table(data["table"][0]).Database(defaultDB).Where(idString+" = ?", id).One()
if err != nil {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": err.Error(),
})
return
}
ignored := []string{idString, "file", "image", "photo", "img", "fichier", "row_id", "table"}
toUpdate := map[string]any{}
for key, val := range data {
if !SliceContains(ignored, key) {
if modelDB[key] == val[0] {
// no changes for bool
continue
}
toUpdate["`"+key+"`"] = val[0]
}
}
s := ""
values := []any{}
if len(toUpdate) > 0 {
for col, v := range toUpdate {
if s == "" {
s += col + "= ?"
} else {
s += "," + col + "= ?"
}
values = append(values, v)
}
}
if s != "" {
_, err := Table(data["table"][0]).Database(defaultDB).Where(idString+" = ?", id).Set(s, values...)
if err != nil {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": err.Error(),
})
return
}
}
s = ""
if len(files) > 0 {
for f := range files {
if s == "" {
s += f
} else {
s += "," + f
}
}
}
if len(toUpdate) > 0 {
for k := range toUpdate {
if s == "" {
s += k
} else {
s += "," + k
}
}
}
c.Json(map[string]string{
"success": s + " updated successfully",
})
}
func handleFilesUpload(files map[string][]*multipart.FileHeader, model string, id string, c *ksmux.Context, idString string) error {
if len(files) > 0 {
for key, val := range files {
file, _ := val[0].Open()
defer file.Close()
uploadedImage, err := uploadMultipartFile(file, val[0].Filename, mediaDir+"/uploads/")
if err != nil {
return err
}
row, err := Table(model).Database(defaultDB).Where(idString+" = ?", id).One()
if err != nil {
return err
}
database_image, okDB := row[key]
if database_image == uploadedImage {
return errors.New("uploadedImage is the same")
} else {
if v, ok := database_image.(string); ok || okDB {
err := c.DeleteFile(v)
if err != nil {
//le fichier n'existe pas
_, err := Table(model).Database(defaultDB).Where(idString+" = ?", id).Set(key+" = ?", uploadedImage)
lg.CheckError(err)
continue
} else {
//le fichier existe et donc supprimer
_, err := Table(model).Database(defaultDB).Where(idString+" = ?", id).Set(key+" = ?", uploadedImage)
lg.CheckError(err)
continue
}
}
}
}
}
return nil
}
var DropTablePost = func(c *ksmux.Context) {
data := c.BodyJson()
if table, ok := data["table"]; ok && table != "" {
if t, ok := data["table"].(string); ok {
_, err := Table(t).Database(defaultDB).Drop()
if lg.CheckError(err) {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": err.Error(),
})
return
}
} else {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": "expecting 'table' to be string",
})
}
} else {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": "missing 'table' in body request",
})
}
c.Json(map[string]any{
"success": fmt.Sprintf("table %s Deleted !", data["table"]),
})
}
var ExportView = func(c *ksmux.Context) {
table := c.Param("table")
if table == "" {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": "no param table found",
})
return
}
data, err := Table(table).Database(defaultDB).All()
lg.CheckError(err)
data_bytes, err := json.Marshal(data)
lg.CheckError(err)
c.Download(data_bytes, table+".json")
}
var ExportCSVView = func(c *ksmux.Context) {
table := c.Param("table")
if table == "" {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": "no param table found",
})
return
}
data, err := Table(table).Database(defaultDB).All()
lg.CheckError(err)
var buff bytes.Buffer
writer := csv.NewWriter(&buff)
cols := []string{}
tab, _ := GetMemoryTable(table, defaultDB)
if len(tab.Columns) > 0 {
cols = tab.Columns
} else if len(data) > 0 {
d := data[0]
for k := range d {
cols = append(cols, k)
}
}
err = writer.Write(cols)
lg.CheckError(err)
for _, sd := range data {
values := []string{}
for _, k := range cols {
switch vv := sd[k].(type) {
case string:
values = append(values, vv)
case bool:
if vv {
values = append(values, "true")
} else {
values = append(values, "false")
}
case int:
values = append(values, strconv.Itoa(vv))
case int64:
values = append(values, strconv.Itoa(int(vv)))
case uint:
values = append(values, strconv.Itoa(int(vv)))
case time.Time:
values = append(values, vv.String())
default:
values = append(values, fmt.Sprintf("%v", vv))
}
}
err = writer.Write(values)
lg.CheckError(err)
}
writer.Flush()
c.Download(buff.Bytes(), table+".csv")
}
var ImportView = func(c *ksmux.Context) {
// get table name
table := c.Request.FormValue("table")
if table == "" {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": "no table !",
})
return
}
t, err := GetMemoryTable(table, defaultDB)
if lg.CheckError(err) {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": err.Error(),
})
return
}
// upload file and return bytes of file
fname, dataBytes, err := c.UploadFile("thefile", "backup", "json", "csv")
if lg.CheckError(err) {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": err.Error(),
})
return
}
isCsv := strings.HasSuffix(fname, ".csv")
// get old data and backup
modelsOld, _ := Table(table).Database(defaultDB).All()
if len(modelsOld) > 0 {
modelsOldBytes, err := json.Marshal(modelsOld)
if !lg.CheckError(err) {
_ = os.MkdirAll(mediaDir+"/backup/", 0770)
dst, err := os.Create(mediaDir + "/backup/" + table + "-" + time.Now().Format("2006-01-02") + ".json")
lg.CheckError(err)
defer dst.Close()
_, err = dst.Write(modelsOldBytes)
lg.CheckError(err)
}
}
// fill list_map
list_map := []map[string]any{}
if isCsv {
reader := csv.NewReader(bytes.NewReader(dataBytes))
lines, err := reader.ReadAll()
if lg.CheckError(err) {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": err.Error(),
})
return
}
for _, values := range lines {
m := map[string]any{}
for i := range values {
m[t.Columns[i]] = values[i]
}
list_map = append(list_map, m)
}
} else {
err := json.Unmarshal(dataBytes, &list_map)
if lg.CheckError(err) {
c.Status(http.StatusBadRequest).Json(map[string]any{
"error": err.Error(),
})
return
}
}
// create models in database
var retErr []error
for _, m := range list_map {
_, err = Table(table).Database(defaultDB).Insert(m)
if err != nil {
retErr = append(retErr, err)
}
}
if len(retErr) > 0 {
c.Json(map[string]any{
"success": "some data could not be added, " + errors.Join(retErr...).Error(),
})
return
}
c.Json(map[string]any{
"success": "Import Done , you can see uploaded backups at ./" + mediaDir + "/backup folder",
})
}
var ManifestView = func(c *ksmux.Context) {
if embededDashboard {
f, err := staticAndTemplatesFS[0].ReadFile(staticDir + "/manifest.json")
if err != nil {
lg.ErrorC("cannot embed manifest.json", "err", err)
return
}
c.ServeEmbededFile("application/json; charset=utf-8", f)
} else {
c.ServeFile("application/json; charset=utf-8", staticDir+"/manifest.json")
}
}
var ServiceWorkerView = func(c *ksmux.Context) {
if embededDashboard {
f, err := staticAndTemplatesFS[0].ReadFile(staticDir + "/sw.js")
if err != nil {
lg.ErrorC("cannot embed sw.js", "err", err)
return
}
c.ServeEmbededFile("application/javascript; charset=utf-8", f)
} else {
c.ServeFile("application/javascript; charset=utf-8", staticDir+"/sw.js")
}
}
var RobotsTxtView = func(c *ksmux.Context) {
c.ServeFile("text/plain; charset=utf-8", "."+staticUrl+"/robots.txt")
}
var OfflineView = func(c *ksmux.Context) {
c.Text("<h1>YOUR ARE OFFLINE, check connection</h1>")
}
func uploadMultipartFile(file multipart.File, filename string, outPath string, acceptedFormats ...string) (string, error) {
//create destination file making sure the path is writeable.
if outPath == "" {
outPath = mediaDir + "/uploads/"
} else {
if !strings.HasSuffix(outPath, "/") {
outPath += "/"
}
}
err := os.MkdirAll(outPath, 0770)
if err != nil {
return "", err
}
l := []string{"jpg", "jpeg", "png", "json"}
if len(acceptedFormats) > 0 {
l = acceptedFormats
}
if strings.ContainsAny(filename, strings.Join(l, "")) {
dst, err := os.Create(outPath + filename)
if err != nil {
return "", err
}
defer dst.Close()
//copy the uploaded file to the destination file
if _, err := io.Copy(dst, file); err != nil {
return "", err
} else {
url := "/" + outPath + filename
return url, nil
}
} else {
return "", fmt.Errorf("not in allowed extensions 'jpg','jpeg','png','json' : %v", l)
}
}