roomapi

package
v0.0.0-...-19f3900 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2024 License: GPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const ProtoVersion = 1

Variables

This section is empty.

Functions

func HandleServer

func HandleServer(log *slog.Logger, mux *http.ServeMux, prefix string, a API, cfg ServerConfig) error

func IsErrorRetriable

func IsErrorRetriable(err error) bool

func MatchesError

func MatchesError(err error, code ErrorCode) bool

Types

type API

type API interface {
	Update(ctx context.Context, req *UpdateRequest) (*UpdateResponse, error)
	Job(ctx context.Context, req *JobRequest) (*JobResponse, error)
	Hello(ctx context.Context, req *HelloRequest) (*HelloResponse, error)
	Bye(ctx context.Context, req *ByeRequest) (*ByeResponse, error)
}

func NewClient

func NewClient(o ClientOptions, httpClient *http.Client) API

type ByeRequest

type ByeRequest struct {
	RoomID string `json:"room_id"`
}

type ByeResponse

type ByeResponse struct{}

type ClientOptions

type ClientOptions struct {
	Endpoint string
	Token    string
}

type Error

type Error struct {
	Code    ErrorCode `json:"code"`
	Message string    `json:"message"`
}

func (*Error) Error

func (e *Error) Error() string

type ErrorCode

type ErrorCode int
const (
	ErrInvalidCode ErrorCode = iota
	ErrNeedsResync
	ErrNoSuchRoom
	ErrNoJob
	ErrNoJobRunning
	ErrBadToken
	ErrBadRequest
	ErrIncompatibleProto
	ErrLocked
	ErrTemporarilyUnavailable
	ErrOutOfSequence
)

type HelloRequest

type HelloRequest struct {
	SupportedProtoVersions []int32 `json:"supported_proto_versions"`
}

type HelloResponse

type HelloResponse struct {
	RoomID       string `json:"room_id"`
	ProtoVersion int32  `json:"proto_version"`
}

type Job

type Job struct {
	ID             string          `json:"id" gorm:"primaryKey"`
	FixedTime      *time.Duration  `json:"fixed_time,omitempty"`
	TimeControl    *clock.Control  `json:"time_control,omitempty" gorm:"serializer:chess"`
	StartBoard     *chess.RawBoard `json:"start_board,omitempty" gorm:"serializer:chess"`
	StartMoves     []chess.UCIMove `json:"start_moves,omitempty" gorm:"serializer:json"`
	ScoreThreshold int32           `json:"score_threshold,omitempty"`
	TimeMargin     *time.Duration  `json:"time_margin,omitempty"`
	White          JobEngine       `json:"white" gorm:"serializer:json"`
	Black          JobEngine       `json:"black" gorm:"serializer:json"`
}

func (Job) Clone

func (j Job) Clone() Job

type JobEngine

type JobEngine struct {
	Name string `json:"name"`
}

func (JobEngine) Clone

func (e JobEngine) Clone() JobEngine

type JobRequest

type JobRequest struct {
	SeqIndex uint64        `json:"seq_index"`
	RoomID   string        `json:"room_id"`
	Timeout  time.Duration `json:"timeout"`
}

type JobResponse

type JobResponse struct {
	Job Job `json:"job"`
}

type ServerConfig

type ServerConfig struct {
	TokenChecker TokenChecker
}

type TokenChecker

type TokenChecker func(token string) error

type UpdateRequest

type UpdateRequest struct {
	SeqIndex  uint64          `json:"seq_index"`
	RoomID    string          `json:"room_id"`
	JobID     string          `json:"job_id"`
	From      delta.JobCursor `json:"from"`
	Delta     *delta.JobState `json:"delta"`
	Timestamp delta.Timestamp `json:"ts"`
	Status    UpdateStatus    `json:"status,omitempty"`
	Error     string          `json:"error,omitempty"`
}

type UpdateResponse

type UpdateResponse struct{}

type UpdateStatus

type UpdateStatus string
const (
	UpdateContinue UpdateStatus = ""
	UpdateDone     UpdateStatus = "done"
	UpdateFail     UpdateStatus = "fail"
	UpdateAbort    UpdateStatus = "abort"
)

Jump to

Keyboard shortcuts

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