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

2
.gitignore vendored
View File

@ -30,3 +30,5 @@ commentsRouter*.go
# ignore build result # ignore build result
casdoor casdoor
server_linux_arm64
server_linux_amd64

View File

@ -118,8 +118,7 @@ func (c *ApiController) GetOrganizationApplications() {
} }
if limit == "" || page == "" { 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.Data["json"] = object.GetMaskedApplications(applications, userId)
c.ServeJSON() c.ServeJSON()
} else { } else {

View File

@ -30,8 +30,7 @@ import (
// @Success 200 {array} object.Chat The Response object // @Success 200 {array} object.Chat The Response object
// @router /get-chats [get] // @router /get-chats [get]
func (c *ApiController) GetChats() { func (c *ApiController) GetChats() {
owner := c.Input().Get("owner") owner := "admin"
owner = "admin"
limit := c.Input().Get("pageSize") limit := c.Input().Get("pageSize")
page := c.Input().Get("p") page := c.Input().Get("p")
field := c.Input().Get("field") 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"` ProviderSecret string `json:"provider_secret"`
}{idp.Config.ClientID, idp.Config.ClientSecret} }{idp.Config.ClientID, idp.Config.ClientSecret}
data, err := idp.postWithBody(pTokenParams, "https://qyapi.weixin.qq.com/cgi-bin/service/get_provider_token") data, err := idp.postWithBody(pTokenParams, "https://qyapi.weixin.qq.com/cgi-bin/service/get_provider_token")
if err != nil {
return nil, err
}
pToken := &WeComProviderToken{} pToken := &WeComProviderToken{}
err = json.Unmarshal(data, pToken) err = json.Unmarshal(data, pToken)
if err != nil { if err != nil {

View File

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

View File

@ -145,7 +145,7 @@ func getProviderMap(owner string) map[string]*Provider {
m := map[string]*Provider{} m := map[string]*Provider{}
for _, provider := range providers { for _, provider := range providers {
// Get QRCode only once // 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) provider.Content, _ = idp.GetWechatOfficialAccountQRCode(provider.ClientId2, provider.ClientSecret2)
UpdateProvider(provider.Owner+"/"+provider.Name, provider) UpdateProvider(provider.Owner+"/"+provider.Name, provider)
} }

View File

@ -248,7 +248,7 @@ func CheckUserPassword(organization string, username string, password string, la
enableCaptcha = options[0] enableCaptcha = options[0]
} }
user := GetUserByFields(organization, username) 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)) 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 { func (*Migrator_1_235_0_PR_1530) IsMigrationNeeded() bool {
exist, _ := adapter.Engine.IsTableExist("casbin_rule") exist, _ := adapter.Engine.IsTableExist("casbin_rule")
if exist { return exist
return true
}
return false
} }
func (*Migrator_1_235_0_PR_1530) DoMigration() *migrate.Migration { 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) // Attempt to parse the host as an IP address (both IPv4 and IPv6)
ip := net.ParseIP(hostWithoutPort) ip := net.ParseIP(hostWithoutPort)
if ip != nil { // if host is not nil is an IP address else is not an IP address
// The host is an IP address return ip != nil
return true
}
// The host is not an IP address
return false
} }
func getOriginFromHost(host string) (string, string) { func getOriginFromHost(host string) (string, string) {

View File

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

View File

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

View File

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