feat: add hello route

This commit is contained in:
Sosokker 2025-02-13 19:35:20 +07:00
parent a1f9a8afdc
commit 126f3754f1

View File

@ -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
}