Documentation ¶
Index ¶
- Constants
- Variables
- func BadRequest(response *restful.Response, err error)
- func Error(response *restful.Response, httpStatus int, responseError error)
- func InternalServerError(response *restful.Response, err error)
- func Ok(response *restful.Response, content interface{})
- func PageNotFound(response *restful.Response, err error)
- func ParseDuration(request *restful.Request, name string) (time.Duration, error)
- func ParseInt(request *restful.Request, name string, fallback int) (value int, err error)
- func Text(response *restful.Response, content string)
- type CacheModification
- type Feedback
- type FeedbackIterator
- type HealthStatus
- type HiddenItemsManager
- type Item
- type ItemIterator
- type LocalCache
- type Measurement
- type PopularItemsCache
- type Recommender
- type RestServer
- func (s *RestServer) AuthFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)
- func (s *RestServer) CreateWebService()
- func (s *RestServer) FilterOutHiddenScores(response *restful.Response, items []cache.Scored, category string) []cache.Scored
- func (s *RestServer) GetMeasurements(ctx context.Context, name string, n int) ([]Measurement, error)
- func (s *RestServer) InsertFeedbackToCache(ctx context.Context, feedback []data.Feedback) error
- func (s *RestServer) InsertMeasurement(ctx context.Context, measurements ...Measurement) error
- func (s *RestServer) LogFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)
- func (s *RestServer) MetricsFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)
- func (s *RestServer) Recommend(ctx context.Context, response *restful.Response, userId, category string, ...) ([]string, error)
- func (s *RestServer) RecommendCollaborative(ctx *recommendContext) error
- func (s *RestServer) RecommendItemBased(ctx *recommendContext) error
- func (s *RestServer) RecommendLatest(ctx *recommendContext) error
- func (s *RestServer) RecommendOffline(ctx *recommendContext) error
- func (s *RestServer) RecommendPopular(ctx *recommendContext) error
- func (s *RestServer) RecommendUserBased(ctx *recommendContext) error
- func (s *RestServer) StartHttpServer(container *restful.Container)
- type ScoredItem
- type Server
- type Success
- type UserIterator
Constants ¶
const ( HealthAPITag = "health" UsersAPITag = "users" ItemsAPITag = "items" FeedbackAPITag = "feedback" RecommendationAPITag = "recommendation" MeasurementsAPITag = "measurements" DepractedAPITag = "deprecated" )
Variables ¶
var ( RestAPIRequestSecondsVec = promauto.NewHistogramVec(prometheus.HistogramOpts{ Namespace: "gorse", Subsystem: "server", Name: "rest_api_request_seconds", }, []string{"api"}) )
Functions ¶
func BadRequest ¶
func BadRequest(response *restful.Response, err error)
BadRequest returns a bad request error.
func InternalServerError ¶
func InternalServerError(response *restful.Response, err error)
InternalServerError returns a internal server error.
func Ok ¶
func Ok(response *restful.Response, content interface{})
Ok sends the content as JSON to the client.
func PageNotFound ¶
func PageNotFound(response *restful.Response, err error)
PageNotFound returns a not found error.
func ParseDuration ¶ added in v0.4.0
ParseDuration parses duration from the query parameter.
Types ¶
type CacheModification ¶ added in v0.4.1
type CacheModification struct {
// contains filtered or unexported fields
}
func NewCacheModification ¶ added in v0.4.1
func NewCacheModification(client cache.Database, hiddenItemsManager *HiddenItemsManager) *CacheModification
func (*CacheModification) Exec ¶ added in v0.4.1
func (cm *CacheModification) Exec() error
func (*CacheModification) HideItem ¶ added in v0.4.1
func (cm *CacheModification) HideItem(itemId string) *CacheModification
type Feedback ¶
type Feedback struct { data.FeedbackKey Timestamp string Comment string }
Feedback is the data structure for the feedback but stores the timestamp using string.
type FeedbackIterator ¶
FeedbackIterator is the iterator for feedback.
type HealthStatus ¶ added in v0.4.10
type HiddenItemsManager ¶ added in v0.4.1
type HiddenItemsManager struct {
// contains filtered or unexported fields
}
func NewHiddenItemsManager ¶ added in v0.4.1
func NewHiddenItemsManager(s *RestServer) *HiddenItemsManager
func (*HiddenItemsManager) IsHidden ¶ added in v0.4.1
func (hc *HiddenItemsManager) IsHidden(members []string, category string) ([]bool, error)
func (*HiddenItemsManager) IsHiddenInCache ¶ added in v0.4.4
func (hc *HiddenItemsManager) IsHiddenInCache(member string, category string) bool
type Item ¶
type Item struct { ItemId string IsHidden bool Categories []string Timestamp string Labels []string Comment string }
Item is the data structure for the item but stores the timestamp using string.
type ItemIterator ¶
ItemIterator is the iterator for items.
type LocalCache ¶
type LocalCache struct { ServerName string // contains filtered or unexported fields }
LocalCache is local cache for the server node.
func LoadLocalCache ¶
func LoadLocalCache(path string) (*LocalCache, error)
LoadLocalCache loads local cache from a file.
func (*LocalCache) WriteLocalCache ¶
func (s *LocalCache) WriteLocalCache() error
WriteLocalCache writes local cache to a file.
type Measurement ¶ added in v0.4.2
Measurement stores a statistical value.
func NewMeasurementFromScore ¶ added in v0.4.2
func NewMeasurementFromScore(name string, score cache.Scored) (Measurement, error)
func (Measurement) GetScore ¶ added in v0.4.2
func (m Measurement) GetScore() cache.Scored
type PopularItemsCache ¶ added in v0.4.1
type PopularItemsCache struct {
// contains filtered or unexported fields
}
func NewPopularItemsCache ¶ added in v0.4.1
func NewPopularItemsCache(s *RestServer) *PopularItemsCache
func (*PopularItemsCache) GetSortedScore ¶ added in v0.4.1
func (sc *PopularItemsCache) GetSortedScore(member string) float64
type Recommender ¶ added in v0.2.5
type Recommender func(ctx *recommendContext) error
type RestServer ¶
type RestServer struct { *config.Settings HttpHost string HttpPort int DisableLog bool WebService *restful.WebService HttpServer *http.Server PopularItemsCache *PopularItemsCache HiddenItemsManager *HiddenItemsManager }
RestServer implements a REST-ful API server.
func (*RestServer) AuthFilter ¶ added in v0.3.3
func (s *RestServer) AuthFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)
func (*RestServer) CreateWebService ¶
func (s *RestServer) CreateWebService()
CreateWebService creates web service.
func (*RestServer) FilterOutHiddenScores ¶ added in v0.3.4
func (*RestServer) GetMeasurements ¶ added in v0.4.2
func (s *RestServer) GetMeasurements(ctx context.Context, name string, n int) ([]Measurement, error)
func (*RestServer) InsertFeedbackToCache ¶
InsertFeedbackToCache inserts feedback to cache.
func (*RestServer) InsertMeasurement ¶ added in v0.4.2
func (s *RestServer) InsertMeasurement(ctx context.Context, measurements ...Measurement) error
func (*RestServer) LogFilter ¶ added in v0.4.0
func (s *RestServer) LogFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)
func (*RestServer) MetricsFilter ¶ added in v0.4.1
func (s *RestServer) MetricsFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)
func (*RestServer) Recommend ¶
func (s *RestServer) Recommend(ctx context.Context, response *restful.Response, userId, category string, n int, recommenders ...Recommender) ([]string, error)
Recommend items to users. 1. If there are recommendations in cache, return cached recommendations. 2. If there are historical interactions of the users, return similar items. 3. Otherwise, return fallback recommendation (popular/latest).
func (*RestServer) RecommendCollaborative ¶ added in v0.2.8
func (s *RestServer) RecommendCollaborative(ctx *recommendContext) error
func (*RestServer) RecommendItemBased ¶ added in v0.2.8
func (s *RestServer) RecommendItemBased(ctx *recommendContext) error
func (*RestServer) RecommendLatest ¶ added in v0.3.1
func (s *RestServer) RecommendLatest(ctx *recommendContext) error
func (*RestServer) RecommendOffline ¶ added in v0.2.8
func (s *RestServer) RecommendOffline(ctx *recommendContext) error
func (*RestServer) RecommendPopular ¶ added in v0.3.1
func (s *RestServer) RecommendPopular(ctx *recommendContext) error
func (*RestServer) RecommendUserBased ¶ added in v0.2.8
func (s *RestServer) RecommendUserBased(ctx *recommendContext) error
func (*RestServer) StartHttpServer ¶
func (s *RestServer) StartHttpServer(container *restful.Container)
StartHttpServer starts the REST-ful API server.
type ScoredItem ¶ added in v0.4.15
type Server ¶
type Server struct { RestServer // contains filtered or unexported fields }
Server manages states of a server node.
type Success ¶
type Success struct {
RowAffected int
}
Success is the returned data structure for data insert operations.