You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.3 KiB
55 lines
1.3 KiB
2 years ago
|
package msggateway
|
||
2 years ago
|
|
||
2 years ago
|
import (
|
||
2 years ago
|
"OpenIM/pkg/utils"
|
||
2 years ago
|
"net/http"
|
||
|
"strconv"
|
||
|
)
|
||
2 years ago
|
|
||
|
type UserConnContext struct {
|
||
|
RespWriter http.ResponseWriter
|
||
|
Req *http.Request
|
||
|
Path string
|
||
|
Method string
|
||
|
RemoteAddr string
|
||
|
}
|
||
|
|
||
|
func newContext(respWriter http.ResponseWriter, req *http.Request) *UserConnContext {
|
||
|
return &UserConnContext{
|
||
|
RespWriter: respWriter,
|
||
|
Req: req,
|
||
|
Path: req.URL.Path,
|
||
|
Method: req.Method,
|
||
|
RemoteAddr: req.RemoteAddr,
|
||
|
}
|
||
|
}
|
||
2 years ago
|
func (c *UserConnContext) Query(key string) (string, bool) {
|
||
|
var value string
|
||
|
if value = c.Req.URL.Query().Get(key); value == "" {
|
||
|
return value, false
|
||
|
}
|
||
|
return value, true
|
||
|
}
|
||
|
func (c *UserConnContext) GetHeader(key string) (string, bool) {
|
||
|
var value string
|
||
|
if value = c.Req.Header.Get(key); value == "" {
|
||
|
return value, false
|
||
|
}
|
||
|
return value, true
|
||
|
}
|
||
|
func (c *UserConnContext) SetHeader(key, value string) {
|
||
|
c.RespWriter.Header().Set(key, value)
|
||
|
}
|
||
|
func (c *UserConnContext) ErrReturn(error string, code int) {
|
||
|
http.Error(c.RespWriter, error, code)
|
||
|
}
|
||
|
func (c *UserConnContext) GetConnID() string {
|
||
|
return c.RemoteAddr + "_" + strconv.Itoa(int(utils.GetCurrentTimestampByMill()))
|
||
|
}
|
||
|
func (c *UserConnContext) GetUserID() string {
|
||
2 years ago
|
return c.Req.URL.Query().Get(WsUserID)
|
||
2 years ago
|
}
|
||
2 years ago
|
func (c *UserConnContext) GetPlatformID() string {
|
||
2 years ago
|
return c.Req.URL.Query().Get(PlatformID)
|
||
2 years ago
|
}
|