github.com/abolfazlbeh/zhycan@v0.0.0-20230819144214-24cf38237387/cmd/cmd_main/commands/templates/app.controller.gotmpl (about)

     1  /*
     2  Create By Zhycan Framework
     3  
     4  Copyright © {{.Year}}
     5  Project: {{.ProjectName}}
     6  File: `app/controller.go` --> {{ .Time.Format .TimeFormat }} by {{.CreatorUserName}}
     7  ------------------------------
     8  */
     9  
    10  package app
    11  
    12  import (
    13      "fmt"
    14      "github.com/gofiber/fiber/v2"
    15      "github.com/abolfazlbeh/zhycan/pkg/http"
    16  )
    17  
    18  // MARK: Controller
    19  
    20  // SampleController - a sample controller to show the functionality
    21  type SampleController struct {}
    22  
    23  // Routes - returning controller specific routes to be registered
    24  func (ctrl *SampleController) Routes() []http.HttpRoute {
    25      return []http.HttpRoute {
    26          http.HttpRoute {
    27              Method:     http.MethodGet,
    28              Path:       "/hello",
    29              RouteName:  "hello",
    30              F:          &ctrl.GetHello,
    31          },
    32      }
    33  }
    34  
    35  // GetHello - just return the 'Hello World' string to user
    36  func (ctrl *SampleController) GetHello(c *fiber.Ctx) error {
    37      return c.SendString("Hello World")
    38  }
    39  
    40  // MARK: gRPC Controller
    41  // SampleProtoController - a sample protobuf controller to show the functionality
    42  type SampleProtoController struct {}
    43  
    44  func (ctrl *SampleProtoController) SayHello(ctx context.Context, rq *pb.HelloRequest) (*pb.HelloResponse, error) {
    45      return &pb.HelloResponse {
    46          Message: fmt.Sprintf("Hello, %s", rq.Name),
    47      }, nil
    48  }