Skip to content

Commit 40ae095

Browse files
committed
rename Iif to Ternary
1 parent 18bd700 commit 40ae095

File tree

35 files changed

+52
-52
lines changed

35 files changed

+52
-52
lines changed

cmd/dump.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ func runDump(ctx *cli.Context) error {
132132
defer outFile.Close()
133133
}
134134

135-
setupConsoleLogger(util.Iif(quite, log.WARN, log.INFO), log.CanColorStderr, os.Stderr)
135+
setupConsoleLogger(util.Ternary(quite, log.WARN, log.INFO), log.CanColorStderr, os.Stderr)
136136

137137
setting.DisableLoggerInit()
138138
setting.LoadSettings() // cannot access session settings otherwise

cmd/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func serveInstalled(ctx *cli.Context) error {
220220
}
221221
}
222222

223-
gtprof.EnableBuiltinTracer(util.Iif(setting.IsProd, 2000*time.Millisecond, 100*time.Millisecond))
223+
gtprof.EnableBuiltinTracer(util.Ternary(setting.IsProd, 2000*time.Millisecond, 100*time.Millisecond))
224224

225225
// Set up Chi routes
226226
webRoutes := routers.NormalRoutes()

models/asymkey/ssh_key_fingerprint.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,13 @@ func calcFingerprintNative(publicKeyContent string) (string, error) {
7777
func CalcFingerprint(publicKeyContent string) (string, error) {
7878
// Call the method based on configuration
7979
useNative := setting.SSH.KeygenPath == ""
80-
calcFn := util.Iif(useNative, calcFingerprintNative, calcFingerprintSSHKeygen)
80+
calcFn := util.Ternary(useNative, calcFingerprintNative, calcFingerprintSSHKeygen)
8181
fp, err := calcFn(publicKeyContent)
8282
if err != nil {
8383
if IsErrKeyUnableVerify(err) {
8484
return "", err
8585
}
86-
return "", fmt.Errorf("CalcFingerprint(%s): %w", util.Iif(useNative, "native", "ssh-keygen"), err)
86+
return "", fmt.Errorf("CalcFingerprint(%s): %w", util.Ternary(useNative, "native", "ssh-keygen"), err)
8787
}
8888
return fp, nil
8989
}

models/issues/issue_project.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func IssueAssignOrRemoveProject(ctx context.Context, issue *Issue, doer *user_mo
155155
Get(&res); err != nil {
156156
return err
157157
}
158-
newSorting := util.Iif(res.IssueCount > 0, res.MaxSorting+1, 0)
158+
newSorting := util.Ternary(res.IssueCount > 0, res.MaxSorting+1, 0)
159159
return db.Insert(ctx, &project_model.ProjectIssue{
160160
IssueID: issue.ID,
161161
ProjectID: newProjectID,

models/issues/issue_update.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func IsErrIssueIsClosed(err error) bool {
4747
}
4848

4949
func (err ErrIssueIsClosed) Error() string {
50-
return fmt.Sprintf("%s [id: %d, repo_id: %d, index: %d] is already closed", util.Iif(err.IsPull, "Pull Request", "Issue"), err.ID, err.RepoID, err.Index)
50+
return fmt.Sprintf("%s [id: %d, repo_id: %d, index: %d] is already closed", util.Ternary(err.IsPull, "Pull Request", "Issue"), err.ID, err.RepoID, err.Index)
5151
}
5252

5353
func SetIssueAsClosed(ctx context.Context, issue *Issue, doer *user_model.User, isMergePull bool) (*Comment, error) {
@@ -84,7 +84,7 @@ func SetIssueAsClosed(ctx context.Context, issue *Issue, doer *user_model.User,
8484
return nil, ErrIssueAlreadyChanged
8585
}
8686

87-
return updateIssueNumbers(ctx, issue, doer, util.Iif(isMergePull, CommentTypeMergePull, CommentTypeClose))
87+
return updateIssueNumbers(ctx, issue, doer, util.Ternary(isMergePull, CommentTypeMergePull, CommentTypeClose))
8888
}
8989

9090
// ErrIssueIsOpen is used when reopen an opened issue
@@ -102,7 +102,7 @@ func IsErrIssueIsOpen(err error) bool {
102102
}
103103

104104
func (err ErrIssueIsOpen) Error() string {
105-
return fmt.Sprintf("%s [id: %d, repo_id: %d, index: %d] is already open", util.Iif(err.IsPull, "Pull Request", "Issue"), err.ID, err.RepoID, err.Index)
105+
return fmt.Sprintf("%s [id: %d, repo_id: %d, index: %d] is already open", util.Ternary(err.IsPull, "Pull Request", "Issue"), err.ID, err.RepoID, err.Index)
106106
}
107107

108108
func setIssueAsReopen(ctx context.Context, issue *Issue, doer *user_model.User) (*Comment, error) {

models/perm/access/repo_permission.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ func (p *Permission) GetFirstUnitRepoID() int64 {
7777
func (p *Permission) UnitAccessMode(unitType unit.Type) perm_model.AccessMode {
7878
// if the units map contains the access mode, use it, but admin/owner mode could override it
7979
if m, ok := p.unitsMode[unitType]; ok {
80-
return util.Iif(p.AccessMode >= perm_model.AccessModeAdmin, p.AccessMode, m)
80+
return util.Ternary(p.AccessMode >= perm_model.AccessModeAdmin, p.AccessMode, m)
8181
}
8282
// if the units map does not contain the access mode, return the default access mode if the unit exists
8383
unitDefaultAccessMode := max(p.AccessMode, p.everyoneAccessMode[unitType])
8484
hasUnit := slices.ContainsFunc(p.units, func(u *repo_model.RepoUnit) bool { return u.Type == unitType })
85-
return util.Iif(hasUnit, unitDefaultAccessMode, perm_model.AccessModeNone)
85+
return util.Ternary(hasUnit, unitDefaultAccessMode, perm_model.AccessModeNone)
8686
}
8787

8888
func (p *Permission) SetUnitsWithDefaultAccessMode(units []*repo_model.RepoUnit, mode perm_model.AccessMode) {

models/perm/access_mode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func ParseAccessMode(permission string, allowed ...AccessMode) AccessMode {
5858
if len(allowed) == 0 {
5959
return m
6060
}
61-
return util.Iif(slices.Contains(allowed, m), m, AccessModeNone)
61+
return util.Ternary(slices.Contains(allowed, m), m, AccessModeNone)
6262
}
6363

6464
// ErrInvalidAccessMode is returned when an invalid access mode is used

models/project/column.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ func NewColumn(ctx context.Context, column *Column) error {
149149
if res.ColumnCount >= maxProjectColumns {
150150
return fmt.Errorf("NewBoard: maximum number of columns reached")
151151
}
152-
column.Sorting = int8(util.Iif(res.ColumnCount > 0, res.MaxSorting+1, 0))
152+
column.Sorting = int8(util.Ternary(res.ColumnCount > 0, res.MaxSorting+1, 0))
153153
_, err := db.GetEngine(ctx).Insert(column)
154154
return err
155155
}

models/project/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (c *Column) moveIssuesToAnotherColumn(ctx context.Context, newColumn *Colum
6262
return nil
6363
}
6464

65-
nextSorting := util.Iif(res.IssueCount > 0, res.MaxSorting+1, 0)
65+
nextSorting := util.Ternary(res.IssueCount > 0, res.MaxSorting+1, 0)
6666
return db.WithTx(ctx, func(ctx context.Context) error {
6767
for i, issue := range issues {
6868
issue.ProjectColumnID = newColumn.ID

modules/httpcache/httpcache.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func SetCacheControlInHeader(h http.Header, opts *CacheControlOptions) {
2626

2727
// "max-age=0 + must-revalidate" (aka "no-cache") is preferred instead of "no-store"
2828
// because browsers may restore some input fields after navigate-back / reload a page.
29-
publicPrivate := util.Iif(opts.IsPublic, "public", "private")
29+
publicPrivate := util.Ternary(opts.IsPublic, "public", "private")
3030
if setting.IsProd {
3131
if opts.MaxAge == 0 {
3232
directives = append(directives, "max-age=0", "private", "must-revalidate")

0 commit comments

Comments
 (0)