-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
73 lines (58 loc) · 1.65 KB
/
main.go
File metadata and controls
73 lines (58 loc) · 1.65 KB
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
package main
import (
"flag"
"fmt"
m "./models"
dbguardian "./utils"
"github.com/kataras/iris"
"github.com/kataras/iris/middleware/logger"
"github.com/kataras/iris/middleware/recover"
)
func main() {
var dbpath string
var renderpath string
flag.StringVar(&dbpath, "DBPATH", "", "db path to storage subscribers")
flag.StringVar(&renderpath, "STATICFILES", "", "location of html and js files")
flag.Parse()
app := iris.New()
app.Use(recover.New())
app.Use(logger.New())
if renderpath == "" {
app.RegisterView(iris.HTML("./views", ".html"))
app.StaticWeb("/dist", "./views/dist")
app.StaticWeb("/public", "./views/public")
} else {
app.RegisterView(iris.HTML(renderpath, ".html"))
app.StaticWeb("/dist", renderpath+"/dist")
app.StaticWeb("/dist", renderpath+"/public")
}
app.Handle("GET", "/", func(ctx iris.Context) {
ctx.Gzip(true)
ctx.View("index.html")
})
developerAPI := app.Party("/developers")
{
developerAPI.Post("/", func(ctx iris.Context) {
dbguardian.Initialize(dbpath)
var newUser m.User
ctx.ReadJSON(&newUser)
fmt.Println(&newUser)
dbguardian.WriteData(&newUser)
ctx.JSON(iris.Map{"message": "Gracias por suscribirte!", "status": "new user added"})
})
developerAPI.Get("/", func(ctx iris.Context) {
dbguardian.Initialize(dbpath)
result := dbguardian.ReadData()
// if err != nil {
// panic(err)
// }
fmt.Println(len(result))
fmt.Println(result)
ctx.WriteString("Nothing to look here YET")
})
developerAPI.Get("/write", func(ctx iris.Context) {
ctx.WriteString("Nothing to look here")
})
}
app.Run(iris.Addr(":8079"), iris.WithoutServerError(iris.ErrServerClosed))
}