function
新建function
package function
import (
"custom-go/pkg/base"
"custom-go/pkg/plugins"
"custom-go/pkg/wgpb"
)
func init() {
// 注册 function
plugins.RegisterFunction[helloReq, helloRes](hello, wgpb.OperationType_MUTATION)
}
type helloReq struct {
Username string `json:"username"`
Password string `json:"password"`
Info helloInfo `json:"info,omitempty"`
}
type helloInfo struct {
Code string `json:"code,omitempty"`
Captcha string `json:"captcha,omitempty"`
}
type helloRes struct {
Msg string `json:"msg"`
Data string `json:"data"`
}
func hello(hook *base.HookRequest, body *base.OperationBody[helloReq, helloRes]) (*base.OperationBody[helloReq, helloRes], error) {
if body.Input.Username != "John" || body.Input.Password != "123456" {
body.Response = &base.OperationBodyResponse[helloRes]{
Errors: []base.GraphQLError{{Message: "username or password wrong"}},
}
return body, nil
}
body.Response = &base.OperationBodyResponse[helloRes]{Data: helloRes{Msg: "hello success"}}
return body, nil
}

最后更新于