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

Fixed some small typos and corrected a filepath in the documentation #21322

Merged
merged 3 commits into from
Oct 7, 2022
Merged
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
32 changes: 14 additions & 18 deletions docs/content/doc/developers/guidelines-backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,18 @@ Some actions should allow for rollback when database record insertion/update/del
So services must be allowed to create a database transaction. Here is some example,

```go
// servcies/repository/repo.go
func CreateXXXX() error {\
ctx, committer, err := db.TxContext()
if err != nil {
return err
}
defer committer.Close()

// do something, if return err, it will rollback automatically when `committer.Close()` is invoked.
if err := issues.UpdateIssue(ctx, repoID); err != nil {
// ...
}

// ......

return committer.Commit()
// services/repository/repository.go
func CreateXXXX() error {
return db.WithTx(func(ctx context.Context) error {
e := db.GetEngine(ctx)
// do something, if err is returned, it will rollback automatically
if err := issues.UpdateIssue(ctx, repoID); err != nil {
// ...
return err
}
// ...
return nil
})
}
```

Expand All @@ -94,14 +90,14 @@ If the function will be used in the transaction, just let `context.Context` as t
func UpdateIssue(ctx context.Context, repoID int64) error {
e := db.GetEngine(ctx)

// ......
// ...
}
```

### Package Name

For the top level package, use a plural as package name, i.e. `services`, `models`, for sub packages, use singular,
i.e. `servcies/user`, `models/repository`.
i.e. `services/user`, `models/repository`.

### Import Alias

Expand Down