2017-10-09 14:26:46 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-06-20 23:12:07 +02:00
|
|
|
"app/controller"
|
|
|
|
"app/database"
|
|
|
|
"app/environment"
|
|
|
|
"app/service"
|
2017-10-09 14:26:46 +02:00
|
|
|
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12"
|
|
|
|
"github.com/kataras/iris/v12/mvc"
|
2017-10-09 14:26:46 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
app := iris.New()
|
2020-08-24 20:44:29 +02:00
|
|
|
app.Logger().SetLevel("debug")
|
|
|
|
|
2020-06-22 16:49:45 +02:00
|
|
|
app.Get("/ping", pong).Describe("healthcheck")
|
|
|
|
|
2020-06-20 23:12:07 +02:00
|
|
|
mvc.Configure(app.Party("/greet"), setup)
|
2017-10-09 14:26:46 +02:00
|
|
|
|
2020-06-20 23:12:07 +02:00
|
|
|
// http://localhost:8080/greet?name=kataras
|
2020-07-12 14:15:59 +02:00
|
|
|
addr := ":" + environment.Getenv("PORT", "8080")
|
2020-08-24 20:44:29 +02:00
|
|
|
app.Listen(addr)
|
2020-06-22 16:49:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func pong(ctx iris.Context) {
|
|
|
|
ctx.WriteString("pong")
|
2017-10-09 14:26:46 +02:00
|
|
|
}
|
2017-12-16 05:38:28 +01:00
|
|
|
|
2020-06-20 23:12:07 +02:00
|
|
|
/*
|
2022-06-17 21:03:18 +02:00
|
|
|
+-------------------+
|
|
|
|
| Env (DEV, PROD) |
|
|
|
|
+---------+---------+
|
|
|
|
| | |
|
|
|
|
| | |
|
|
|
|
| | |
|
|
|
|
DEV | | | PROD
|
|
|
|
|
2020-06-20 23:12:07 +02:00
|
|
|
-------------------+---------------------+ | +----------------------+-------------------
|
2022-06-17 21:03:18 +02:00
|
|
|
|
|
|
|
| | |
|
|
|
|
| | |
|
|
|
|
+---+-----+ +----------------v------------------+ +----+----+
|
|
|
|
| sqlite | | NewDB(Env) DB | | mysql |
|
|
|
|
+---+-----+ +----------------+---+--------------+ +----+----+
|
|
|
|
| | | |
|
|
|
|
| | | |
|
|
|
|
| | | |
|
|
|
|
+--------------+-----+ +-------------------v---v-----------------+ +----+------+
|
|
|
|
| greeterWithLogging | | NewGreetService(Env, DB) GreetService | | greeter |
|
|
|
|
+--------------+-----+ +---------------------------+-------------+ +----+------+
|
|
|
|
| | |
|
|
|
|
| | |
|
|
|
|
| +-----------------------------------------+ |
|
|
|
|
| | GreetController | | |
|
|
|
|
| | | | |
|
|
|
|
| | - Service GreetService <-- | |
|
|
|
|
| | | |
|
|
|
|
| +-------------------+---------------------+ |
|
|
|
|
| | |
|
|
|
|
| | |
|
|
|
|
| | |
|
|
|
|
| +-----------+-----------+ |
|
|
|
|
| | HTTP Request | |
|
|
|
|
| +-----------------------+ |
|
|
|
|
| | /greet?name=kataras | |
|
|
|
|
| +-----------+-----------+ |
|
|
|
|
| | |
|
|
|
|
|
2020-06-20 23:12:07 +02:00
|
|
|
+------------------+--------+ +------------+------------+ +-------+------------------+
|
|
|
|
| model.Response (JSON) | | Response (JSON, error) | | Bad Request |
|
|
|
|
+---------------------------+ +-------------------------+ +--------------------------+
|
|
|
|
| { | | mysql: not implemented |
|
|
|
|
| "msg": "Hello kataras" | +--------------------------+
|
|
|
|
| } |
|
|
|
|
+---------------------------+
|
|
|
|
*/
|
|
|
|
func setup(app *mvc.Application) {
|
|
|
|
// Register Dependencies.
|
|
|
|
// Tip: A dependency can depend on other dependencies too.
|
2020-06-22 16:49:45 +02:00
|
|
|
env := environment.ReadEnv("ENVIRONMENT", environment.DEV)
|
2020-06-20 23:12:07 +02:00
|
|
|
app.Register(
|
2020-06-22 16:49:45 +02:00
|
|
|
env, // DEV, PROD
|
2020-06-20 23:12:07 +02:00
|
|
|
database.NewDB, // sqlite, mysql
|
|
|
|
service.NewGreetService, // greeterWithLogging, greeter
|
|
|
|
)
|
2017-12-16 05:38:28 +01:00
|
|
|
|
2020-06-20 23:12:07 +02:00
|
|
|
// Register Controllers.
|
|
|
|
app.Handle(new(controller.GreetController))
|
2017-12-16 05:38:28 +01:00
|
|
|
}
|