refactor: code-optimization (#1885)

* refactor: code-optimization

* fix: restoring code style

* fix: gofmt
This commit is contained in:
guangwu
2023-05-23 17:54:51 +08:00
committed by GitHub
parent 2389d47c34
commit 54e4747dbc
12 changed files with 22 additions and 29 deletions

View File

@ -145,7 +145,7 @@ func getProviderMap(owner string) map[string]*Provider {
m := map[string]*Provider{}
for _, provider := range providers {
// Get QRCode only once
if provider.Type == "WeChat" && provider.DisableSsl == true && provider.Content == "" {
if provider.Type == "WeChat" && provider.DisableSsl && provider.Content == "" {
provider.Content, _ = idp.GetWechatOfficialAccountQRCode(provider.ClientId2, provider.ClientSecret2)
UpdateProvider(provider.Owner+"/"+provider.Name, provider)
}

View File

@ -248,7 +248,7 @@ func CheckUserPassword(organization string, username string, password string, la
enableCaptcha = options[0]
}
user := GetUserByFields(organization, username)
if user == nil || user.IsDeleted == true {
if user == nil || user.IsDeleted {
return nil, fmt.Sprintf(i18n.Translate(lang, "general:The user: %s doesn't exist"), util.GetId(organization, username))
}

View File

@ -25,10 +25,7 @@ type Migrator_1_235_0_PR_1530 struct{}
func (*Migrator_1_235_0_PR_1530) IsMigrationNeeded() bool {
exist, _ := adapter.Engine.IsTableExist("casbin_rule")
if exist {
return true
}
return false
return exist
}
func (*Migrator_1_235_0_PR_1530) DoMigration() *migrate.Migration {

View File

@ -55,13 +55,8 @@ func isIpAddress(host string) bool {
// Attempt to parse the host as an IP address (both IPv4 and IPv6)
ip := net.ParseIP(hostWithoutPort)
if ip != nil {
// The host is an IP address
return true
}
// The host is not an IP address
return false
// if host is not nil is an IP address else is not an IP address
return ip != nil
}
func getOriginFromHost(host string) (string, string) {

View File

@ -33,10 +33,10 @@ type VerifyResult struct {
}
const (
VerificationSuccess int = 0
wrongCodeError = 1
noRecordError = 2
timeoutError = 3
VerificationSuccess = iota
wrongCodeError
noRecordError
timeoutError
)
const (