service

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2023 License: Apache-2.0 Imports: 43 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

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

func NewHandler

func NewHandler(service *Service, pool *buffer.Pool, maxDuration time.Duration) *Handler

NewHandler creates a new HTTP service Handler

func (*Handler) NewContext

func (h *Handler) NewContext() (context.Context, context.CancelFunc)

NewContext creates a new context

func (*Handler) ServeHTTP

func (h *Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request)

ServeHTTP serve HTTP

type Option

type Option interface {
	Apply(c *Service)
}

func WithDataStorer

func WithDataStorer(storer datastore.Storer) Option

WithDataStorer creates dictionary option

type Request

type Request struct {
	Body  []byte // usually the POST JSON content
	Feeds []interface{}
	// contains filtered or unexported fields
}

Request represents the server-side post-processed information about a request. There is no strict struct for request payload since some of the keys of the request are dynamically generated based on the model inputs. See shared/client.Message for client-side perspective.

func (*Request) NKeys

func (r *Request) NKeys() int

NKeys a gojay feature, set to 0 to handle "improper" (but syntactically valid) requests (duplicate JSON keys)

func (*Request) Put

func (r *Request) Put(key string, value string) error

Put is used when constructing a request NOT using gojay.

func (*Request) UnmarshalJSONObject

func (r *Request) UnmarshalJSONObject(dec *gojay.Decoder, key string) error

UnmarshalJSONObject gojay implementation; see service.(*Handler).serveHTTP() There is some polymorphism involved, as well as loose-typing. Model inputs aren't strictly typed from the perspective of the request. The primary polymorphism comes from the support for multiple rows worth of inputs. There are 2 optional keys that aren't part of the model input: "batch_size" and "cache_key". If the key "batch_size" is provided, then the keys' values should be an array of scalars; otherwise, the keys' values can be a single scalar. The key "cache_key" is used for caching, and should be an array of strings if "batch_size" is provided.

func (*Request) Validate

func (r *Request) Validate() error

Validate is only used server-side. Extra fields are ignored.

type Response

type Response struct {
	Status         string
	Error          string
	DictHash       int
	Data           interface{}
	ServiceTimeMcs int
	// contains filtered or unexported fields
}

Response represents service response

func (*Response) IsNil

func (r *Response) IsNil() bool

IsNil returns true if nil (gojay json API)

func (*Response) MarshalJSONObject

func (r *Response) MarshalJSONObject(enc *gojay.Encoder)

MarshalJSONObject marshal response

func (*Response) SetError

func (r *Response) SetError(err error)

SetError sets errors

type Service

type Service struct {
	ReloadOK int32
	// contains filtered or unexported fields
}

Service represents ml service

func New

func New(ctx context.Context, fs afs.Service, cfg *config.Model, metrics *gmetric.Service, datastores map[string]*datastore.Service, options ...Option) (*Service, error)

New creates a service

func (*Service) Close

func (s *Service) Close() error

Close closes service

func (*Service) Config

func (s *Service) Config() *config.Model

Config returns service config

func (*Service) Dictionary

func (s *Service) Dictionary() *common.Dictionary

Dictionary returns service dictionary

func (*Service) Do

func (s *Service) Do(ctx context.Context, request *Request, response *Response) error

Do handles service request

func (*Service) NewRequest

func (s *Service) NewRequest() *Request

NewRequest creates a new request

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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