mirror of
https://github.com/ForFarmTeam/ForFarm.git
synced 2025-12-19 14:04:08 +01:00
feat: add hello route
This commit is contained in:
parent
a1f9a8afdc
commit
126f3754f1
@ -2,16 +2,37 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/danielgtaylor/huma/v2"
|
||||||
|
"github.com/go-chi/chi/v5"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HelloworldOutput struct {
|
type HelloWorldInput struct {
|
||||||
|
MyHeader string `header:"Authorization" required:"true" example:"Bearer token"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type HelloWorldOutput struct {
|
||||||
Body struct {
|
Body struct {
|
||||||
Message string `json:"message" example:"Hello, world!" doc:"Greeting message"`
|
Message string `json:"message" example:"hello world"`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *api) helloWorldHandler(ctx context.Context, input *struct{}) (*HelloworldOutput, error) {
|
func (a *api) registerHelloRoutes(_ chi.Router, api huma.API) {
|
||||||
resp := &HelloworldOutput{}
|
tags := []string{"hello"}
|
||||||
resp.Body.Message = "Hello, world!"
|
|
||||||
|
huma.Register(api, huma.Operation{
|
||||||
|
OperationID: "helloWorld",
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Path: "/hello",
|
||||||
|
Tags: tags,
|
||||||
|
Summary: "Get hello world message",
|
||||||
|
Description: "Returns a simple hello world message",
|
||||||
|
}, a.helloWorldHandler)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *api) helloWorldHandler(ctx context.Context, input *HelloWorldInput) (*HelloWorldOutput, error) {
|
||||||
|
resp := &HelloWorldOutput{}
|
||||||
|
resp.Body.Message = "hello world from forfarm"
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user