Skip to content

Commit

Permalink
移除“zap” & 不允许包含“作者”
Browse files Browse the repository at this point in the history
  • Loading branch information
movsb committed Mar 9, 2024
1 parent ce6c432 commit 0efa0a4
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 34 deletions.
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require (
github.com/spf13/cobra v1.0.0
github.com/xeonx/timeago v1.0.0-rc4
github.com/yuin/goldmark v1.6.0
go.uber.org/zap v1.10.0
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1
google.golang.org/grpc v1.56.3
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.2.0
Expand Down Expand Up @@ -50,8 +49,6 @@ require (
github.com/prometheus/common v0.26.0 // indirect
github.com/prometheus/procfs v0.6.0 // indirect
github.com/spf13/pflag v1.0.3 // indirect
go.uber.org/atomic v1.4.0 // indirect
go.uber.org/multierr v1.1.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFSt
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down Expand Up @@ -246,11 +245,8 @@ github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:
github.com/yuin/goldmark v1.6.0 h1:boZcn2GTjpsynOsC0iJHnBWa4Bi0qzfJjthwauItG68=
github.com/yuin/goldmark v1.6.0/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.uber.org/atomic v1.4.0 h1:cxzIVoETapQEqDhQu3QfnvXAV4AlzcvUCxkVUFw3+EU=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.10.0 h1:ORx85nbTijNz8ljznvCMR1ZBIPKFn3jQrag10X2AsuM=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down
5 changes: 0 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ import (
"github.com/movsb/taoblog/modules/version"
_ "github.com/movsb/taoblog/setup/tool-deps"
"github.com/spf13/cobra"
"go.uber.org/zap"
)

func main() {
logger, _ := zap.NewDevelopment()
defer logger.Sync()
zap.ReplaceGlobals(logger)

rootCmd := &cobra.Command{
Use: filepath.Base(os.Args[0]),
Short: `TaoBlog client & server program.`,
Expand Down
9 changes: 0 additions & 9 deletions modules/utils/log.go

This file was deleted.

9 changes: 4 additions & 5 deletions service/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/mattn/go-sqlite3"
"github.com/movsb/taoblog/modules/utils"
"github.com/movsb/taoblog/protocols"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
Expand Down Expand Up @@ -73,14 +72,14 @@ func (s *Service) Backup(req *protocols.BackupRequest, srv protocols.Management_
}
n, err := io.Copy(w, rcs)
if err != nil {
zap.S().Errorw(`compress failed`, `err`, err)
log.Println(`compress failed:`, err)
panic(`compress failed`)
}
if err := w.Close(); err != nil {
zap.S().Errorw(`close failed`, `err`, err)
log.Println(`close failed:`, err)
panic(`close failed`)
}
zap.S().Infow(`compress completed`, `before`, n, `after`, buf.Len())
log.Printf(`compress completed: before: %v, after: %v`, n, buf.Len())
rcs.ReadCloser = ioutil.NopCloser(buf)
rcs.Size = func() int {
return buf.Len()
Expand Down Expand Up @@ -211,7 +210,7 @@ func (s *Service) backupSQLite3(ctx context.Context, progress func(percentage fl
return ``, err
}

zap.L().Info(`backed up to file`, zap.String(`path`, tmpFile.Name()))
log.Printf(`backed up to file: path: %s`, tmpFile.Name())

return tmpFile.Name(), nil
}
Expand Down
10 changes: 4 additions & 6 deletions service/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/yuin/goldmark/extension"
"github.com/yuin/goldmark/renderer/html"
"github.com/yuin/goldmark/text"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -264,6 +263,9 @@ func (s *Service) CreateComment(ctx context.Context, in *protocols.Comment) (*pr
panic(exception.NewValidationError("不能使用此昵称"))
}
}
if in.Author != "" && strings.Contains(in.Author, "作者") {
panic(exception.NewValidationError("昵称中不应包含“作者”两字"))
}
}

s.MustTxCall(func(txs *Service) error {
Expand Down Expand Up @@ -362,11 +364,7 @@ func (s *Service) isAdminEmail(email string) bool {

func (s *Service) doCommentNotification(c *models.Comment) {
if !s.cfg.Comment.Notify {
zap.S().Infow(
`comment notification is disabled`,
`comment_id`, c.ID,
`post_id`, c.PostID,
)
log.Printf(`comment notification is disabled. comment_id: %v, post_id: %v`, c.ID, c.PostID)
return
}

Expand Down
3 changes: 1 addition & 2 deletions theme/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/movsb/taoblog/theme/modules/rss"
"github.com/movsb/taoblog/theme/modules/sitemap"
"github.com/movsb/taoblog/theme/modules/watcher"
"go.uber.org/zap"
)

// Theme ...
Expand Down Expand Up @@ -209,7 +208,7 @@ func (t *Theme) Exception(w http.ResponseWriter, req *http.Request, e interface{
if t.redir != nil {
target, err := t.redir.FindRedirect(req.URL.Path)
if err != nil {
zap.L().Error(`FindRedirect failed`, zap.Error(err))
log.Println(`FindRedirect failed. `, err)
// fallthrough
}
if target != `` {
Expand Down

0 comments on commit 0efa0a4

Please sign in to comment.