Skip to content

Commit

Permalink
Moved /extra/fuegogin/lib to /examples/gin-compat
Browse files Browse the repository at this point in the history
  • Loading branch information
EwenQuim committed Dec 17, 2024
1 parent a4861bb commit 8251355
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 53 deletions.
47 changes: 47 additions & 0 deletions examples/gin-compat/handlers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main

import (
"fmt"
"net/http"

"github.com/gin-gonic/gin"

"github.com/go-fuego/fuego"
"github.com/go-fuego/fuego/extra/fuegogin"
)

func ginController(c *gin.Context) {
c.String(200, "pong")
}

func fuegoControllerGet(c fuegogin.ContextNoBody) (HelloResponse, error) {
return HelloResponse{
Message: "Hello",
}, nil
}

func fuegoControllerPost(c fuegogin.ContextWithBody[HelloRequest]) (HelloResponse, error) {
body, err := c.Body()
if err != nil {
return HelloResponse{}, err
}

name := c.QueryParam("name")

return HelloResponse{
Message: fmt.Sprintf("Hello %s, %s", body.Word, name),
}, nil
}

func serveController(s *fuego.OpenAPI) func(ctx *gin.Context) {
return func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, s.Description())
}
}

func DefaultOpenAPIHandler(specURL string) gin.HandlerFunc {
return func(ctx *gin.Context) {
ctx.Header("Content-Type", "text/html; charset=utf-8")
ctx.String(200, fuego.DefaultOpenAPIHTML(specURL))
}
}
42 changes: 4 additions & 38 deletions extra/fuegogin/lib/lib.go → examples/gin-compat/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package lib
package main

import (
"fmt"
"net/http"

"github.com/gin-gonic/gin"

Expand All @@ -20,7 +19,7 @@ type HelloResponse struct {
Message string `json:"message"`
}

func SetupGin() (*gin.Engine, *fuego.OpenAPI) {
func main() {
e := gin.Default()
openapi := fuego.NewOpenAPI()

Expand Down Expand Up @@ -48,41 +47,8 @@ func SetupGin() (*gin.Engine, *fuego.OpenAPI) {

fmt.Println("OpenAPI at at http://localhost:8980/swagger")

return e, openapi
}

func ginController(c *gin.Context) {
c.String(200, "pong")
}

func fuegoControllerGet(c fuegogin.ContextNoBody) (HelloResponse, error) {
return HelloResponse{
Message: "Hello",
}, nil
}

func fuegoControllerPost(c fuegogin.ContextWithBody[HelloRequest]) (HelloResponse, error) {
body, err := c.Body()
err := e.Run(":8980")
if err != nil {
return HelloResponse{}, err
}

name := c.QueryParam("name")

return HelloResponse{
Message: fmt.Sprintf("Hello %s, %s", body.Word, name),
}, nil
}

func serveController(s *fuego.OpenAPI) func(ctx *gin.Context) {
return func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, s.Description())
}
}

func DefaultOpenAPIHandler(specURL string) gin.HandlerFunc {
return func(ctx *gin.Context) {
ctx.Header("Content-Type", "text/html; charset=utf-8")
ctx.String(200, fuego.DefaultOpenAPIHTML(specURL))
panic(err)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package lib
package main

import (
"net/url"
Expand Down
14 changes: 0 additions & 14 deletions extra/fuegogin/serve/main.go

This file was deleted.

0 comments on commit 8251355

Please sign in to comment.