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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 22 additions and 29 deletions

4
.gitignore vendored
View File

@ -29,4 +29,6 @@ lastupdate.tmp
commentsRouter*.go
# ignore build result
casdoor
casdoor
server_linux_arm64
server_linux_amd64

View File

@ -118,8 +118,7 @@ func (c *ApiController) GetOrganizationApplications() {
}
if limit == "" || page == "" {
var applications []*object.Application
applications = object.GetOrganizationApplications(owner, organization)
applications := object.GetOrganizationApplications(owner, organization)
c.Data["json"] = object.GetMaskedApplications(applications, userId)
c.ServeJSON()
} else {

View File

@ -30,8 +30,7 @@ import (
// @Success 200 {array} object.Chat The Response object
// @router /get-chats [get]
func (c *ApiController) GetChats() {
owner := c.Input().Get("owner")
owner = "admin"
owner := "admin"
limit := c.Input().Get("pageSize")
page := c.Input().Get("p")
field := c.Input().Get("field")

View File

@ -75,7 +75,9 @@ func (idp *WeComIdProvider) GetToken(code string) (*oauth2.Token, error) {
ProviderSecret string `json:"provider_secret"`
}{idp.Config.ClientID, idp.Config.ClientSecret}
data, err := idp.postWithBody(pTokenParams, "https://qyapi.weixin.qq.com/cgi-bin/service/get_provider_token")
if err != nil {
return nil, err
}
pToken := &WeComProviderToken{}
err = json.Unmarshal(data, pToken)
if err != nil {

View File

@ -27,7 +27,6 @@ import (
"github.com/casdoor/casdoor/object"
"github.com/casdoor/casdoor/proxy"
"github.com/casdoor/casdoor/routers"
_ "github.com/casdoor/casdoor/routers"
"github.com/casdoor/casdoor/util"
)

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 (

View File

@ -66,13 +66,13 @@ func (db *Database) OnRow(e *canal.RowsEvent) error {
for i, row := range e.Rows {
for j, item := range row {
if i%2 == 0 {
if isChar[j] == true {
if isChar[j] {
oldColumnValue[j] = fmt.Sprintf("%s", item)
} else {
oldColumnValue[j] = fmt.Sprintf("%d", item)
}
} else {
if isChar[j] == true {
if isChar[j] {
if item == nil {
newColumnValue[j] = nil
} else {
@ -103,7 +103,7 @@ func (db *Database) OnRow(e *canal.RowsEvent) error {
db.engine.Exec("BEGIN")
for _, row := range e.Rows {
for j, item := range row {
if isChar[j] == true {
if isChar[j] {
oldColumnValue[j] = fmt.Sprintf("%s", item)
} else {
oldColumnValue[j] = fmt.Sprintf("%d", item)
@ -128,7 +128,7 @@ func (db *Database) OnRow(e *canal.RowsEvent) error {
db.engine.Exec("BEGIN")
for _, row := range e.Rows {
for j, item := range row {
if isChar[j] == true {
if isChar[j] {
if item == nil {
newColumnValue[j] = nil
} else {

View File

@ -25,7 +25,7 @@ import (
var rePhone *regexp.Regexp
func init() {
rePhone, _ = regexp.Compile("(\\d{3})\\d*(\\d{4})")
rePhone, _ = regexp.Compile(`(\d{3})\d*(\d{4})`)
}
func IsEmailValid(email string) bool {