server

package
v0.4.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 16, 2022 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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

func ParseDuration(request *restful.Request, name string) (time.Duration, error)

ParseDuration parses duration from the query parameter.

func ParseInt

func ParseInt(request *restful.Request, name string, fallback int) (value int, err error)

ParseInt parses integers from the query parameter.

func Text

func Text(response *restful.Response, content string)

Text returns a plain text.

Types

type CacheModification

type CacheModification struct {
	// contains filtered or unexported fields
}

func NewCacheModification

func NewCacheModification(client cache.Database, hiddenItemsManager *HiddenItemsManager) *CacheModification

func (*CacheModification) Exec

func (cm *CacheModification) Exec() error

func (*CacheModification) HideItem

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.

func (Feedback) ToDataFeedback

func (f Feedback) ToDataFeedback() (data.Feedback, error)

type FeedbackIterator

type FeedbackIterator struct {
	Cursor   string
	Feedback []data.Feedback
}

FeedbackIterator is the iterator for feedback.

type HiddenItemsManager

type HiddenItemsManager struct {
	// contains filtered or unexported fields
}

func NewHiddenItemsManager

func NewHiddenItemsManager(s *RestServer) *HiddenItemsManager

func (*HiddenItemsManager) IsHidden

func (hc *HiddenItemsManager) IsHidden(members []string, category string) ([]bool, error)

func (*HiddenItemsManager) IsHiddenInCache

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

type ItemIterator struct {
	Cursor string
	Items  []data.Item
}

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

type Measurement struct {
	Name      string
	Timestamp time.Time
	Value     float32
}

Measurement stores a statistical value.

func NewMeasurementFromScore

func NewMeasurementFromScore(name string, score cache.Scored) (Measurement, error)

func (Measurement) GetScore

func (m Measurement) GetScore() cache.Scored

type PopularItemsCache

type PopularItemsCache struct {
	// contains filtered or unexported fields
}

func NewPopularItemsCache

func NewPopularItemsCache(s *RestServer) *PopularItemsCache

func (*PopularItemsCache) GetSortedScore

func (sc *PopularItemsCache) GetSortedScore(member string) float64

type Recommender

type Recommender func(ctx *recommendContext) error

type RestServer

type RestServer struct {
	OneMode bool
	*config.Settings

	HttpHost    string
	HttpPort    int
	IsDashboard bool
	DisableLog  bool
	WebService  *restful.WebService

	PopularItemsCache  *PopularItemsCache
	HiddenItemsManager *HiddenItemsManager
}

RestServer implements a REST-ful API server.

func (*RestServer) AuthFilter

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

func (s *RestServer) FilterOutHiddenScores(response *restful.Response, items []cache.Scored, category string) []cache.Scored

func (*RestServer) GetMeasurements

func (s *RestServer) GetMeasurements(name string, n int) ([]Measurement, error)

func (*RestServer) InsertFeedbackToCache

func (s *RestServer) InsertFeedbackToCache(feedback []data.Feedback) error

InsertFeedbackToCache inserts feedback to cache.

func (*RestServer) InsertMeasurement

func (s *RestServer) InsertMeasurement(measurements ...Measurement) error

func (*RestServer) LogFilter

func (s *RestServer) LogFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)

func (*RestServer) MetricsFilter

func (s *RestServer) MetricsFilter(req *restful.Request, resp *restful.Response, chain *restful.FilterChain)

func (*RestServer) Recommend

func (s *RestServer) Recommend(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

func (s *RestServer) RecommendCollaborative(ctx *recommendContext) error

func (*RestServer) RecommendItemBased

func (s *RestServer) RecommendItemBased(ctx *recommendContext) error

func (*RestServer) RecommendLatest

func (s *RestServer) RecommendLatest(ctx *recommendContext) error

func (*RestServer) RecommendOffline

func (s *RestServer) RecommendOffline(ctx *recommendContext) error

func (*RestServer) RecommendPopular

func (s *RestServer) RecommendPopular(ctx *recommendContext) error

func (*RestServer) RecommendUserBased

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 Server

type Server struct {
	RestServer
	// contains filtered or unexported fields
}

Server manages states of a server node.

func NewServer

func NewServer(masterHost string, masterPort int, serverHost string, serverPort int, cacheFile string) *Server

NewServer creates a server node.

func (*Server) Serve

func (s *Server) Serve()

Serve starts a server node.

func (*Server) SetOneMode

func (s *Server) SetOneMode(settings *config.Settings)

func (*Server) Sync

func (s *Server) Sync()

Sync this server to the master.

type Success

type Success struct {
	RowAffected int
}

Success is the returned data structure for data insert operations.

type UserIterator

type UserIterator struct {
	Cursor string
	Users  []data.User
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL