mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-23 02:35:49 +08:00
fix: improve code format (#2665)
* feat: replace io/ioutils pacakage with io/os package * fix: add missing error handling
This commit is contained in:
parent
0918757e85
commit
e593f5be5b
@ -19,7 +19,7 @@ import (
|
||||
"encoding/json"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@ -921,7 +921,7 @@ func (c *ApiController) HandleSamlLogin() {
|
||||
// @router /webhook [POST]
|
||||
// @Success 200 {object} object.Userinfo The Response object
|
||||
func (c *ApiController) HandleOfficialAccountEvent() {
|
||||
respBytes, err := ioutil.ReadAll(c.Ctx.Request.Body)
|
||||
respBytes, err := io.ReadAll(c.Ctx.Request.Body)
|
||||
if err != nil {
|
||||
c.ResponseError(err.Error())
|
||||
return
|
||||
|
@ -121,6 +121,10 @@ func (c *ApiController) Enforce() {
|
||||
}
|
||||
} else if owner != "" {
|
||||
permissions, err = object.GetPermissions(owner)
|
||||
if err != nil {
|
||||
c.ResponseError(err.Error())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
c.ResponseError(c.T("general:Missing parameter"))
|
||||
return
|
||||
@ -235,6 +239,10 @@ func (c *ApiController) BatchEnforce() {
|
||||
}
|
||||
} else if owner != "" {
|
||||
permissions, err = object.GetPermissions(owner)
|
||||
if err != nil {
|
||||
c.ResponseError(err.Error())
|
||||
return
|
||||
}
|
||||
} else {
|
||||
c.ResponseError(c.T("general:Missing parameter"))
|
||||
return
|
||||
|
@ -47,6 +47,11 @@ func (c *ApiController) GetSystemInfo() {
|
||||
// @router /get-version-info [get]
|
||||
func (c *ApiController) GetVersionInfo() {
|
||||
versionInfo, err := util.GetVersionInfo()
|
||||
if err != nil {
|
||||
c.ResponseError(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
if versionInfo.Version != "" {
|
||||
c.ResponseOk(versionInfo)
|
||||
return
|
||||
|
@ -20,7 +20,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
@ -218,7 +217,7 @@ func GetWechatOfficialAccountAccessToken(clientId string, clientSecret string) (
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
respBytes, err := ioutil.ReadAll(resp.Body)
|
||||
respBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@ -255,7 +254,7 @@ func GetWechatOfficialAccountQRCode(clientId string, clientSecret string) (strin
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
respBytes, err := ioutil.ReadAll(resp.Body)
|
||||
respBytes, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -16,7 +16,6 @@ package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@ -40,7 +39,7 @@ func GetPath(path string) string {
|
||||
func ListFiles(path string) []string {
|
||||
res := []string{}
|
||||
|
||||
files, err := ioutil.ReadDir(path)
|
||||
files, err := os.ReadDir(path)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -14,10 +14,10 @@
|
||||
|
||||
package util
|
||||
|
||||
import "io/ioutil"
|
||||
import "os"
|
||||
|
||||
func GetUploadXlsxPath(fileId string) string {
|
||||
file, err := ioutil.TempFile("", fileId)
|
||||
file, err := os.CreateTemp("", fileId)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
@ -119,6 +119,9 @@ func GetVersionInfo() (*VersionInfo, error) {
|
||||
}
|
||||
|
||||
cIter, err := r.Log(&git.LogOptions{From: ref.Hash()})
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
|
||||
commitOffset := 0
|
||||
version := ""
|
||||
|
@ -70,6 +70,9 @@ func TestGetVersion(t *testing.T) {
|
||||
|
||||
testHash := plumbing.NewHash("f8bc87eb4e5ba3256424cf14aafe0549f812f1cf")
|
||||
cIter, err := r.Log(&git.LogOptions{From: testHash})
|
||||
if err != nil {
|
||||
t.Log(err)
|
||||
}
|
||||
|
||||
aheadCnt := 0
|
||||
releaseVersion := ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user