Documentation
¶
Index ¶
- Variables
- func Init() error
- func Register[S types.Service[M, REQ, RSP], M types.Model, REQ types.Request, ...](phase consts.Phase)
- type Base
- func (Base[M, REQ, RSP]) Create(*types.ServiceContext, REQ) (RSP, error)
- func (Base[M, REQ, RSP]) CreateAfter(*types.ServiceContext, M) error
- func (Base[M, REQ, RSP]) CreateBefore(*types.ServiceContext, M) error
- func (Base[M, REQ, RSP]) CreateMany(*types.ServiceContext, REQ) (RSP, error)
- func (Base[M, REQ, RSP]) CreateManyAfter(*types.ServiceContext, ...M) error
- func (Base[M, REQ, RSP]) CreateManyBefore(*types.ServiceContext, ...M) error
- func (Base[M, REQ, RSP]) Delete(*types.ServiceContext, REQ) (RSP, error)
- func (Base[M, REQ, RSP]) DeleteAfter(*types.ServiceContext, M) error
- func (Base[M, REQ, RSP]) DeleteBefore(*types.ServiceContext, M) error
- func (Base[M, REQ, RSP]) DeleteMany(*types.ServiceContext, REQ) (RSP, error)
- func (Base[M, REQ, RSP]) DeleteManyAfter(*types.ServiceContext, ...M) error
- func (Base[M, REQ, RSP]) DeleteManyBefore(*types.ServiceContext, ...M) error
- func (Base[M, REQ, RSP]) Export(*types.ServiceContext, ...M) ([]byte, error)
- func (Base[M, REQ, RSP]) Filter(_ *types.ServiceContext, m M) M
- func (Base[M, REQ, RSP]) FilterRaw(_ *types.ServiceContext) string
- func (Base[M, REQ, RSP]) Get(*types.ServiceContext, REQ) (RSP, error)
- func (Base[M, REQ, RSP]) GetAfter(*types.ServiceContext, M) error
- func (Base[M, REQ, RSP]) GetBefore(*types.ServiceContext, M) error
- func (Base[M, REQ, RSP]) Import(*types.ServiceContext, io.Reader) ([]M, error)
- func (Base[M, REQ, RSP]) List(*types.ServiceContext, REQ) (RSP, error)
- func (Base[M, REQ, RSP]) ListAfter(*types.ServiceContext, *[]M) error
- func (Base[M, REQ, RSP]) ListBefore(*types.ServiceContext, *[]M) error
- func (Base[M, REQ, RSP]) Patch(*types.ServiceContext, REQ) (RSP, error)
- func (Base[M, REQ, RSP]) PatchAfter(*types.ServiceContext, M) error
- func (Base[M, REQ, RSP]) PatchBefore(*types.ServiceContext, M) error
- func (Base[M, REQ, RSP]) PatchMany(*types.ServiceContext, REQ) (RSP, error)
- func (Base[M, REQ, RSP]) PatchManyAfter(*types.ServiceContext, ...M) error
- func (Base[M, REQ, RSP]) PatchManyBefore(*types.ServiceContext, ...M) error
- func (Base[M, REQ, RSP]) Update(*types.ServiceContext, REQ) (RSP, error)
- func (Base[M, REQ, RSP]) UpdateAfter(*types.ServiceContext, M) error
- func (Base[M, REQ, RSP]) UpdateBefore(*types.ServiceContext, M) error
- func (Base[M, REQ, RSP]) UpdateMany(*types.ServiceContext, REQ) (RSP, error)
- func (Base[M, REQ, RSP]) UpdateManyAfter(*types.ServiceContext, ...M) error
- func (Base[M, REQ, RSP]) UpdateManyBefore(*types.ServiceContext, ...M) error
- type Factory
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFoundService = errors.New("no service instant matches the give Model interface, skip processing service layer") ErrNotFoundServiceID = errors.New("not found service id in assetIdMap") )
Functions ¶
func Register ¶
func Register[S types.Service[M, REQ, RSP], M types.Model, REQ types.Request, RSP types.Response](phase consts.Phase)
Register registers a service instance for the specified phase.
The service type parameter S can be either a pointer to a struct type (e.g., *MyService) or a non-pointer struct type (e.g., MyService). The function will automatically handle both cases and always store a pointer instance in the service map.
Example usage with pointer type:
type myService struct {
service.Base[*model.User, *request.CreateUserReq, *response.CreateUserRsp]
}
func init() {
service.Register[*myService](consts.PHASE_CREATE)
}
Example usage with non-pointer type:
type myService struct {
service.Base[*model.User, *request.CreateUserReq, *response.CreateUserRsp]
}
func init() {
service.Register[myService](consts.PHASE_CREATE)
}
Logger initialization:
- If Register is called in an "init" function, logger.Service may be nil, and the service.Logger will be set later in service.Init().
- If Register is called after initialization (e.g., in Init function), logger.Service is already available, and the service.Logger will be set directly.
Types ¶
type Base ¶
func (Base[M, REQ, RSP]) Create ¶
func (Base[M, REQ, RSP]) Create(*types.ServiceContext, REQ) (RSP, error)
func (Base[M, REQ, RSP]) CreateAfter ¶
func (Base[M, REQ, RSP]) CreateAfter(*types.ServiceContext, M) error
func (Base[M, REQ, RSP]) CreateBefore ¶
func (Base[M, REQ, RSP]) CreateBefore(*types.ServiceContext, M) error
func (Base[M, REQ, RSP]) CreateMany ¶
func (Base[M, REQ, RSP]) CreateMany(*types.ServiceContext, REQ) (RSP, error)
func (Base[M, REQ, RSP]) CreateManyAfter ¶
func (Base[M, REQ, RSP]) CreateManyAfter(*types.ServiceContext, ...M) error
func (Base[M, REQ, RSP]) CreateManyBefore ¶
func (Base[M, REQ, RSP]) CreateManyBefore(*types.ServiceContext, ...M) error
func (Base[M, REQ, RSP]) Delete ¶
func (Base[M, REQ, RSP]) Delete(*types.ServiceContext, REQ) (RSP, error)
func (Base[M, REQ, RSP]) DeleteAfter ¶
func (Base[M, REQ, RSP]) DeleteAfter(*types.ServiceContext, M) error
func (Base[M, REQ, RSP]) DeleteBefore ¶
func (Base[M, REQ, RSP]) DeleteBefore(*types.ServiceContext, M) error
func (Base[M, REQ, RSP]) DeleteMany ¶
func (Base[M, REQ, RSP]) DeleteMany(*types.ServiceContext, REQ) (RSP, error)
func (Base[M, REQ, RSP]) DeleteManyAfter ¶
func (Base[M, REQ, RSP]) DeleteManyAfter(*types.ServiceContext, ...M) error
func (Base[M, REQ, RSP]) DeleteManyBefore ¶
func (Base[M, REQ, RSP]) DeleteManyBefore(*types.ServiceContext, ...M) error
func (Base[M, REQ, RSP]) Export ¶
func (Base[M, REQ, RSP]) Export(*types.ServiceContext, ...M) ([]byte, error)
func (Base[M, REQ, RSP]) Filter ¶
func (Base[M, REQ, RSP]) Filter(_ *types.ServiceContext, m M) M
func (Base[M, REQ, RSP]) FilterRaw ¶
func (Base[M, REQ, RSP]) FilterRaw(_ *types.ServiceContext) string
func (Base[M, REQ, RSP]) Get ¶
func (Base[M, REQ, RSP]) Get(*types.ServiceContext, REQ) (RSP, error)
func (Base[M, REQ, RSP]) GetAfter ¶
func (Base[M, REQ, RSP]) GetAfter(*types.ServiceContext, M) error
func (Base[M, REQ, RSP]) GetBefore ¶
func (Base[M, REQ, RSP]) GetBefore(*types.ServiceContext, M) error
func (Base[M, REQ, RSP]) List ¶
func (Base[M, REQ, RSP]) List(*types.ServiceContext, REQ) (RSP, error)
func (Base[M, REQ, RSP]) ListAfter ¶
func (Base[M, REQ, RSP]) ListAfter(*types.ServiceContext, *[]M) error
func (Base[M, REQ, RSP]) ListBefore ¶
func (Base[M, REQ, RSP]) ListBefore(*types.ServiceContext, *[]M) error
func (Base[M, REQ, RSP]) Patch ¶
func (Base[M, REQ, RSP]) Patch(*types.ServiceContext, REQ) (RSP, error)
func (Base[M, REQ, RSP]) PatchAfter ¶
func (Base[M, REQ, RSP]) PatchAfter(*types.ServiceContext, M) error
func (Base[M, REQ, RSP]) PatchBefore ¶
func (Base[M, REQ, RSP]) PatchBefore(*types.ServiceContext, M) error
func (Base[M, REQ, RSP]) PatchMany ¶
func (Base[M, REQ, RSP]) PatchMany(*types.ServiceContext, REQ) (RSP, error)
func (Base[M, REQ, RSP]) PatchManyAfter ¶
func (Base[M, REQ, RSP]) PatchManyAfter(*types.ServiceContext, ...M) error
func (Base[M, REQ, RSP]) PatchManyBefore ¶
func (Base[M, REQ, RSP]) PatchManyBefore(*types.ServiceContext, ...M) error
func (Base[M, REQ, RSP]) Update ¶
func (Base[M, REQ, RSP]) Update(*types.ServiceContext, REQ) (RSP, error)
func (Base[M, REQ, RSP]) UpdateAfter ¶
func (Base[M, REQ, RSP]) UpdateAfter(*types.ServiceContext, M) error
func (Base[M, REQ, RSP]) UpdateBefore ¶
func (Base[M, REQ, RSP]) UpdateBefore(*types.ServiceContext, M) error
func (Base[M, REQ, RSP]) UpdateMany ¶
func (Base[M, REQ, RSP]) UpdateMany(*types.ServiceContext, REQ) (RSP, error)
func (Base[M, REQ, RSP]) UpdateManyAfter ¶
func (Base[M, REQ, RSP]) UpdateManyAfter(*types.ServiceContext, ...M) error
func (Base[M, REQ, RSP]) UpdateManyBefore ¶
func (Base[M, REQ, RSP]) UpdateManyBefore(*types.ServiceContext, ...M) error
type Factory ¶
Factory produces service instances; instances should be registered via Register() in init(). User-defined services are typically unexported; instances are obtained via NewFactory().Service(phase).
func NewFactory ¶ added in v0.10.13
NewFactory returns a factory that produces service instances for the given model/request/response types.