This topic describes how to perform hook operations before the PAI-Rec service starts.
Service initialization
Before the PAI-Rec service starts, you can define hookfunc methods and register the methods with the startup process by using AddStartHook. The hookfunc methods are called in sequence according to the registration order before service startup.
func main() {
pairec.AddStartHook(func() error {
precall.RegisterRecall("LiveRoomRecall", recall.NewLiveRoomRecall())
module.RegisterGenerateItemDataFunc(filter.GenerateExposureHistoryItemData)
prank.SetBoostFunc(rank.BoostScore)
return nil
})
pairec.Route("/api/rec/live_room_sync", &controller.LiveRoomSyncController{})
pairec.Route("/api/rec/live_feed", &controller.LiveFeedController{})
pairec.Run()
}Route configuration
PAI-Rec provides the following methods for registering routes, which work in a way similar to Golang HTTP requests:
Use the HandleFunc method:
HandleFunc("/ping", func(w http.ResponseWriter, r *http.Request) { io.WriteString(w, "success") })
Use the controller interface:
Route("/api/recommend", &web.RecommendController{})If you want to use your controller interface, you need to implement the ControllerInterface interface.
type ControllerInterface interface { Process(http.ResponseWriter, *http.Request) }