mirror of
https://github.com/ForFarmTeam/ForFarm.git
synced 2025-12-18 13:34:08 +01:00
feat: add hello route
This commit is contained in:
parent
a1f9a8afdc
commit
126f3754f1
@ -2,16 +2,37 @@ package api
|
||||
|
||||
import (
|
||||
"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 {
|
||||
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) {
|
||||
resp := &HelloworldOutput{}
|
||||
resp.Body.Message = "Hello, world!"
|
||||
func (a *api) registerHelloRoutes(_ chi.Router, api huma.API) {
|
||||
tags := []string{"hello"}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user