Documentation
¶
Index ¶
- Constants
- Variables
- func CreateServerFromInfra(repos domain.Repositories, qs *chat.Queryers, ps chat.Pubsub, conf *Config) (*Server, DoneFunc)
- func ListenAndServe(chatCmd chat.CommandService, chatQuery chat.QueryService, chatHub chat.Hub, ...) error
- func LoggedInUserID(c echo.Context) (uint64, bool)
- func NewHTTPError(statusCode int, msg ...interface{}) *echo.HTTPError
- type Config
- type DoneFunc
- type LoginHandler
- func (lh *LoginHandler) Filter() echo.MiddlewareFunc
- func (lh *LoginHandler) GetLoginState(c echo.Context) error
- func (lh *LoginHandler) IsLoggedInRequest(c echo.Context) bool
- func (lh *LoginHandler) Login(c echo.Context) error
- func (lh *LoginHandler) Logout(c echo.Context) error
- func (lh *LoginHandler) Middleware() echo.MiddlewareFunc
- func (lh *LoginHandler) Session(c echo.Context) (*LoginState, bool)
- type LoginState
- type RESTHandler
- func (rest *RESTHandler) AddRoomMember(e echo.Context) error
- func (rest *RESTHandler) CreateRoom(e echo.Context) error
- func (rest *RESTHandler) DeleteRoom(e echo.Context) error
- func (rest *RESTHandler) GetRoomInfo(e echo.Context) error
- func (rest *RESTHandler) GetRoomMessages(e echo.Context) error
- func (rest *RESTHandler) GetUnreadRoomMessages(e echo.Context) error
- func (rest *RESTHandler) GetUserInfo(e echo.Context) error
- func (rest *RESTHandler) PostRoomMessage(e echo.Context) error
- func (rest *RESTHandler) ReadRoomMessages(e echo.Context) error
- func (rest *RESTHandler) RemoveRoomMember(e echo.Context) error
- type Server
- type UserForm
Constants ¶
const ( KeySessionID = "SESSION-ID" // key for session value which is user loggedin state. KeyLoginState = "LOGIN-STATE" // seconds in 365 days, where 86400 is a seconds in 1 day SecondsInYear = 86400 * 365 )
const ( // keys for the URL parameters. e.g. /root/:param_name ParamKeyUserID = "user_id" ParamKeyRoomID = "room_id" )
const KeyLoggedInUserID = "SESSION-USER-ID"
KeyLoggedInUserID is the key for the logged-in user id in the echo.Context. It is set when user is logged-in through LoginHandler.
Variables ¶
var DefaultConfig = Config{ HTTP: "localhost:8080", ChatAPIPrefix: "", StaticHandlerPrefix: "", StaticFileDir: "", EnableServeStaticFile: true, ShowRoutes: true, }
DefaultConfig is default configuration for the server.
var DefaultOptions = session.Options{ HttpOnly: true, }
var ( // ErrAPIRequireLoginFirst indicates that unauthenticated error message with htto status code. ErrAPIRequireLoginFirst = NewHTTPError(http.StatusForbidden, "require login first") )
Functions ¶
func CreateServerFromInfra ¶
func CreateServerFromInfra(repos domain.Repositories, qs *chat.Queryers, ps chat.Pubsub, conf *Config) (*Server, DoneFunc)
CreateServerFromInfra creates server with infrastructure dependencies. It returns created server and finalize function. a nil config is OK and use DefaultConfig insteadly.
func ListenAndServe ¶
func ListenAndServe(chatCmd chat.CommandService, chatQuery chat.QueryService, chatHub chat.Hub, login chat.LoginService, conf *Config) error
It starts server process using default server with user config. A nil config is OK and use DefaultConfig insteadly. It blocks until the process occurs any error and return the error.
func LoggedInUserID ¶
get logged in user id which is valid after LoginHandler.Filter. the second returned value is false if logged in user id is not found.
func NewHTTPError ¶
Wrapper function for the echo.HTTPError. Because echo.DefaultHTTPHandler handles only string message in the echo.HTTPError, This converts error types to string.
Types ¶
type Config ¶
type Config struct { // HTTP service address for the server. // The format is `[host]:[port]`, e.g. localhost:8080. HTTP string // Prefix of URI for the chat API. // e.g. given ChatAPIPrefix = `/api` and chat API `/chat/rooms`, // the prefixed chat API is `/api/chat/rooms`. ChatAPIPrefix string // Prefix of URI for the static file server. // // Example: given local html file `/www/index.html`, // StaticHandlerPrefix = "/www" and StaticHandlerPrefix = "/static", // the requesting the server with URI `/static/index.html` responds // the html content of `/www/index.html`. StaticHandlerPrefix string // root directory to serve static files. StaticFileDir string // indicates whether serving static files is enable. // if false, StaticHandlerPrefix and StaticFileDir do not // affect the server. EnableServeStaticFile bool // show all of URI routes at server starts. ShowRoutes bool }
Configuration for server behavior.
type DoneFunc ¶
type DoneFunc func()
DoneFunc is function to be called after all of operations are done.
type LoginHandler ¶
type LoginHandler struct {
// contains filtered or unexported fields
}
LoginHandler handles login requests. it holds logged-in users, so that each request can reference any logged-in user.
func NewLoginHandler ¶
func NewLoginHandler(ls chat.LoginService, secretKeyPairs ...[]byte) *LoginHandler
func (*LoginHandler) Filter ¶
func (lh *LoginHandler) Filter() echo.MiddlewareFunc
Filter is a middleware which filters unauthenticated request.
it sets logged-in user's id for echo.Context using KeyLoggedInUserID when the request is authenticated.
func (*LoginHandler) GetLoginState ¶
func (lh *LoginHandler) GetLoginState(c echo.Context) error
func (*LoginHandler) IsLoggedInRequest ¶
func (lh *LoginHandler) IsLoggedInRequest(c echo.Context) bool
func (*LoginHandler) Middleware ¶
func (lh *LoginHandler) Middleware() echo.MiddlewareFunc
Middleware returns echo.MiddlewareFunc. it should be registered for echo.Server to use this LoginHandler.
func (*LoginHandler) Session ¶
func (lh *LoginHandler) Session(c echo.Context) (*LoginState, bool)
it returns loginState as session state. the second returned value is true when LoginState exists.
type LoginState ¶
type RESTHandler ¶
type RESTHandler struct {
// contains filtered or unexported fields
}
func NewRESTHandler ¶
func NewRESTHandler(chatCmd chat.CommandService, chatQuery chat.QueryService) *RESTHandler
func (*RESTHandler) AddRoomMember ¶
func (rest *RESTHandler) AddRoomMember(e echo.Context) error
func (*RESTHandler) CreateRoom ¶
func (rest *RESTHandler) CreateRoom(e echo.Context) error
func (*RESTHandler) DeleteRoom ¶
func (rest *RESTHandler) DeleteRoom(e echo.Context) error
func (*RESTHandler) GetRoomInfo ¶
func (rest *RESTHandler) GetRoomInfo(e echo.Context) error
func (*RESTHandler) GetRoomMessages ¶
func (rest *RESTHandler) GetRoomMessages(e echo.Context) error
func (*RESTHandler) GetUnreadRoomMessages ¶
func (rest *RESTHandler) GetUnreadRoomMessages(e echo.Context) error
func (*RESTHandler) GetUserInfo ¶
func (rest *RESTHandler) GetUserInfo(e echo.Context) error
func (*RESTHandler) PostRoomMessage ¶
func (rest *RESTHandler) PostRoomMessage(e echo.Context) error
func (*RESTHandler) ReadRoomMessages ¶
func (rest *RESTHandler) ReadRoomMessages(e echo.Context) error
func (*RESTHandler) RemoveRoomMember ¶
func (rest *RESTHandler) RemoveRoomMember(e echo.Context) error
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
it represents server which can accepts chat room and its clients.
func NewServer ¶
func NewServer(chatCmd chat.CommandService, chatQuery chat.QueryService, chatHub chat.Hub, login chat.LoginService, conf *Config) *Server
it returns new constructed server with config. nil config is ok and use DefaultConfig insteadly.
func (*Server) ListenAndServe ¶
it starts server process. it blocks until process occurs any error and return the error.