123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package hhc_telws
- import (
- "github.com/pascaldekloe/jwt"
- "io"
- "net"
- )
- type TelwsSessionContext struct {
- tscc *TelwsSessionContextContainer
- }
- type TelwsSessionContextContainer struct {
- tsc *TelwsSessionContext
- jwtClaims *jwt.Claims
- conn net.Conn
- }
- func WrapNewTelwsSessionContext() *TelwsSessionContextContainer {
- tscc := &TelwsSessionContextContainer{}
- tsc := &TelwsSessionContext{
- tscc: tscc,
- }
- tscc.tsc = tsc
- return tscc
- }
- func (tscc *TelwsSessionContextContainer) GetUserContext() *TelwsSessionContext {
- return tscc.tsc
- }
- func (tscc *TelwsSessionContextContainer) SetJwtClaims(clm *jwt.Claims) {
- tscc.jwtClaims = clm
- }
- func (tscc *TelwsSessionContextContainer) SetConn(conn net.Conn) {
- tscc.conn = conn
- }
- func (tsc *TelwsSessionContext) GetAuthInfo() map[string]interface{} {
- return tsc.tscc.jwtClaims.Set
- }
- func (tsc *TelwsSessionContext) GetUsername() string {
- t := tsc.tscc.jwtClaims.Set
- if t == nil {
- return ""
- }
- un, ok := t["username"]
- if ok {
- switch un.(type) {
- case string:
- return un.(string)
- default:
- return ""
- }
- }
- return ""
- }
- func (tsc *TelwsSessionContext) GetWriter() io.Writer {
- return tsc.tscc.conn
- }
- func (tsc *TelwsSessionContext) GetReader() io.Reader {
- return tsc.tscc.conn
- }
- func (tsc *TelwsSessionContext) GetReadWriter() io.ReadWriter {
- return tsc.tscc.conn
- }
- func (tsc *TelwsSessionContext) GetConn() net.Conn {
- return tsc.tscc.conn
- }
|