replacing interface{} with any

This commit is contained in:
or-else
2023-03-21 11:36:49 -07:00
parent 68471c8b82
commit 2bb1aef472
17 changed files with 181 additions and 181 deletions
+4 -4
View File
@@ -83,9 +83,9 @@ type videoCall struct {
// Call message seq ID.
seq int
// Call message content.
content interface{}
content any
// Call message content mime type.
contentMime interface{}
contentMime any
// Time when the call was accepted.
acceptedAt time.Time
}
@@ -173,9 +173,9 @@ func initVideoCalls(jsconfig json.RawMessage) error {
// Add webRTC-related headers to message Head. The original Head may already contain some entries,
// like 'sender', preserve them.
func (call *videoCall) messageHead(head map[string]interface{}, newState string, duration int) map[string]interface{} {
func (call *videoCall) messageHead(head map[string]any, newState string, duration int) map[string]any {
if head == nil {
head = map[string]interface{}{}
head = map[string]any{}
}
head["replace"] = ":" + strconv.Itoa(call.seq)
+5 -5
View File
@@ -302,7 +302,7 @@ func (n *ClusterNode) reconnect() {
}
}
func (n *ClusterNode) call(proc string, req, resp interface{}) error {
func (n *ClusterNode) call(proc string, req, resp any) error {
if !n.connected {
return errors.New("cluster: node '" + n.name + "' not connected")
}
@@ -338,7 +338,7 @@ func (n *ClusterNode) handleRpcResponse(call *rpc.Call) {
}
}
func (n *ClusterNode) callAsync(proc string, req, resp interface{}, done chan *rpc.Call) *rpc.Call {
func (n *ClusterNode) callAsync(proc string, req, resp any, done chan *rpc.Call) *rpc.Call {
if done != nil && cap(done) == 0 {
logs.Err.Panic("cluster: RPC done channel is unbuffered")
}
@@ -962,8 +962,8 @@ func clusterInit(configString json.RawMessage, self *string) int {
return 1
}
gob.Register([]interface{}{})
gob.Register(map[string]interface{}{})
gob.Register([]any{})
gob.Register(map[string]any{})
gob.Register(map[string]int{})
gob.Register(map[string]string{})
gob.Register(MsgAccessMode{})
@@ -1111,7 +1111,7 @@ func (c *Cluster) rehash(nodes []string) []string {
// TODO: consider resubscribing to topics instead of forcing sessions to resubscribe.
func (c *Cluster) invalidateProxySubs(forNode string) {
sessions := make(map[*Session][]string)
globals.hub.topics.Range(func(_, v interface{}) bool {
globals.hub.topics.Range(func(_, v any) bool {
topic := v.(*Topic)
if !topic.isProxy {
// Topic isn't a proxy.
+32 -32
View File
@@ -60,9 +60,9 @@ type MsgSetSub struct {
// MsgSetDesc is a C2S in set.what == "desc", acc, sub message.
type MsgSetDesc struct {
DefaultAcs *MsgDefaultAcsMode `json:"defacs,omitempty"` // default access mode
Public interface{} `json:"public,omitempty"` // description of the user or topic
Trusted interface{} `json:"trusted,omitempty"` // trusted (system-provided) user or topic data
Private interface{} `json:"private,omitempty"` // per-subscription private data
Public any `json:"public,omitempty"` // description of the user or topic
Trusted any `json:"trusted,omitempty"` // trusted (system-provided) user or topic data
Private any `json:"private,omitempty"` // per-subscription private data
}
// MsgCredClient is an account credential such as email or phone number.
@@ -74,7 +74,7 @@ type MsgCredClient struct {
// Verification response
Response string `json:"resp,omitempty"`
// Request parameters, such as preferences. Passed to valiator without interpretation.
Params map[string]interface{} `json:"params,omitempty"`
Params map[string]any `json:"params,omitempty"`
}
// MsgSetQuery is an update to topic or user metadata: description, subscriptions, tags, credentials.
@@ -253,11 +253,11 @@ type MsgClientLeave struct {
// MsgClientPub is client's request to publish data to topic subscribers {pub}.
type MsgClientPub struct {
Id string `json:"id,omitempty"`
Topic string `json:"topic"`
NoEcho bool `json:"noecho,omitempty"`
Head map[string]interface{} `json:"head,omitempty"`
Content interface{} `json:"content"`
Id string `json:"id,omitempty"`
Topic string `json:"topic"`
NoEcho bool `json:"noecho,omitempty"`
Head map[string]any `json:"head,omitempty"`
Content any `json:"content"`
}
// MsgClientGet is a query of topic state {get}.
@@ -436,11 +436,11 @@ type MsgTopicDesc struct {
ReadSeqId int `json:"read,omitempty"`
RecvSeqId int `json:"recv,omitempty"`
// Id of the last delete operation as seen by the requesting user
DelId int `json:"clear,omitempty"`
Public interface{} `json:"public,omitempty"`
Trusted interface{} `json:"trusted,omitempty"`
DelId int `json:"clear,omitempty"`
Public any `json:"public,omitempty"`
Trusted any `json:"trusted,omitempty"`
// Per-subscription private data
Private interface{} `json:"private,omitempty"`
Private any `json:"private,omitempty"`
}
func (src *MsgTopicDesc) describe() string {
@@ -496,11 +496,11 @@ type MsgTopicSub struct {
// ID of the message reported by the given user as received
RecvSeqId int `json:"recv,omitempty"`
// Topic's public data
Public interface{} `json:"public,omitempty"`
Public any `json:"public,omitempty"`
// Topic's trusted public data
Trusted interface{} `json:"trusted,omitempty"`
Trusted any `json:"trusted,omitempty"`
// User's own private data per topic
Private interface{} `json:"private,omitempty"`
Private any `json:"private,omitempty"`
// Response to non-'me' topic
@@ -563,9 +563,9 @@ type MsgDelValues struct {
// MsgServerCtrl is a server control message {ctrl}.
type MsgServerCtrl struct {
Id string `json:"id,omitempty"`
Topic string `json:"topic,omitempty"`
Params interface{} `json:"params,omitempty"`
Id string `json:"id,omitempty"`
Topic string `json:"topic,omitempty"`
Params any `json:"params,omitempty"`
Code int `json:"code"`
Text string `json:"text,omitempty"`
@@ -589,12 +589,12 @@ func (src *MsgServerCtrl) describe() string {
type MsgServerData struct {
Topic string `json:"topic"`
// ID of the user who originated the message as {pub}, could be empty if sent by the system
From string `json:"from,omitempty"`
Timestamp time.Time `json:"ts"`
DeletedAt *time.Time `json:"deleted,omitempty"`
SeqId int `json:"seq"`
Head map[string]interface{} `json:"head,omitempty"`
Content interface{} `json:"content"`
From string `json:"from,omitempty"`
Timestamp time.Time `json:"ts"`
DeletedAt *time.Time `json:"deleted,omitempty"`
SeqId int `json:"seq"`
Head map[string]any `json:"head,omitempty"`
Content any `json:"content"`
}
// Deep-shallow copy.
@@ -894,13 +894,13 @@ func NoErrReply(msg *ClientComMessage, ts time.Time) *ServerComMessage {
}
// NoErrParams indicates successful completion with additional parameters (200).
func NoErrParams(id, topic string, ts time.Time, params interface{}) *ServerComMessage {
func NoErrParams(id, topic string, ts time.Time, params any) *ServerComMessage {
return NoErrParamsExplicitTs(id, topic, ts, ts, params)
}
// NoErrParamsExplicitTs indicates successful completion with additional parameters
// and explicit server and incoming request timestamps (200).
func NoErrParamsExplicitTs(id, topic string, serverTs, incomingReqTs time.Time, params interface{}) *ServerComMessage {
func NoErrParamsExplicitTs(id, topic string, serverTs, incomingReqTs time.Time, params any) *ServerComMessage {
return &ServerComMessage{
Ctrl: &MsgServerCtrl{
Id: id,
@@ -917,7 +917,7 @@ func NoErrParamsExplicitTs(id, topic string, serverTs, incomingReqTs time.Time,
// NoErrParamsReply indicates successful completion with additional parameters
// and explicit server and incoming request timestamps (200).
func NoErrParamsReply(msg *ClientComMessage, ts time.Time, params interface{}) *ServerComMessage {
func NoErrParamsReply(msg *ClientComMessage, ts time.Time, params any) *ServerComMessage {
return NoErrParamsExplicitTs(msg.Id, msg.Original, ts, msg.Timestamp, params)
}
@@ -957,7 +957,7 @@ func NoErrAcceptedExplicitTs(id, topic string, serverTs, incomingReqTs time.Time
}
// NoContentParams indicates request was processed but resulted in no content (204).
func NoContentParams(id, topic string, serverTs, incomingReqTs time.Time, params interface{}) *ServerComMessage {
func NoContentParams(id, topic string, serverTs, incomingReqTs time.Time, params any) *ServerComMessage {
return &ServerComMessage{
Ctrl: &MsgServerCtrl{
Id: id,
@@ -974,7 +974,7 @@ func NoContentParams(id, topic string, serverTs, incomingReqTs time.Time, params
// NoContentParamsReply indicates request was processed but resulted in no content
// in response to a client request (204).
func NoContentParamsReply(msg *ClientComMessage, ts time.Time, params interface{}) *ServerComMessage {
func NoContentParamsReply(msg *ClientComMessage, ts time.Time, params any) *ServerComMessage {
return NoContentParams(msg.Id, msg.Original, ts, msg.Timestamp, params)
}
@@ -1003,7 +1003,7 @@ func NoErrShutdown(ts time.Time) *ServerComMessage {
}
// NoErrDeliveredParams means requested content has been delivered (208).
func NoErrDeliveredParams(id, topic string, ts time.Time, params interface{}) *ServerComMessage {
func NoErrDeliveredParams(id, topic string, ts time.Time, params any) *ServerComMessage {
return &ServerComMessage{
Ctrl: &MsgServerCtrl{
Id: id,
@@ -1046,7 +1046,7 @@ func InfoChallenge(id string, ts time.Time, challenge []byte) *ServerComMessage
Id: id,
Code: http.StatusMultipleChoices, // 300
Text: "challenge",
Params: map[string]interface{}{"challenge": challenge},
Params: map[string]any{"challenge": challenge},
Timestamp: ts,
},
Id: id,
+2 -2
View File
@@ -73,7 +73,7 @@ func (*grpcNodeServer) MessageLoop(stream pbx.Node_MessageLoopServer) error {
return nil
}
func (sess *Session) sendMessageGrpc(msg interface{}) bool {
func (sess *Session) sendMessageGrpc(msg any) bool {
if len(sess.send) > sendQueueLimit {
logs.Err.Println("grpc: outbound queue limit exceeded", sess.sid)
return false
@@ -136,7 +136,7 @@ func (sess *Session) writeGrpcLoop() {
}
}
func grpcWrite(sess *Session, msg interface{}) error {
func grpcWrite(sess *Session, msg any) error {
if out := sess.grpcnode; out != nil {
// Will panic if msg is not of *pbx.ServerMsg type. This is an intentional panic.
return out.Send(msg.(*pbx.ServerMsg))
+2 -2
View File
@@ -19,7 +19,7 @@ import (
"github.com/tinode/chat/server/logs"
)
func (sess *Session) sendMessageLp(wrt http.ResponseWriter, msg interface{}) bool {
func (sess *Session) sendMessageLp(wrt http.ResponseWriter, msg any) bool {
if len(sess.send) > sendQueueLimit {
logs.Err.Println("longPoll: outbound queue limit exceeded", sess.sid)
return false
@@ -88,7 +88,7 @@ func (sess *Session) writeOnce(wrt http.ResponseWriter, req *http.Request) {
}
}
func lpWrite(wrt http.ResponseWriter, msg interface{}) error {
func lpWrite(wrt http.ResponseWriter, msg any) error {
// This will panic if msg is not []byte. This is intentional.
wrt.Write(msg.([]byte))
return nil
+2 -2
View File
@@ -63,7 +63,7 @@ func (sess *Session) readLoop() {
}
}
func (sess *Session) sendMessage(msg interface{}) bool {
func (sess *Session) sendMessage(msg any) bool {
if len(sess.send) > sendQueueLimit {
logs.Err.Println("ws: outbound queue limit exceeded", sess.sid)
return false
@@ -144,7 +144,7 @@ func (sess *Session) writeLoop() {
}
// Writes a message with the given message type (mt) and payload.
func wsWrite(ws *websocket.Conn, mt int, msg interface{}) error {
func wsWrite(ws *websocket.Conn, mt int, msg any) error {
var bits []byte
if msg != nil {
bits = msg.([]byte)
+1 -1
View File
@@ -452,7 +452,7 @@ func serveStatus(wrt http.ResponseWriter, req *http.Request) {
return true
})
// Topics.
globals.hub.topics.Range(func(_, t interface{}) bool {
globals.hub.topics.Range(func(_, t any) bool {
topic := t.(*Topic)
psd := make([]string, 0, len(topic.sessions))
for s := range topic.sessions {
+10 -10
View File
@@ -298,7 +298,7 @@ func (h *Hub) run() {
// Cluster rehashing. Some previously local topics became remote,
// and the other way round.
// Such topics must be shut down at this node.
h.topics.Range(func(_, t interface{}) bool {
h.topics.Range(func(_, t any) bool {
topic := t.(*Topic)
// Handle two cases:
// 1. Master topic has moved out to another node.
@@ -323,7 +323,7 @@ func (h *Hub) run() {
// start cleanup process
topicsdone := make(chan bool)
topicCount := 0
h.topics.Range(func(_, topic interface{}) bool {
h.topics.Range(func(_, topic any) bool {
topic.(*Topic).exit <- &shutDown{done: topicsdone}
topicCount++
return true
@@ -350,7 +350,7 @@ func (h *Hub) run() {
// * group topics where the given user is the owner.
// 'me' and fnd' are ignored here because they are direcly tied to the user object.
func (h *Hub) topicsStateForUser(uid types.Uid, suspended bool) {
h.topics.Range(func(name interface{}, t interface{}) bool {
h.topics.Range(func(name any, t any) bool {
topic := t.(*Topic)
if topic.cat == types.TopicCatMe || topic.cat == types.TopicCatFnd {
return true
@@ -573,7 +573,7 @@ func (h *Hub) stopTopicsForUser(uid types.Uid, reason int, alldone chan<- bool)
}
count := 0
h.topics.Range(func(name interface{}, t interface{}) bool {
h.topics.Range(func(name any, t any) bool {
topic := t.(*Topic)
if _, isMember := topic.perUser[uid]; (topic.cat != types.TopicCatGrp && isMember) ||
topic.owner == uid {
@@ -806,13 +806,13 @@ func replyOfflineTopicSetSub(sess *Session, msg *ClientComMessage) {
return
}
update := make(map[string]interface{})
update := make(map[string]any)
if msg.Set.Desc != nil && msg.Set.Desc.Private != nil {
private, ok := msg.Set.Desc.Private.(map[string]interface{})
private, ok := msg.Set.Desc.Private.(map[string]any)
if !ok {
update = map[string]interface{}{"Private": msg.Set.Desc.Private}
update = map[string]any{"Private": msg.Set.Desc.Private}
} else if private, changed := mergeInterfaces(sub.Private, private); changed {
update = map[string]interface{}{"Private": private}
update = map[string]any{"Private": private}
}
}
@@ -849,9 +849,9 @@ func replyOfflineTopicSetSub(sess *Session, msg *ClientComMessage) {
logs.Warn.Println("replyOfflineTopicSetSub update:", err)
sess.queueOut(decodeStoreErrorExplicitTs(err, msg.Id, msg.Original, now, msg.Timestamp, nil))
} else {
var params interface{}
var params any
if update["ModeWant"] != nil {
params = map[string]interface{}{
params = map[string]any{
"acs": MsgAccessMode{
Given: sub.ModeGiven.String(),
Want: sub.ModeWant.String(),
+7 -7
View File
@@ -14,7 +14,7 @@ import (
func pbServCtrlSerialize(ctrl *MsgServerCtrl) *pbx.ServerMsg_Ctrl {
var params map[string][]byte
if ctrl.Params != nil {
if in, ok := ctrl.Params.(map[string]interface{}); ok {
if in, ok := ctrl.Params.(map[string]any); ok {
params = interfaceMapToByteMap(in)
}
}
@@ -494,7 +494,7 @@ func pbCliDeserialize(pkt *pbx.ClientMsg) *ClientComMessage {
return &msg
}
func interfaceMapToByteMap(in map[string]interface{}) map[string][]byte {
func interfaceMapToByteMap(in map[string]any) map[string][]byte {
out := make(map[string][]byte, len(in))
for key, val := range in {
if val != nil {
@@ -504,8 +504,8 @@ func interfaceMapToByteMap(in map[string]interface{}) map[string][]byte {
return out
}
func byteMapToInterfaceMap(in map[string][]byte) map[string]interface{} {
out := make(map[string]interface{}, len(in))
func byteMapToInterfaceMap(in map[string][]byte) map[string]any {
out := make(map[string]any, len(in))
for key, raw := range in {
if val := bytesToInterface(raw); val != nil {
out[key] = val
@@ -514,7 +514,7 @@ func byteMapToInterfaceMap(in map[string][]byte) map[string]interface{} {
return out
}
func interfaceToBytes(in interface{}) []byte {
func interfaceToBytes(in any) []byte {
if in != nil {
out, _ := json.Marshal(in)
return out
@@ -522,8 +522,8 @@ func interfaceToBytes(in interface{}) []byte {
return nil
}
func bytesToInterface(in []byte) interface{} {
var out interface{}
func bytesToInterface(in []byte) any {
var out any
if len(in) > 0 {
err := json.Unmarshal(in, &out)
if err != nil {
+11 -11
View File
@@ -134,11 +134,11 @@ type Session struct {
// Outbound mesages, buffered.
// The content must be serialized in format suitable for the session.
send chan interface{}
send chan any
// Channel for shutting down the session, buffer 1.
// Content in the same format as for 'send'
stop chan interface{}
stop chan any
// detach - channel for detaching session from topic, buffered.
// Content is topic name to detach from.
@@ -391,7 +391,7 @@ func (s *Session) detachSession(fromTopic string) {
}
}
func (s *Session) stopSession(data interface{}) {
func (s *Session) stopSession(data any) {
s.stop <- data
s.maybeScheduleClusterWriteLoop()
}
@@ -690,7 +690,7 @@ func (s *Session) publish(msg *ClientComMessage) {
// Add "sender" header if the message is sent on behalf of another user.
if msg.AsUser != s.uid.UserId() {
if msg.Pub.Head == nil {
msg.Pub.Head = make(map[string]interface{})
msg.Pub.Head = make(map[string]any)
}
msg.Pub.Head["sender"] = s.uid.UserId()
} else if msg.Pub.Head != nil {
@@ -728,7 +728,7 @@ func (s *Session) publish(msg *ClientComMessage) {
// Client metadata
func (s *Session) hello(msg *ClientComMessage) {
var params map[string]interface{}
var params map[string]any
var deviceIDUpdate bool
if s.ver == 0 {
@@ -746,7 +746,7 @@ func (s *Session) hello(msg *ClientComMessage) {
return
}
params = map[string]interface{}{
params = map[string]any{
"ver": currentVersion,
"build": store.Store.GetAdapterName() + ":" + buildstamp,
"maxMessageSize": globals.maxMessageSize,
@@ -871,7 +871,7 @@ func (s *Session) acc(msg *ClientComMessage) {
rec, _, err = authHdl.Authenticate(msg.Acc.TmpSecret, s.remoteAddr)
if err != nil {
s.queueOut(decodeStoreError(err, msg.Acc.Id, msg.Timestamp,
map[string]interface{}{"what": "auth"}))
map[string]any{"what": "auth"}))
logs.Warn.Println("s.acc: invalid temp auth", err, s.sid)
return
}
@@ -1012,11 +1012,11 @@ func (s *Session) authSecretReset(params []byte) error {
// onLogin performs steps after successful authentication.
func (s *Session) onLogin(msgID string, timestamp time.Time, rec *auth.Rec, missing []string) *ServerComMessage {
var reply *ServerComMessage
var params map[string]interface{}
var params map[string]any
features := rec.Features
params = map[string]interface{}{
params = map[string]any{
"user": rec.Uid.UserId(),
"authlvl": rec.AuthLevel.String(),
}
@@ -1316,7 +1316,7 @@ func (s *Session) expandTopicName(msg *ClientComMessage) (string, *ServerComMess
return routeTo, nil
}
func (s *Session) serializeAndUpdateStats(msg *ServerComMessage) interface{} {
func (s *Session) serializeAndUpdateStats(msg *ServerComMessage) any {
dataSize, data := s.serialize(msg)
if dataSize >= 0 {
statsAddHistSample("OutgoingMessageSize", float64(dataSize))
@@ -1324,7 +1324,7 @@ func (s *Session) serializeAndUpdateStats(msg *ServerComMessage) interface{} {
return data
}
func (s *Session) serialize(msg *ServerComMessage) (int, interface{}) {
func (s *Session) serialize(msg *ServerComMessage) (int, any) {
if s.proto == GRPC {
msg := pbServSerialize(msg)
// TODO: calculate and return the size of `msg`.
+32 -32
View File
@@ -16,7 +16,7 @@ import (
func TestDispatchHello(t *testing.T) {
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: types.Uid(1),
authLvl: auth.LevelAuth,
}
@@ -87,7 +87,7 @@ func verifyResponseCodes(r *responses, codes []int, t *testing.T) {
func TestDispatchInvalidVersion(t *testing.T) {
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: types.Uid(1),
authLvl: auth.LevelAuth,
}
@@ -110,7 +110,7 @@ func TestDispatchInvalidVersion(t *testing.T) {
func TestDispatchUnsupportedVersion(t *testing.T) {
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: types.Uid(1),
authLvl: auth.LevelAuth,
}
@@ -159,7 +159,7 @@ func TestDispatchLogin(t *testing.T) {
aa.EXPECT().GenSecret(authRec).Return([]byte(token), expires, nil)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
authLvl: auth.LevelAuth,
ver: 16,
}
@@ -197,7 +197,7 @@ func TestDispatchLogin(t *testing.T) {
if resp.Ctrl.Params == nil {
t.Error("Response is expected to contain params dict.")
}
p := resp.Ctrl.Params.(map[string]interface{})
p := resp.Ctrl.Params.(map[string]any)
if authToken := string(p["token"].([]byte)); authToken != token {
t.Errorf("Auth token: expected '%s', found '%s'.", token, authToken)
}
@@ -212,7 +212,7 @@ func TestDispatchLogin(t *testing.T) {
func TestDispatchSubscribe(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -267,7 +267,7 @@ func TestDispatchSubscribe(t *testing.T) {
func TestDispatchAlreadySubscribed(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -301,7 +301,7 @@ func TestDispatchAlreadySubscribed(t *testing.T) {
func TestDispatchSubscribeJoinChannelFull(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -342,7 +342,7 @@ func TestDispatchSubscribeJoinChannelFull(t *testing.T) {
func TestDispatchLeave(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -396,7 +396,7 @@ func TestDispatchLeave(t *testing.T) {
func TestDispatchLeaveUnsubMe(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -429,7 +429,7 @@ func TestDispatchLeaveUnsubMe(t *testing.T) {
func TestDispatchLeaveUnknownTopic(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -461,7 +461,7 @@ func TestDispatchLeaveUnknownTopic(t *testing.T) {
func TestDispatchLeaveUnsubFromUnknownTopic(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -494,7 +494,7 @@ func TestDispatchLeaveUnsubFromUnknownTopic(t *testing.T) {
func TestDispatchPublish(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -550,7 +550,7 @@ func TestDispatchPublish(t *testing.T) {
func TestDispatchPublishBroadcastChannelFull(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -591,7 +591,7 @@ func TestDispatchPublishBroadcastChannelFull(t *testing.T) {
func TestDispatchPublishMissingSubcription(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -626,7 +626,7 @@ func TestDispatchPublishMissingSubcription(t *testing.T) {
func TestDispatchGet(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -677,7 +677,7 @@ func TestDispatchGet(t *testing.T) {
func TestDispatchGetMalformedWhat(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -710,7 +710,7 @@ func TestDispatchGetMalformedWhat(t *testing.T) {
func TestDispatchGetMetaChannelFull(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -751,7 +751,7 @@ func TestDispatchGetMetaChannelFull(t *testing.T) {
func TestDispatchSet(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -809,7 +809,7 @@ func TestDispatchSet(t *testing.T) {
func TestDispatchSetMalformedWhat(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -841,7 +841,7 @@ func TestDispatchSetMalformedWhat(t *testing.T) {
func TestDispatchSetMetaChannelFull(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -886,7 +886,7 @@ func TestDispatchSetMetaChannelFull(t *testing.T) {
func TestDispatchDelMsg(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -937,7 +937,7 @@ func TestDispatchDelMsg(t *testing.T) {
func TestDispatchDelMalformedWhat(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -968,7 +968,7 @@ func TestDispatchDelMalformedWhat(t *testing.T) {
func TestDispatchDelMetaChanFull(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -1009,7 +1009,7 @@ func TestDispatchDelMetaChanFull(t *testing.T) {
func TestDispatchDelUnsubscribedSession(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -1043,7 +1043,7 @@ func TestDispatchDelUnsubscribedSession(t *testing.T) {
func TestDispatchNote(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -1101,7 +1101,7 @@ func TestDispatchNote(t *testing.T) {
func TestDispatchNoteBroadcastChanFull(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -1140,7 +1140,7 @@ func TestDispatchNoteBroadcastChanFull(t *testing.T) {
func TestDispatchNoteOnNonSubscribedTopic(t *testing.T) {
uid := types.Uid(1)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
uid: uid,
authLvl: auth.LevelAuth,
inflightReqs: &sync.WaitGroup{},
@@ -1197,7 +1197,7 @@ func TestDispatchAccNew(t *testing.T) {
// This login is available.
aa.EXPECT().IsUnique([]byte(secret), remoteAddr).Return(true, nil)
uu.EXPECT().Create(gomock.Any(), gomock.Any()).DoAndReturn(
func(user *types.User, private interface{}) (*types.User, error) {
func(user *types.User, private any) (*types.User, error) {
user.SetUid(uid)
return user, nil
})
@@ -1210,7 +1210,7 @@ func TestDispatchAccNew(t *testing.T) {
uu.EXPECT().UpdateTags(uid, tags, nil, nil).Return(tags, nil)
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
authLvl: auth.LevelAuth,
ver: 16,
remoteAddr: remoteAddr,
@@ -1253,7 +1253,7 @@ func TestDispatchAccNew(t *testing.T) {
if resp.Ctrl.Params == nil {
t.Error("Response is expected to contain params dict.")
}
p := resp.Ctrl.Params.(map[string]interface{})
p := resp.Ctrl.Params.(map[string]any)
if respUid := string(p["user"].(string)); respUid != uid.UserId() {
t.Errorf("Response uid: expected '%s', found '%s'.", uid.UserId(), respUid)
}
@@ -1271,7 +1271,7 @@ func TestDispatchAccNew(t *testing.T) {
func TestDispatchNoMessage(t *testing.T) {
remoteAddr := "192.168.0.1"
s := &Session{
send: make(chan interface{}, 10),
send: make(chan any, 10),
authLvl: auth.LevelAuth,
ver: 16,
remoteAddr: remoteAddr,
+4 -4
View File
@@ -36,7 +36,7 @@ type SessionStore struct {
}
// NewSession creates a new session and saves it to the session store.
func (ss *SessionStore) NewSession(conn interface{}, sid string) (*Session, int) {
func (ss *SessionStore) NewSession(conn any, sid string) (*Session, int) {
var s Session
if sid == "" {
@@ -69,9 +69,9 @@ func (ss *SessionStore) NewSession(conn interface{}, sid string) (*Session, int)
}
s.subs = make(map[string]*Subscription)
s.send = make(chan interface{}, sendQueueLimit+32) // buffered
s.stop = make(chan interface{}, 1) // Buffered by 1 just to make it non-blocking
s.detach = make(chan string, 64) // buffered
s.send = make(chan any, sendQueueLimit+32) // buffered
s.stop = make(chan any, 1) // Buffered by 1 just to make it non-blocking
s.detach = make(chan string, 64) // buffered
s.bkgTimer = time.NewTimer(time.Hour)
s.bkgTimer.Stop()
+3 -3
View File
@@ -48,7 +48,7 @@ type varUpdate struct {
// Name of the variable to update
varname string
// Value to publish (int, float, etc.)
value interface{}
value any
// Treat the count as an increment as opposite to the final value.
inc bool
}
@@ -63,10 +63,10 @@ func statsInit(mux *http.ServeMux, path string) {
globals.statsUpdate = make(chan *varUpdate, 1024)
start := time.Now()
expvar.Publish("Uptime", expvar.Func(func() interface{} {
expvar.Publish("Uptime", expvar.Func(func() any {
return time.Since(start).Seconds()
}))
expvar.Publish("NumGoroutines", expvar.Func(func() interface{} {
expvar.Publish("NumGoroutines", expvar.Func(func() any {
return runtime.NumGoroutine()
}))
+34 -34
View File
@@ -60,9 +60,9 @@ type Topic struct {
tags []string
// Topic's public data
public interface{}
public any
// Topic's trusted data
trusted interface{}
trusted any
// Topic's per-subscriber data
perUser map[types.Uid]perUserData
@@ -137,14 +137,14 @@ type perUserData struct {
// ID of the latest Delete operation
delID int
private interface{}
private any
modeWant types.AccessMode
modeGiven types.AccessMode
// P2P only:
public interface{}
trusted interface{}
public any
trusted any
lastSeen *time.Time
lastUA string
@@ -953,7 +953,7 @@ func (t *Topic) sendSubNotifications(asUid types.Uid, sid, userAgent string) {
// Saves a new message (defined by head, content and attachments) in the topic
// in response to a client request (msg, asUid) and broadcasts it to the attached sessions.
func (t *Topic) saveAndBroadcastMessage(msg *ClientComMessage, asUid types.Uid, noEcho bool, attachments []string, head map[string]interface{}, content interface{}) error {
func (t *Topic) saveAndBroadcastMessage(msg *ClientComMessage, asUid types.Uid, noEcho bool, attachments []string, head map[string]any, content any) error {
pud, userFound := t.perUser[asUid]
// Anyone is allowed to post to 'sys' topic.
if t.cat != types.TopicCatSys {
@@ -967,7 +967,7 @@ func (t *Topic) saveAndBroadcastMessage(msg *ClientComMessage, asUid types.Uid,
if msg.sess != nil && msg.sess.uid != asUid {
// The "sender" header contains ID of the user who sent the message on behalf of asUid.
if head == nil {
head = map[string]interface{}{}
head = map[string]any{}
}
head["sender"] = msg.sess.uid.UserId()
} else if head != nil {
@@ -1003,7 +1003,7 @@ func (t *Topic) saveAndBroadcastMessage(msg *ClientComMessage, asUid types.Uid,
if msg.Id != "" && msg.sess != nil {
reply := NoErrAccepted(msg.Id, t.original(asUid), msg.Timestamp)
reply.Ctrl.Params = map[string]interface{}{"seq": t.lastID}
reply.Ctrl.Params = map[string]any{"seq": t.lastID}
msg.sess.queueOut(reply)
}
@@ -1168,7 +1168,7 @@ func (t *Topic) handleNoteBroadcast(msg *ClientComMessage) {
topicName = msg.Note.Topic
}
upd := map[string]interface{}{}
upd := map[string]any{}
if recv > 0 {
upd["RecvSeqId"] = recv
}
@@ -1348,7 +1348,7 @@ func (t *Topic) subscriptionReply(asChan bool, msg *ClientComMessage) error {
msgsub.Newsub = !found || pud.deleted
}
var private interface{}
var private any
var mode string
if msgsub.Set != nil {
if msgsub.Set.Sub != nil {
@@ -1396,7 +1396,7 @@ func (t *Topic) subscriptionReply(asChan bool, msg *ClientComMessage) error {
}
}
params := map[string]interface{}{}
params := map[string]any{}
// Report back the assigned access mode.
if modeChanged != nil {
params["acs"] = modeChanged
@@ -1453,7 +1453,7 @@ func (t *Topic) subscriptionReply(asChan bool, msg *ClientComMessage) error {
// E. User is accepting ownership transfer (requesting ownership transfer is not permitted).
// In case of a group topic the user may be a reader or a full subscriber.
func (t *Topic) thisUserSub(sess *Session, pkt *ClientComMessage, asUid types.Uid, asChan bool, want string,
private interface{}) (*MsgAccessMode, error) {
private any) (*MsgAccessMode, error) {
now := types.TimeNow()
asLvl := auth.Level(pkt.AuthLvl)
@@ -1609,7 +1609,7 @@ func (t *Topic) thisUserSub(sess *Session, pkt *ClientComMessage, asUid types.Ui
} else if asChan && userData.modeWant != oldWant {
// Channel reader changed access mode, save changed mode to db.
if err := store.Subs.Update(tname, asUid,
map[string]interface{}{"ModeWant": userData.modeWant}); err != nil {
map[string]any{"ModeWant": userData.modeWant}); err != nil {
sess.queueOut(ErrUnknownReply(pkt, now))
return nil, err
}
@@ -1709,7 +1709,7 @@ func (t *Topic) thisUserSub(sess *Session, pkt *ClientComMessage, asUid types.Ui
}
// Save changes to DB
update := map[string]interface{}{}
update := map[string]any{}
if isNullValue(private) {
update["Private"] = nil
userData.private = nil
@@ -1743,7 +1743,7 @@ func (t *Topic) thisUserSub(sess *Session, pkt *ClientComMessage, asUid types.Ui
oldOwnerData.modeGiven = (oldOwnerData.modeGiven & ^types.ModeOwner)
oldOwnerData.modeWant = (oldOwnerData.modeWant & ^types.ModeOwner)
if err := store.Subs.Update(t.name, t.owner,
map[string]interface{}{
map[string]any{
"ModeWant": oldOwnerData.modeWant,
"ModeGiven": oldOwnerData.modeGiven,
}); err != nil {
@@ -1985,7 +1985,7 @@ func (t *Topic) anotherUserSub(sess *Session, asUid, target types.Uid, asChan bo
// Save changed value to database
if err := store.Subs.Update(t.name, target,
map[string]interface{}{"ModeGiven": modeGiven}); err != nil {
map[string]any{"ModeGiven": modeGiven}); err != nil {
return nil, err
}
@@ -2148,7 +2148,7 @@ func (t *Topic) replySetDesc(sess *Session, asUid types.Uid, asChan bool,
authLevel auth.Level, msg *ClientComMessage) error {
now := types.TimeNow()
assignAccess := func(upd map[string]interface{}, mode *MsgDefaultAcsMode) error {
assignAccess := func(upd map[string]any, mode *MsgDefaultAcsMode) error {
if mode == nil {
return nil
}
@@ -2185,7 +2185,7 @@ func (t *Topic) replySetDesc(sess *Session, asUid types.Uid, asChan bool,
return nil
}
assignGenericValues := func(upd map[string]interface{}, what string, dst, src interface{}) (changed bool) {
assignGenericValues := func(upd map[string]any, what string, dst, src any) (changed bool) {
if dst, changed = mergeInterfaces(dst, src); changed {
upd[what] = dst
}
@@ -2199,9 +2199,9 @@ func (t *Topic) replySetDesc(sess *Session, asUid types.Uid, asChan bool,
var err error
// Change to the main object (user or topic).
core := make(map[string]interface{})
core := make(map[string]any)
// Change to subscription.
sub := make(map[string]interface{})
sub := make(map[string]any)
if set := msg.Set; set.Desc != nil {
if set.Desc.Trusted != nil && authLevel != auth.LevelRoot {
// Only ROOT can change Trusted.
@@ -2640,7 +2640,7 @@ func (t *Topic) replyGetSub(sess *Session, asUid types.Uid, authLevel auth.Level
sess.queueOut(&ServerComMessage{Meta: meta})
} else {
// Inform the client that there are no subscriptions.
sess.queueOut(NoContentParamsReply(msg, now, map[string]interface{}{"what": "sub"}))
sess.queueOut(NoContentParamsReply(msg, now, map[string]any{"what": "sub"}))
}
return nil
@@ -2683,7 +2683,7 @@ func (t *Topic) replySetSub(sess *Session, pkt *ClientComMessage, asChan bool) e
var resp *ServerComMessage
if modeChanged != nil {
// Report resulting access mode.
params := map[string]interface{}{"acs": modeChanged}
params := map[string]any{"acs": modeChanged}
if target != asUid {
params["user"] = target.UserId()
}
@@ -2748,10 +2748,10 @@ func (t *Topic) replyGetData(sess *Session, asUid types.Uid, asChan bool, req *M
// Inform the requester that all the data has been served.
if count == 0 {
sess.queueOut(NoContentParamsReply(msg, now, map[string]interface{}{"what": "data"}))
sess.queueOut(NoContentParamsReply(msg, now, map[string]any{"what": "data"}))
} else {
sess.queueOut(NoErrDeliveredParams(msg.Id, msg.Original, now,
map[string]interface{}{"what": "data", "count": count}))
map[string]any{"what": "data", "count": count}))
}
return nil
@@ -2810,7 +2810,7 @@ func (t *Topic) replySetTags(sess *Session, asUid types.Uid, msg *ClientComMessa
} else {
added, removed, _ := stringSliceDelta(t.tags, tags)
if len(added) > 0 || len(removed) > 0 {
update := map[string]interface{}{"Tags": tags, "UpdatedAt": now}
update := map[string]any{"Tags": tags, "UpdatedAt": now}
if t.cat == types.TopicCatMe {
err = store.Users.Update(asUid, update)
} else if t.cat == types.TopicCatGrp {
@@ -2823,7 +2823,7 @@ func (t *Topic) replySetTags(sess *Session, asUid types.Uid, msg *ClientComMessa
t.tags = tags
t.presSubsOnline("tags", "", nilPresParams, &presFilters{singleUser: asUid.UserId()}, sess.sid)
params := make(map[string]interface{})
params := make(map[string]any)
if len(added) > 0 {
params["added"] = len(added)
}
@@ -3329,7 +3329,7 @@ func (t *Topic) evictUser(uid types.Uid, unsub bool, skip string) {
// Detach all user's sessions
msg := NoErrEvicted("", t.original(uid), now)
msg.Ctrl.Params = map[string]interface{}{"unsub": unsub}
msg.Ctrl.Params = map[string]any{"unsub": unsub}
msg.SkipSid = skip
msg.uid = uid
msg.AsUser = uid.UserId()
@@ -3577,12 +3577,12 @@ func (t *Topic) p2pOtherUser(uid types.Uid) types.Uid {
}
// Get per-session value of fnd.Public
func (t *Topic) fndGetPublic(sess *Session) interface{} {
func (t *Topic) fndGetPublic(sess *Session) any {
if t.cat == types.TopicCatFnd {
if t.public == nil {
return nil
}
if pubmap, ok := t.public.(map[string]interface{}); ok {
if pubmap, ok := t.public.(map[string]any); ok {
return pubmap[sess.sid]
}
panic("Invalid Fnd.Public type")
@@ -3591,21 +3591,21 @@ func (t *Topic) fndGetPublic(sess *Session) interface{} {
}
// Assign per-session fnd.Public. Returns true if value has been changed.
func (t *Topic) fndSetPublic(sess *Session, public interface{}) bool {
func (t *Topic) fndSetPublic(sess *Session, public any) bool {
if t.cat != types.TopicCatFnd {
panic("Not Fnd topic")
}
var pubmap map[string]interface{}
var pubmap map[string]any
var ok bool
if t.public != nil {
if pubmap, ok = t.public.(map[string]interface{}); !ok {
if pubmap, ok = t.public.(map[string]any); !ok {
// This could only happen if fnd.public is assigned outside of this function.
panic("Invalid Fnd.Public type")
}
}
if pubmap == nil {
pubmap = make(map[string]interface{})
pubmap = make(map[string]any)
}
if public != nil {
@@ -3628,7 +3628,7 @@ func (t *Topic) fndRemovePublic(sess *Session) {
}
// FIXME: case of a multiplexing session won't work correctly.
// Maybe handle it at the proxy topic.
if pubmap, ok := t.public.(map[string]interface{}); ok {
if pubmap, ok := t.public.(map[string]any); ok {
delete(pubmap, sess.sid)
return
}
+9 -9
View File
@@ -17,7 +17,7 @@ import (
)
type responses struct {
messages []interface{}
messages []any
}
// Test fixture.
@@ -70,7 +70,7 @@ func (b *TopicTestHelper) newSession(sid string, uid types.Uid) (*Session, *resp
sid: sid,
uid: uid,
subs: make(map[string]*Subscription),
send: make(chan interface{}, 10),
send: make(chan any, 10),
detach: make(chan string, 10),
}
r := &responses{}
@@ -278,7 +278,7 @@ func TestHandleBroadcastCall(t *testing.T) {
Original: from,
Pub: &MsgClientPub{
Topic: "p2p",
Head: map[string]interface{}{"webrtc": "started"},
Head: map[string]any{"webrtc": "started"},
Content: "test",
NoEcho: true,
},
@@ -626,7 +626,7 @@ func TestHandleBroadcastInfoP2P(t *testing.T) {
from := helper.uids[0]
to := helper.uids[1]
helper.ss.EXPECT().Update(topicName, from, map[string]interface{}{"ReadSeqId": readId}).Return(nil)
helper.ss.EXPECT().Update(topicName, from, map[string]any{"ReadSeqId": readId}).Return(nil)
msg := &ClientComMessage{
AsUser: from.UserId(),
@@ -918,7 +918,7 @@ func TestHandleBroadcastInfoDbError(t *testing.T) {
from := helper.uids[0]
to := helper.uids[1]
helper.ss.EXPECT().Update(topicName, from, map[string]interface{}{"ReadSeqId": readId}).Return(types.ErrInternal)
helper.ss.EXPECT().Update(topicName, from, map[string]any{"ReadSeqId": readId}).Return(types.ErrInternal)
msg := &ClientComMessage{
AsUser: from.UserId(),
@@ -1022,7 +1022,7 @@ func TestHandleBroadcastInfoChannelProcessing(t *testing.T) {
helper.topic.perUser[uid] = pud
}
helper.ss.EXPECT().Update(chanName, from, map[string]interface{}{"ReadSeqId": readId}).Return(nil)
helper.ss.EXPECT().Update(chanName, from, map[string]any{"ReadSeqId": readId}).Return(nil)
msg := &ClientComMessage{
AsUser: from.UserId(),
@@ -2375,8 +2375,8 @@ func SupersetOf(subset map[string]string) gomock.Matcher {
return &supersetOf{subset}
}
func (s *supersetOf) Matches(x interface{}) bool {
super := x.(map[string]interface{})
func (s *supersetOf) Matches(x any) bool {
super := x.(map[string]any)
if super == nil {
return false
}
@@ -2407,7 +2407,7 @@ func TestHandleMetaSetDescMePublicPrivate(t *testing.T) {
uid := helper.uids[0]
gomock.InOrder(
helper.uu.EXPECT().Update(uid, SupersetOf(map[string]string{"Public": "new public"})).Return(nil),
helper.ss.EXPECT().Update(topicName, uid, map[string]interface{}{"Private": "new private"}).Return(nil),
helper.ss.EXPECT().Update(topicName, uid, map[string]any{"Private": "new private"}).Return(nil),
)
meta := &ClientComMessage{
+12 -12
View File
@@ -42,19 +42,19 @@ func replyCreateUser(s *Session, msg *ClientComMessage, rec *auth.Rec) {
if ok, err := authhdl.IsUnique(msg.Acc.Secret, s.remoteAddr); !ok {
logs.Warn.Println("create user: auth secret is not unique", err, "sid=", s.sid)
s.queueOut(decodeStoreError(err, msg.Id, msg.Timestamp,
map[string]interface{}{"what": "auth"}))
map[string]any{"what": "auth"}))
return
}
var user types.User
var private interface{}
var private any
// If account state is being assigned, make sure the sender is a root user.
if msg.Acc.State != "" {
if auth.Level(msg.AuthLvl) != auth.LevelRoot {
logs.Warn.Println("create user: attempt to set account state by non-root, sid=", s.sid)
msg := ErrPermissionDenied(msg.Id, "", msg.Timestamp)
msg.Ctrl.Params = map[string]interface{}{"what": "state"}
msg.Ctrl.Params = map[string]any{"what": "state"}
s.queueOut(msg)
return
}
@@ -73,7 +73,7 @@ func replyCreateUser(s *Session, msg *ClientComMessage, rec *auth.Rec) {
if !restrictedTagsEqual(tags, nil, globals.immutableTagNS) {
logs.Warn.Println("create user: attempt to directly assign restricted tags, sid=", s.sid)
msg := ErrPermissionDenied(msg.Id, "", msg.Timestamp)
msg.Ctrl.Params = map[string]interface{}{"what": "tags"}
msg.Ctrl.Params = map[string]any{"what": "tags"}
s.queueOut(msg)
return
}
@@ -89,7 +89,7 @@ func replyCreateUser(s *Session, msg *ClientComMessage, rec *auth.Rec) {
if _, err := vld.PreCheck(cr.Value, cr.Params); err != nil {
logs.Warn.Println("create user: failed credential pre-check", cr, err, "sid=", s.sid)
s.queueOut(decodeStoreError(err, msg.Id, msg.Timestamp,
map[string]interface{}{"what": cr.Method}))
map[string]any{"what": cr.Method}))
return
}
}
@@ -156,7 +156,7 @@ func replyCreateUser(s *Session, msg *ClientComMessage, rec *auth.Rec) {
}
_, missing, _ := stringSliceDelta(globals.authValidators[rec.AuthLevel], credentialMethods(creds))
s.queueOut(decodeStoreError(types.ErrPolicy, msg.Id, msg.Timestamp,
map[string]interface{}{"creds": missing}))
map[string]any{"creds": missing}))
return
}
@@ -192,13 +192,13 @@ func replyCreateUser(s *Session, msg *ClientComMessage, rec *auth.Rec) {
} else {
// Not using the new account for logging in.
reply = NoErrCreated(msg.Id, "", msg.Timestamp)
reply.Ctrl.Params = map[string]interface{}{
reply.Ctrl.Params = map[string]any{
"user": user.Uid().UserId(),
"authlvl": rec.AuthLevel.String(),
}
}
params := reply.Ctrl.Params.(map[string]interface{})
params := reply.Ctrl.Params.(map[string]any)
params["desc"] = &MsgTopicDesc{
CreatedAt: &user.CreatedAt,
UpdatedAt: &user.UpdatedAt,
@@ -274,7 +274,7 @@ func replyUpdateUser(s *Session, msg *ClientComMessage, rec *auth.Rec) {
return
}
var params map[string]interface{}
var params map[string]any
if msg.Acc.Scheme != "" {
err = updateUserAuth(msg, user, rec, s.remoteAddr)
} else if len(msg.Acc.Cred) > 0 {
@@ -300,7 +300,7 @@ func replyUpdateUser(s *Session, msg *ClientComMessage, rec *auth.Rec) {
}
_, missing, _ := stringSliceDelta(globals.authValidators[authLvl], validated)
if len(missing) > 0 {
params = map[string]interface{}{"cred": missing}
params = map[string]any{"cred": missing}
}
}
}
@@ -773,14 +773,14 @@ func (pq pendingReceiptsQueue) Swap(i, j int) {
pq[j].index = j
}
func (pq *pendingReceiptsQueue) Push(x interface{}) {
func (pq *pendingReceiptsQueue) Push(x any) {
n := len(*pq)
item := x.(*pendingReceipt)
item.index = n
*pq = append(*pq, item)
}
func (pq *pendingReceiptsQueue) Pop() interface{} {
func (pq *pendingReceiptsQueue) Pop() any {
old := *pq
n := len(old)
item := old[n-1]
+11 -11
View File
@@ -221,19 +221,19 @@ func msgOpts2storeOpts(req *MsgGetOpts) *types.QueryOpt {
}
// Check if the interface contains a string with a single Unicode Del control character.
func isNullValue(i interface{}) bool {
func isNullValue(i any) bool {
if str, ok := i.(string); ok {
return str == nullValue
}
return false
}
func decodeStoreError(err error, id string, ts time.Time, params map[string]interface{}) *ServerComMessage {
func decodeStoreError(err error, id string, ts time.Time, params map[string]any) *ServerComMessage {
return decodeStoreErrorExplicitTs(err, id, "", ts, ts, params)
}
func decodeStoreErrorExplicitTs(err error, id, topic string, serverTs, incomingReqTs time.Time,
params map[string]interface{}) *ServerComMessage {
params map[string]any) *ServerComMessage {
var errmsg *ServerComMessage
@@ -435,7 +435,7 @@ func rewriteTag(orig, countryCode string, withLogin bool) string {
}
// Check if token can be rewritten by any of the validators
param := map[string]interface{}{"countryCode": countryCode}
param := map[string]any{"countryCode": countryCode}
for name, conf := range globals.validators {
if conf.addToTags {
val := store.Store.GetValidator(name)
@@ -758,7 +758,7 @@ func parseTLSConfig(tlsEnabled bool, jsconfig json.RawMessage) (*tls.Config, err
// Merge source interface{} into destination interface.
// If values are maps,deep-merge them. Otherwise shallow-copy.
// Returns dst, true if the dst value was changed.
func mergeInterfaces(dst, src interface{}) (interface{}, bool) {
func mergeInterfaces(dst, src any) (any, bool) {
var changed bool
if src == nil {
@@ -768,8 +768,8 @@ func mergeInterfaces(dst, src interface{}) (interface{}, bool) {
vsrc := reflect.ValueOf(src)
switch vsrc.Kind() {
case reflect.Map:
if xsrc, ok := src.(map[string]interface{}); ok {
xdst, _ := dst.(map[string]interface{})
if xsrc, ok := src.(map[string]any); ok {
xdst, _ := dst.(map[string]any)
dst, changed = mergeMaps(xdst, xsrc)
} else {
changed = true
@@ -791,7 +791,7 @@ func mergeInterfaces(dst, src interface{}) (interface{}, bool) {
}
// Deep copy maps.
func mergeMaps(dst, src map[string]interface{}) (map[string]interface{}, bool) {
func mergeMaps(dst, src map[string]any) (map[string]any, bool) {
var changed bool
if len(src) == 0 {
@@ -799,16 +799,16 @@ func mergeMaps(dst, src map[string]interface{}) (map[string]interface{}, bool) {
}
if dst == nil {
dst = make(map[string]interface{})
dst = make(map[string]any)
}
for key, val := range src {
xval := reflect.ValueOf(val)
switch xval.Kind() {
case reflect.Map:
if xsrc, _ := val.(map[string]interface{}); xsrc != nil {
if xsrc, _ := val.(map[string]any); xsrc != nil {
// Deep-copy map[string]interface{}
xdst, _ := dst[key].(map[string]interface{})
xdst, _ := dst[key].(map[string]any)
var lchange bool
dst[key], lchange = mergeMaps(xdst, xsrc)
changed = changed || lchange