-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.py
36 lines (26 loc) · 840 Bytes
/
index.py
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
from arnelify_router import ArnelifyRouter
import json
def main() -> int:
router = ArnelifyRouter()
def controller(ctx: dict) -> dict:
return ctx
router.get("/", controller)
router.get("/:id", controller)
routeOpt: dict | None = router.find("GET", "/1")
if not routeOpt:
print("[Arnelify Router]: Route not found.")
return 0
route: dict = routeOpt
print("[Arnelify Router]: Route serialized: " + json.dumps(route))
controllerOpt: callable | None = router.getController(route["id"])
if not controllerOpt:
print("[Arnelify Router]: Controller not found.")
controller: callable = controllerOpt
ctx = {
"code": 200,
"success": "Welcome to Arnelify Router"
}
res: dict = controller(ctx)
print("[Arnelify Router]: Response: " + json.dumps(res))
if __name__ == "__main__":
main()