Documentation
¶
Index ¶
- Constants
- Variables
- func FormatValidationErrors(err error) string
- func JWTMiddleware(a core.AuthStore) router.Middleware
- func SessionFromRequest(r *http.Request) core.Session
- type AddRoomMemberPayload
- type App
- func (app *App) AddCleanupFunc(f func(context.Context))
- func (app *App) IsOnlineHandler(ctx context.Context, e *core.Event) error
- func (app *App) MessageEventHandler(ctx context.Context, e *core.Event) error
- func (app *App) ReadMessageHandler(ctx context.Context, e *core.Event) error
- func (app *App) Start()
- func (app *App) TypingHandler(ctx context.Context, e *core.Event) error
- type AuthHandler
- type Authenticator
- type Base64Encoded
- type ChatHandler
- func (h *ChatHandler) AddRoomMemberHandler(w http.ResponseWriter, r *http.Request) error
- func (h *ChatHandler) CreateRoomHandler(w http.ResponseWriter, r *http.Request) error
- func (h *ChatHandler) GetMyRoomsHandler(w http.ResponseWriter, r *http.Request) error
- func (h *ChatHandler) GetRoomByIDHandler(w http.ResponseWriter, r *http.Request) error
- func (h *ChatHandler) GetRoomMessagesHandler(w http.ResponseWriter, r *http.Request) error
- func (h *ChatHandler) GetRoomUserRoomsHandler(w http.ResponseWriter, r *http.Request) error
- func (h *ChatHandler) RemoveRoomMemberHandler(w http.ResponseWriter, r *http.Request) error
- func (h *ChatHandler) SendMessageHandler(w http.ResponseWriter, r *http.Request) error
- type Config
- type CreateRoomPayload
- type CreateRoomResponse
- type IsInRoomResponse
- type IsOnlineEventPayload
- type MessageEventPayload
- type OfflineEventPayload
- type OnlineEventPayload
- type ReadMessageEventPayload
- type SigninPayload
- type StaticFS
- type TypingEventPayload
- type UserHandler
Constants ¶
View Source
const ( MessageEvent = "message" ReadMessageEvent = "read_message" OnlineEvent = "online" OfflineEvent = "offline" IsOnlineEvent = "is_online" TypingEvent = "typing" )
View Source
const (
AuthCookieName = "auth_token"
)
Variables ¶
View Source
var ( DevMode = "dev" ProdMode = "prod" )
Functions ¶
func FormatValidationErrors ¶
func JWTMiddleware ¶
func JWTMiddleware(a core.AuthStore) router.Middleware
JWTMiddleware extracts the JWT token from the request and validates it and attaches the session to the request context. The session is gaurenteed to be attached to the request context if the JWT token is valid for subsequent handlers.
Types ¶
type AddRoomMemberPayload ¶
type AddRoomMemberPayload struct {
Username string `json:"username" validate:"required"`
Role core.MemberRole `json:"role" validate:"required"`
}
type App ¶
type App struct {
// contains filtered or unexported fields
}
func (*App) AddCleanupFunc ¶
func (*App) IsOnlineHandler ¶
func (*App) MessageEventHandler ¶
func (*App) ReadMessageHandler ¶
type AuthHandler ¶
type AuthHandler struct {
// contains filtered or unexported fields
}
func NewAuthHandler ¶
func NewAuthHandler(store core.AuthStore) *AuthHandler
func (*AuthHandler) SigninHandler ¶
func (h *AuthHandler) SigninHandler(w http.ResponseWriter, r *http.Request) error
func (*AuthHandler) SignoutHandler ¶
func (h *AuthHandler) SignoutHandler(w http.ResponseWriter, r *http.Request) error
type Authenticator ¶
type Authenticator struct {
}
func (*Authenticator) Authenticate ¶
func (a *Authenticator) Authenticate(r *http.Request) (string, error)
type Base64Encoded ¶
type Base64Encoded []byte
func (*Base64Encoded) UnmarshalText ¶
func (b *Base64Encoded) UnmarshalText(text []byte) error
type ChatHandler ¶
type ChatHandler struct {
// contains filtered or unexported fields
}
func NewChatHandler ¶
func NewChatHandler(chatStore core.ChatStore) *ChatHandler
func (*ChatHandler) AddRoomMemberHandler ¶
func (h *ChatHandler) AddRoomMemberHandler(w http.ResponseWriter, r *http.Request) error
func (*ChatHandler) CreateRoomHandler ¶
func (h *ChatHandler) CreateRoomHandler(w http.ResponseWriter, r *http.Request) error
func (*ChatHandler) GetMyRoomsHandler ¶
func (h *ChatHandler) GetMyRoomsHandler(w http.ResponseWriter, r *http.Request) error
func (*ChatHandler) GetRoomByIDHandler ¶
func (h *ChatHandler) GetRoomByIDHandler(w http.ResponseWriter, r *http.Request) error
func (*ChatHandler) GetRoomMessagesHandler ¶
func (h *ChatHandler) GetRoomMessagesHandler(w http.ResponseWriter, r *http.Request) error
func (*ChatHandler) GetRoomUserRoomsHandler ¶
func (h *ChatHandler) GetRoomUserRoomsHandler(w http.ResponseWriter, r *http.Request) error
func (*ChatHandler) RemoveRoomMemberHandler ¶
func (h *ChatHandler) RemoveRoomMemberHandler(w http.ResponseWriter, r *http.Request) error
func (*ChatHandler) SendMessageHandler ¶
func (h *ChatHandler) SendMessageHandler(w http.ResponseWriter, r *http.Request) error
type Config ¶
type Config struct {
// Mode is the mode of the server. The default is dev.jk
Mode string `validate:"required,oneof=dev prod"`
TLS struct {
// Key is the path to the TLS private key file.
// The key must in encoded in PEM format.
Key string `validate:"required_if=Mode prod"`
// Crt is the path to the TLS certificate file.
// The certificate must be in encoded in PEM format.
Crt string `validate:"required_if=Mode prod"`
}
// Port is the Port number to listen on.
// If the Mode is dev, the default is 8080.
// If the Mode is prod, the default is 443.
Port int `validate:"required,port"`
// Hostname is the Hostname to listen on. The default is 0.0.0.0.
Hostname string `validate:"required"`
Auth struct {
// Secret is the Secret key used to sign JWT tokens.
// The secret must be a base64 encoded string. The default is a random 32 byte string.
Secret Base64Encoded `validate:"required"`
}
SQLite struct {
// File is the path to the SQLite database file.
File string `validate:"required" `
// Migrations is the path to the directory that the migration files reside.
Migrations string `validate:"required" `
}
// AllowedOrigins is a list of origins that are allowed to connect to the server.
// The default is ["*"].
// If the Mode is prod, default to [].
AllowedOrigins []string
// contains filtered or unexported fields
}
func LoadConfig ¶
LoadConfig loads the configuration from the config file and environment variables. Any invalid configuration will not be loaded, and the error wil be cought in the validation step.
type CreateRoomPayload ¶
type CreateRoomPayload struct {
Name string `json:"name"`
}
type CreateRoomResponse ¶
type CreateRoomResponse struct {
ID string `json:"id"`
}
type IsInRoomResponse ¶
type IsInRoomResponse struct {
OK bool `json:"ok"`
Role core.MemberRole `json:"role"`
}
type IsOnlineEventPayload ¶
type IsOnlineEventPayload struct {
Username string `json:"username"`
}
type MessageEventPayload ¶
type OfflineEventPayload ¶
type OfflineEventPayload struct {
Username string `json:"username"`
}
type OnlineEventPayload ¶
type OnlineEventPayload struct {
Username string `json:"username"`
}
type ReadMessageEventPayload ¶
type SigninPayload ¶
type StaticFS ¶
type StaticFS struct {
http.FileSystem
// contains filtered or unexported fields
}
StatisFS is a wrapper around http.FileSystem that adds etag support, cache control support and fallback file. It can be used to serve React build files.
func NewStaticFS ¶
NewStaticFS returns a new StaticFS
func (StaticFS) EtagMiddleware ¶
type TypingEventPayload ¶
type UserHandler ¶
type UserHandler struct {
// contains filtered or unexported fields
}
func NewUserHandler ¶
func NewUserHandler(store core.UserStore) *UserHandler
func (*UserHandler) GetUserByUsernameHandler ¶
func (h *UserHandler) GetUserByUsernameHandler(w http.ResponseWriter, r *http.Request) error
func (*UserHandler) MeHandler ¶
func (h *UserHandler) MeHandler(w http.ResponseWriter, r *http.Request) error
func (*UserHandler) RegisterUserHandler ¶
func (h *UserHandler) RegisterUserHandler(w http.ResponseWriter, r *http.Request) error
Click to show internal directories.
Click to hide internal directories.