pink_fox/application/inner/controllers/site_controller.go

49 lines
1.0 KiB
Go

package controllers
import (
"pink_fox/inner/commands"
"pink_fox/packages/fw"
"strings"
)
type SiteController struct {
services SiteControllerService
}
type SiteControllerService interface {
fw.BaseServices
}
func NewSiteController(services SiteControllerService) *SiteController {
return &SiteController{
services: services,
}
}
func (it *SiteController) Index() (fw.Response, fw.Error) {
//return it.services.ResponseFactory().HtmlError(404, "test"), nil
//return nil, fw.ErrStr("site controller not yet implemented")
return it.services.ResponseFactory().View("index.html", map[string]any{
"text": "Hello world",
}), nil
}
type TestActionServices interface {
UserCommand() *commands.UserCommand
}
func (it *SiteController) Test(services TestActionServices) (fw.Response, fw.Error) {
getUserList, err := services.UserCommand().CheckAndFind(100)
if err != nil {
return nil, err.Tap()
}
list, err := getUserList(1000)
if err != nil {
return nil, err.Tap()
}
return it.services.ResponseFactory().String(strings.Join(list, ", ")), nil
}