Skip to content

Commit

Permalink
Remove deperated go func
Browse files Browse the repository at this point in the history
  • Loading branch information
xuqingfeng committed Dec 14, 2023
1 parent fd96704 commit ff869f5
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 14 deletions.
3 changes: 1 addition & 2 deletions mail/attachment.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package mail

import (
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -19,7 +18,7 @@ func SaveAttachment(fileContent []byte, token, fileName string) error {
return err
}
attachmentPath := filepath.Join(homeDir, util.ConfigPath["tmpPath"], token, fileName)
err = ioutil.WriteFile(attachmentPath, fileContent, os.ModePerm)
err = os.WriteFile(attachmentPath, fileContent, os.ModePerm)
if err != nil {
util.FileLog.Error(err.Error())
return err
Expand Down
3 changes: 1 addition & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -274,7 +273,7 @@ func fileHandler(w http.ResponseWriter, r *http.Request) {
for _, fileHeaders := range r.MultipartForm.File {
for _, fileHeader := range fileHeaders {
f, _ := fileHeader.Open()
fileContent, _ := ioutil.ReadAll(f)
fileContent, _ := io.ReadAll(f)
err := mail.SaveAttachment(fileContent, token, fileHeader.Filename)
if err != nil {
sendError(w, "E! save attachment fail")
Expand Down
2 changes: 1 addition & 1 deletion smtp/smtp.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func GetSMTPServer(email string) (SMTPServer, error) {
}
}

return SMTPServer{}, util.SMTPServerNotFoundErr
return SMTPServer{}, util.ErrSMTPServerNotFound
}
func GetCustomSMTPServer() ([]SMTPServer, error) {

Expand Down
2 changes: 1 addition & 1 deletion smtp/smtp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestGetSMTPServer(t *testing.T) {

fakeEmailAddress0 := "[email protected]"
_, err := GetSMTPServer(fakeEmailAddress0)
if util.SMTPServerNotFoundErr != err {
if util.ErrSMTPServerNotFound != err {
t.Error("@example.net SMTP Server exists")
}

Expand Down
2 changes: 1 addition & 1 deletion statik/statik.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions util/boltStore.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var (
ContactsBucketName = []byte("contacts")
SmtpBucketName = []byte("smtp")
testBucketName = []byte("test")
KeyNotFoundErr = errors.New("Key Not Found")
ErrKeyNotFound = errors.New("key not found")
)

type BoltStore struct {
Expand Down Expand Up @@ -111,7 +111,7 @@ func (b *BoltStore) Get(k, bucketName []byte) ([]byte, error) {
val := bucket.Get(k)

if val == nil {
return nil, KeyNotFoundErr
return nil, ErrKeyNotFound
}

return append([]byte{}, val...), nil
Expand Down
11 changes: 6 additions & 5 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package util

import (
"errors"
"io/ioutil"
"io"
"os"
"path/filepath"

Expand All @@ -27,7 +27,7 @@ var (
}
DBPath string
DefaultLang = "en"
SMTPServerNotFoundErr = errors.New("SMTP Server Not Found")
ErrSMTPServerNotFound = errors.New("SMTP server not found")
)

func init() {
Expand All @@ -49,7 +49,7 @@ func init() {
type Msg struct {
Success bool `json:"success"`
Message string `json:"message"`
Data interface{} `json:"data,emitempty"`
Data interface{} `json:"data,omitempty"`
}

func GetHomeDir() string {
Expand Down Expand Up @@ -115,11 +115,12 @@ func GetContentFromStatik(name string) (string, error) {
}

hf, err := staticFS.Open(name)
defer hf.Close()
if err != nil {
return "", err
}
content, err := ioutil.ReadAll(hf)
defer hf.Close()

content, err := io.ReadAll(hf)
if err != nil {
return "", err
}
Expand Down

0 comments on commit ff869f5

Please sign in to comment.