Skip to content

Commit

Permalink
Remove ioutil
Browse files Browse the repository at this point in the history
  • Loading branch information
ego008 committed May 9, 2024
1 parent 1520848 commit 35c95d6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 17 deletions.
5 changes: 2 additions & 3 deletions controller/site_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/valyala/fasthttp"
"goyoubbs/model"
"goyoubbs/util"
"io/ioutil"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -133,7 +132,7 @@ func (h *BaseHandler) SitemapIndexHandler(ctx *fasthttp.RequestCtx) {

filename := "static/sitemap/" + xmlFile
var buf []byte
buf, err = ioutil.ReadFile(filename)
buf, err = os.ReadFile(filename)
if err == nil {
// get sitemap_x.xml mtime
var fileInfo os.FileInfo
Expand Down Expand Up @@ -207,7 +206,7 @@ func (h *BaseHandler) SitemapIndexHandler(ctx *fasthttp.RequestCtx) {
return
}

buf, err = ioutil.ReadFile("static/sitemap/" + xmlFile)
buf, err = os.ReadFile("static/sitemap/" + xmlFile)
if err != nil {
ctx.SetStatusCode(fasthttp.StatusInternalServerError)
return
Expand Down
10 changes: 5 additions & 5 deletions controller/static_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package controller
import (
"bytes"
"github.com/valyala/fasthttp"
"io/ioutil"
"net/http"
"os"
)

var defaultRobots = `User-agent: *
Expand All @@ -13,7 +13,7 @@ Disallow: /admin

func (h *BaseHandler) Robots(ctx *fasthttp.RequestCtx) {
ctx.SetContentType("text/plain; charset=utf-8")
buf, err := ioutil.ReadFile("static/robots.txt")
buf, err := os.ReadFile("static/robots.txt")
if err != nil {
_, _ = ctx.WriteString(defaultRobots + "\nSitemap: " + h.App.Cf.Site.MainDomain + "/sitemap.xml")
return
Expand All @@ -26,7 +26,7 @@ func (h *BaseHandler) Robots(ctx *fasthttp.RequestCtx) {

func (h *BaseHandler) Ads(ctx *fasthttp.RequestCtx) {
ctx.SetContentType("text/plain; charset=utf-8")
buf, err := ioutil.ReadFile("static/ads.txt")
buf, err := os.ReadFile("static/ads.txt")
if err != nil {
ctx.SetStatusCode(fasthttp.StatusNotFound)
_, _ = ctx.WriteString("404: not found")
Expand All @@ -37,7 +37,7 @@ func (h *BaseHandler) Ads(ctx *fasthttp.RequestCtx) {

func (h *BaseHandler) StaticFile(ctx *fasthttp.RequestCtx) {
filePath := ctx.UserValue("filepath").(string)
buf, err := ioutil.ReadFile("static/" + filePath)
buf, err := os.ReadFile("static/" + filePath)
if err != nil {
ctx.SetContentType("text/plain; charset=utf-8")
ctx.SetStatusCode(fasthttp.StatusNotFound)
Expand All @@ -51,7 +51,7 @@ func (h *BaseHandler) StaticFile(ctx *fasthttp.RequestCtx) {

func (h *BaseHandler) ShowIcon(ctx *fasthttp.RequestCtx) {
ctx.SetContentType("image/png")
buf, err := ioutil.ReadFile("static/logo.png")
buf, err := os.ReadFile("static/logo.png")
if err != nil {
ctx.NotFound()
return
Expand Down
2 changes: 1 addition & 1 deletion controller/topic_icon.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (h *BaseHandler) TopicIconHandle(ctx *fasthttp.RequestCtx) {
})

//for _, v := range uIds {
// dat, err := ioutil.ReadFile("static/avatar/" + strconv.Itoa(v) + ".jpg")
// dat, err := os.ReadFile("static/avatar/" + strconv.Itoa(v) + ".jpg")
// if err != nil {
// log.Println("Read avatar err", err)
// continue
Expand Down
2 changes: 1 addition & 1 deletion cronjob/fetch_avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func FetchAvatar(db *sdb.DB, uid uint64, targetUrl, saveFilePath, ua, sock5Str s

// save to local
/*
err = ioutil.WriteFile(saveFilePath, body, 0644)
err = os.WriteFile(saveFilePath, body, 0644)
if err != nil {
log.Println("WriteFile err", err)
return err
Expand Down
8 changes: 4 additions & 4 deletions lib/qqOAuth/qqOAuth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package qqOAuth
import (
"errors"
"github.com/ego008/goutils/json"
"io/ioutil"
"io"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -103,7 +103,7 @@ func (oauth *OAuth) GetAccessToken(code string) (*OAuthToken, error) {
}
defer resp.Body.Close()

bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -144,7 +144,7 @@ func (oauth *OAuth) GetOpenID(accessToken string) (*OpenID, error) {
}
defer resp.Body.Close()

bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -190,7 +190,7 @@ func (oauth *OAuth) GetUserInfo(accessToken string, openID string) (*UserInfo, e
}
defer resp.Body.Close()

bodyBytes, err := ioutil.ReadAll(resp.Body)
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions lib/weiboOAuth/weiboOAuth.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package weiboOAuth
import (
"errors"
"github.com/ego008/goutils/json"
"io/ioutil"
"io"
"log"
"net/http"
"net/url"
Expand Down Expand Up @@ -89,7 +89,7 @@ func (oauth *OAuth) GetAccessToken(code string) (*OAuthToken, error) {
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func (oauth *OAuth) GetUserInfo(accessToken, uid string) (*UserInfo, error) {
}
defer resp.Body.Close()

body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 35c95d6

Please sign in to comment.