From 126f3754f1308954ed1528330b8a4e85f7158410 Mon Sep 17 00:00:00 2001 From: Sosokker Date: Thu, 13 Feb 2025 19:35:20 +0700 Subject: [PATCH] feat: add hello route --- backend/internal/api/helloworld.go | 31 +++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/backend/internal/api/helloworld.go b/backend/internal/api/helloworld.go index a1d2664..df72e79 100644 --- a/backend/internal/api/helloworld.go +++ b/backend/internal/api/helloworld.go @@ -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 }