Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drop ioutil and other cleans. #796

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/admin/models/datascope.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package models

import (
"errors"

"github.com/go-admin-team/go-admin-core/sdk/pkg"
"gorm.io/gorm"

Expand Down Expand Up @@ -31,7 +32,7 @@ func (e *DataPermission) GetDataScope(tableName string, db *gorm.DB) (*gorm.DB,
}
err = db.Find(role, user.RoleId).Error
if err != nil {
return nil, errors.New("获取用户数据出错 msg:" + err.Error())
return nil, errors.New("获取角色数据出错 msg:" + err.Error())
}
if role.DataScope == "2" {
db = db.Where(tableName+".create_by in (select sys_user.user_id from sys_role_dept left join sys_user on sys_user.dept_id=sys_role_dept.dept_id where sys_role_dept.role_id = ?)", user.RoleId)
Expand Down
9 changes: 5 additions & 4 deletions app/admin/models/initdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package models
import (
"fmt"
"go-admin/common/global"
"gorm.io/gorm"
"io/ioutil"
"log"
"os"
"strings"

"gorm.io/gorm"
)

func InitDb(db *gorm.DB) (err error) {
Expand Down Expand Up @@ -44,10 +45,10 @@ func ExecSql(db *gorm.DB, filePath string) error {
}

func Ioutil(filePath string) (string, error) {
if contents, err := ioutil.ReadFile(filePath); err == nil {
if contents, err := os.ReadFile(filePath); err == nil {
//因为contents是[]byte类型,直接转换成string类型后会多一行空格,需要使用strings.Replace替换换行符
result := strings.Replace(string(contents), "\n", "", 1)
fmt.Println("Use ioutil.ReadFile to read a file:", result)
fmt.Println("Use os.ReadFile to read a file:", result)
return result, nil
} else {
return "", err
Expand Down
6 changes: 3 additions & 3 deletions app/admin/models/sys_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"regexp"
"strings"

Expand Down Expand Up @@ -65,7 +65,7 @@ func SaveSysApi(message storage.Messager) (err error) {

// 根据接口方法注释里的@Summary填充接口名称,适用于代码生成器
// 可在此处增加配置路径前缀的if判断,只对代码生成的自建应用进行定向的接口名称填充
jsonFile, _ := ioutil.ReadFile("docs/swagger.json")
jsonFile, _ := os.ReadFile("docs/swagger.json")
jsonData, _ := simplejson.NewFromReader(bytes.NewReader(jsonFile))
urlPath := v.RelativePath
idPatten := "(.*)/:(\\w+)" // 正则替换,把:id换成{id}
Expand All @@ -81,7 +81,7 @@ func SaveSysApi(message storage.Messager) (err error) {
//Update("handle", v.Handler).
Error
if err != nil {
err := fmt.Errorf("Models SaveSysApi error: %s \r\n ", err.Error())
err := fmt.Errorf("models SaveSysApi error: %s \r\n ", err.Error())
return err
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/other/apis/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/gin-gonic/gin"
Expand Down Expand Up @@ -86,7 +86,7 @@ func (e File) baseImg(c *gin.Context, fileResponse FileResponse, urlPerfix strin
e.Error(500, errors.New(""), "初始化文件路径失败")
}
base64File := path + fileName
_ = ioutil.WriteFile(base64File, ddd, 0666)
_ = os.WriteFile(base64File, ddd, 0666)
typeStr := strings.Replace(strings.Replace(file2list[0], "data:", "", -1), ";base64", "", -1)
fileResponse = FileResponse{
Size: pkg.GetFileSize(base64File),
Expand Down
5 changes: 2 additions & 3 deletions cmd/migrate/migration/models/initdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package models
import (
"fmt"
"go-admin/common/global"
"io/ioutil"
"log"
"strings"

Expand Down Expand Up @@ -61,10 +60,10 @@ func ExecSql(db *gorm.DB, filePath string) error {
}

func Ioutil(filePath string) (string, error) {
if contents, err := ioutil.ReadFile(filePath); err == nil {
if contents, err := os.ReadFil(filePath); err == nil {
//因为contents是[]byte类型,直接转换成string类型后会多一行空格,需要使用strings.Replace替换换行符
result := strings.Replace(string(contents), "\n", "", 1)
fmt.Println("Use ioutil.ReadFile to read a file:", result)
fmt.Println("Use os.ReadFil to read a file:", result)
return result, nil
} else {
return "", err
Expand Down
5 changes: 2 additions & 3 deletions common/middleware/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"go-admin/app/admin/service/dto"
"go-admin/common"
"io"
"io/ioutil"
"net/http"
"strings"
"time"
Expand Down Expand Up @@ -38,8 +37,8 @@ func LoggerToFile() gin.HandlerFunc {
log.Warnf("copy body error, %s", err.Error())
err = nil
}
rb, _ := ioutil.ReadAll(bf)
c.Request.Body = ioutil.NopCloser(bytes.NewBuffer(rb))
rb, _ := io.ReadAll(bf)
c.Request.Body = io.NopCloser(bytes.NewBuffer(rb))
body = string(rb)
}

Expand Down