Skip to content

Commit

Permalink
feat(validate):validate success
Browse files Browse the repository at this point in the history
  • Loading branch information
steven committed Jan 15, 2022
1 parent f14654d commit 4e1d142
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
7 changes: 7 additions & 0 deletions router.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,17 @@ func (s *ImSrever) Connection(writer http.ResponseWriter, request *http.Request)
res.Data = err.Error()
return
}
// validate failed
if err := s.opt.ServerValidate.Validate(token);err !=nil {
s.opt.ServerValidate.ValidateFailed(err,cli)
return
}else {
//validate success
s.opt.ServerValidate.ValidateSuccess(cli)
}


// register to data
if err := bs.Register(cli,token);err !=nil {
cli.Send([]byte(err.Error()))
cli.Offline()
Expand Down
8 changes: 7 additions & 1 deletion validate/example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ func (d *DefaultValidate)ValidateFailed(err error,cli client.Clienter){
// 当用户登录验证失败,逻辑应该在这里来处理
cli.Send([]byte("user validate is bad"))
cli.Offline()
}
}


func (d *DefaultValidate)ValidateSuccess(cli client.Clienter){
// 当用户登录验证失败,逻辑应该在这里来处理
cli.Send([]byte("user is online "))
}
1 change: 1 addition & 0 deletions validate/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ import "github.com/mongofs/im/client"
type Validater interface {
Validate(token string)error
ValidateFailed(err error,cli client.Clienter)
ValidateSuccess(cli client.Clienter)
}

0 comments on commit 4e1d142

Please sign in to comment.