-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c7c956b
commit 57020b3
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/Trendyol/chaki" | ||
"github.com/Trendyol/chaki/logger" | ||
"github.com/Trendyol/chaki/modules/server" | ||
"github.com/Trendyol/chaki/modules/server/controller" | ||
"github.com/Trendyol/chaki/modules/server/route" | ||
"github.com/Trendyol/chaki/modules/swagger" | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
func main() { | ||
app := chaki.New() | ||
|
||
app.WithOption( | ||
chaki.WithConfigPath("config.yaml"), | ||
) | ||
|
||
app.Use( | ||
server.Module(), | ||
swagger.Module(), | ||
) | ||
|
||
app.Provide( | ||
newController, | ||
) | ||
|
||
logger.Fatal(app.Start()) | ||
} | ||
|
||
type greetRequest struct { | ||
Name string `param:"name" validate:"required"` | ||
} | ||
|
||
type fooController struct { | ||
controller.Controller | ||
} | ||
|
||
func newController() controller.Controller { | ||
return &fooController{ | ||
Controller: controller.New("foo-controller").SetPrefix("/foo"), | ||
} | ||
} | ||
|
||
func (ct *fooController) greet(c *fiber.Ctx) error { | ||
return c.JSON(fmt.Sprintf("Hello %s", c.Params("name"))) | ||
} | ||
|
||
func (ct *fooController) Routes() []route.Route { | ||
return []route.Route{ | ||
route.FiberGet[greetRequest, string]("/:name", ct.greet), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package route | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v2" | ||
) | ||
|
||
func NewFiber[Req, Res any](method, path string, h fiber.Handler) Route { | ||
return newRoute[Req, Res](method, path, h) | ||
} | ||
|
||
func FiberGet[Req, Res any](path string, h fiber.Handler) Route { | ||
return NewFiber[Req, Res](fiber.MethodGet, path, h) | ||
} | ||
|
||
func FiberPost[Req, Res any](path string, h fiber.Handler) Route { | ||
return NewFiber[Req, Res](fiber.MethodPost, path, h) | ||
} | ||
|
||
func FiberDelete[Req, Res any](path string, h fiber.Handler) Route { | ||
return NewFiber[Req, Res](fiber.MethodDelete, path, h) | ||
} | ||
|
||
func FiberPatch[Req, Res any](path string, h fiber.Handler) Route { | ||
return NewFiber[Req, Res](fiber.MethodPatch, path, h) | ||
} | ||
|
||
func FiberPut[Req, Res any](path string, h fiber.Handler) Route { | ||
return NewFiber[Req, Res](fiber.MethodPut, path, h) | ||
} |