handler

package
v0.0.0-...-b37c17f Latest Latest
Warning

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

Go to latest
Published: May 12, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

from https://echo.labstack.com/docs/cookbook/sse

Index

Constants

View Source
const (
	KeyErrCode         = "errCode"
	KeyUsername        = "username"
	KeyUuid            = "uuid"
	CookieAccessToken  = "accessToken"
	CookieRefreshToken = "refreshToken"
	CookieInfoToken    = "infoToken"
	ActionChat         = "chat"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	// ID is used to set the EventSource object's last event ID value.
	ID []byte
	// Data field is for the message. When the EventSource receives multiple consecutive lines
	// that begin with data:, it concatenates them, inserting a newline character between each one.
	// Trailing newlines are removed.
	Data []byte
	// Event is a string identifying the type of event described. If this is specified, an event
	// will be dispatched on the browser to the listener for the specified event name; the website
	// source code should use addEventListener() to listen for named events. The onmessage handler
	// is called if no event name is specified for a message.
	Event []byte
	// Retry is the reconnection time. If the connection to the server is lost, the browser will
	// wait for the specified time before attempting to reconnect. This must be an integer, specifying
	// the reconnection time in milliseconds. If a non-integer value is specified, the field is ignored.
	Retry []byte
	// Comment line can be used to prevent connections from timing out; a server can send a comment
	// periodically to keep the connection alive.
	Comment []byte
}

Event represents Server-Sent Event. SSE explanation: https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events/Using_server-sent_events#event_stream_format

func (*Event) MarshalTo

func (ev *Event) MarshalTo(w io.Writer) error

MarshalTo marshals Event to given Writer

type Handler

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

func New

func New(conf *util.Configuration, logger util.ILogger,
	modelService *service.Model, oAuthService *service.OAuth, messageService *service.Message, openAiService *service.OpenAi,
	userService *service.User,
) (*Handler, error)

func (*Handler) Authorize

func (h *Handler) Authorize(c echo.Context) error

func (*Handler) ListenAndServe

func (h *Handler) ListenAndServe() error

func (*Handler) Refresh

func (h *Handler) Refresh(c echo.Context) error

Refresh will first verify the access token, if not valid, it will try to refresh the token

func (*Handler) Shutdown

func (h *Handler) Shutdown(ctx context.Context) error

Jump to

Keyboard shortcuts

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