Documentation ¶
Overview ¶
services package is au json-rpc service for session management. client can perform three operations on session: - Open to initiate a session with valid credentials - Renew to extends the validty period from a valid session - Close to invalidate a session
Index ¶
- Constants
- Variables
- func AppendRequestLog(log *logrus.Entry, r *http.Request) *logrus.Entry
- func ContextValues(ctx context.Context) (db bank.Database, session *sessions.Session, err error)
- func CreateCorsOptions(corsAllowedOrigins []string) *cors.Cors
- func GetRequestLog(ctx context.Context, r *http.Request) *logrus.Entry
- func GetServiceRequestLog(log *logrus.Entry, r *http.Request, service, operation string) *logrus.Entry
- func NewSessionHandler(ctx context.Context) http.Handler
- func NewUserHandler(ctx context.Context) http.Handler
- func OpenSessionAllowed(ctx context.Context, userID uint64) bool
- func RegisterServices(ctx context.Context, mux *http.ServeMux, corsAllowedOrigins []string)
- func RequesterIP(r *http.Request) string
- type CookieCodec
- type CookieCodecRequest
- type SessionArgs
- type SessionOpenRequest
- type SessionReply
- type SessionService
- type StatsArgs
- type StatsReply
- type StatsService
- type UserInfoRequest
- type UserInfoResponse
- type UserService
Constants ¶
const (
SessionDuration = 3 * time.Minute
)
const Version string = "0.1"
Version
Variables ¶
var ( ErrInvalidCrendential = errors.New("InvalidCredentials") ErrMissingCookie = errors.New("MissingCookie") ErrInvalidCookie = errors.New("ErrInvalidCookie") ErrSessionCreationFailed = errors.New("SessionCreationFailed") ErrTooManyOpenSession = errors.New("TooManyOpenSession") ErrSessionExpired = sessions.ErrSessionExpired ErrSessionClose = errors.New("SessionCloseFailed") )
var (
ErrServiceInternalError = errors.New("Service Internal Error")
)
var (
StatsMiddleware = stats.New()
)
Functions ¶
func ContextValues ¶
func CreateCorsOptions ¶
func GetServiceRequestLog ¶
func RegisterServices ¶
func RequesterIP ¶
Types ¶
type CookieCodec ¶
type CookieCodec struct {
// contains filtered or unexported fields
}
func NewCookieCodec ¶
func NewCookieCodec(ctx context.Context) *CookieCodec
func (*CookieCodec) NewRequest ¶
func (p *CookieCodec) NewRequest(r *http.Request) rpc.CodecRequest
type CookieCodecRequest ¶
type CookieCodecRequest struct {
// contains filtered or unexported fields
}
func (*CookieCodecRequest) Method ¶
func (p *CookieCodecRequest) Method() (string, error)
func (*CookieCodecRequest) ReadRequest ¶
func (p *CookieCodecRequest) ReadRequest(args interface{}) error
func (*CookieCodecRequest) WriteError ¶
func (p *CookieCodecRequest) WriteError(w http.ResponseWriter, status int, err error)
func (*CookieCodecRequest) WriteResponse ¶
func (p *CookieCodecRequest) WriteResponse(w http.ResponseWriter, args interface{})
type SessionArgs ¶
type SessionArgs struct {
SessionID string `json:"-"` // SessionID is transmit to client via cookie
}
SessionArgs holds SessionID for operation requests and repls
type SessionOpenRequest ¶
type SessionOpenRequest struct { Login string `json:"login"` Password string `json:"password"` OTP string `json:"otp,omitempty"` }
SessionOpenRequest holds args for open requests
type SessionReply ¶
type SessionReply struct { SessionArgs Status string `json:"status"` ValidUntil int64 `json:"valid_until"` }
SessionReply holds session informations for operation replies
type SessionService ¶
type SessionService int
SessionService receiver
func (*SessionService) Close ¶
func (p *SessionService) Close(r *http.Request, request *SessionArgs, reply *SessionReply) error
Close operation close the session and set status to closed
func (*SessionService) Open ¶
func (p *SessionService) Open(r *http.Request, request *SessionOpenRequest, reply *SessionReply) error
Open operation perform check regarding credentials and return a sessionID session has a status [open, close] and a validation period
func (*SessionService) Renew ¶
func (p *SessionService) Renew(r *http.Request, request *SessionArgs, reply *SessionReply) error
Open operation perform check the session validity and extends the validation period
type StatsReply ¶
type StatsService ¶
type StatsService int
func (*StatsService) Status ¶
func (t *StatsService) Status(r *http.Request, args *StatsArgs, result *StatsReply) error
type UserInfoRequest ¶
type UserInfoRequest struct {
SessionArgs
}
UserInfoRequest holds args for start requests
type UserInfoResponse ¶
type UserInfoResponse struct {
Email string `json:"email"`
}
UserInfoResponse holds args for start requests
type UserService ¶
type UserService int
KYCService receiver
func (*UserService) Info ¶
func (p *UserService) Info(r *http.Request, request *UserInfoRequest, reply *UserInfoResponse) error
Info operation return user's email