package api import ( "github.com/yaoapp/gou/process" "github.com/yaoapp/kun/exception" "github.com/yaoapp/yao/sui/core" ) func init() { process.RegisterGroup("sui", map[string]process.Handler{ "template.get": TemplateGet, "template.find": TemplateFind, }) } // TemplateGet handle the get Template request // Process sui..templates func TemplateGet(process *process.Process) interface{} { process.ValidateArgNums(1) sui := get(process) templates, err := sui.GetTemplates() if err != nil { exception.New(err.Error(), 500).Throw() } return templates } // TemplateFind handle the find Template request func TemplateFind(process *process.Process) interface{} { process.ValidateArgNums(2) sui := get(process) template, err := sui.GetTemplate(process.ArgsString(1)) if err != nil { exception.New(err.Error(), 500).Throw() } return template } // get the sui func get(process *process.Process) core.SUI { sui, has := core.SUIs[process.ArgsString(0)] if !has { exception.New("the sui %s does not exist", 404, process.ID).Throw() } return sui }