Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
2fe8932c
"backend/vscode:/vscode.git/clone" did not exist on "eeb1282f0cbcb7519a30f7f036d351791cb32d47"
Unverified
Commit
2fe8932c
authored
Feb 03, 2026
by
Call White
Committed by
GitHub
Feb 03, 2026
Browse files
Merge pull request #3 from cyhhao/main
merge to main
parents
2f2e76f9
adb77af1
Changes
267
Hide whitespace changes
Inline
Side-by-side
backend/ent/tx.go
View file @
2fe8932c
...
...
@@ -32,6 +32,8 @@ type Tx struct {
RedeemCode
*
RedeemCodeClient
// Setting is the client for interacting with the Setting builders.
Setting
*
SettingClient
// UsageCleanupTask is the client for interacting with the UsageCleanupTask builders.
UsageCleanupTask
*
UsageCleanupTaskClient
// UsageLog is the client for interacting with the UsageLog builders.
UsageLog
*
UsageLogClient
// User is the client for interacting with the User builders.
...
...
@@ -184,6 +186,7 @@ func (tx *Tx) init() {
tx
.
Proxy
=
NewProxyClient
(
tx
.
config
)
tx
.
RedeemCode
=
NewRedeemCodeClient
(
tx
.
config
)
tx
.
Setting
=
NewSettingClient
(
tx
.
config
)
tx
.
UsageCleanupTask
=
NewUsageCleanupTaskClient
(
tx
.
config
)
tx
.
UsageLog
=
NewUsageLogClient
(
tx
.
config
)
tx
.
User
=
NewUserClient
(
tx
.
config
)
tx
.
UserAllowedGroup
=
NewUserAllowedGroupClient
(
tx
.
config
)
...
...
backend/ent/usagecleanuptask.go
0 → 100644
View file @
2fe8932c
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"encoding/json"
"fmt"
"strings"
"time"
"entgo.io/ent"
"entgo.io/ent/dialect/sql"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
)
// UsageCleanupTask is the model entity for the UsageCleanupTask schema.
type
UsageCleanupTask
struct
{
config
`json:"-"`
// ID of the ent.
ID
int64
`json:"id,omitempty"`
// CreatedAt holds the value of the "created_at" field.
CreatedAt
time
.
Time
`json:"created_at,omitempty"`
// UpdatedAt holds the value of the "updated_at" field.
UpdatedAt
time
.
Time
`json:"updated_at,omitempty"`
// Status holds the value of the "status" field.
Status
string
`json:"status,omitempty"`
// Filters holds the value of the "filters" field.
Filters
json
.
RawMessage
`json:"filters,omitempty"`
// CreatedBy holds the value of the "created_by" field.
CreatedBy
int64
`json:"created_by,omitempty"`
// DeletedRows holds the value of the "deleted_rows" field.
DeletedRows
int64
`json:"deleted_rows,omitempty"`
// ErrorMessage holds the value of the "error_message" field.
ErrorMessage
*
string
`json:"error_message,omitempty"`
// CanceledBy holds the value of the "canceled_by" field.
CanceledBy
*
int64
`json:"canceled_by,omitempty"`
// CanceledAt holds the value of the "canceled_at" field.
CanceledAt
*
time
.
Time
`json:"canceled_at,omitempty"`
// StartedAt holds the value of the "started_at" field.
StartedAt
*
time
.
Time
`json:"started_at,omitempty"`
// FinishedAt holds the value of the "finished_at" field.
FinishedAt
*
time
.
Time
`json:"finished_at,omitempty"`
selectValues
sql
.
SelectValues
}
// scanValues returns the types for scanning values from sql.Rows.
func
(
*
UsageCleanupTask
)
scanValues
(
columns
[]
string
)
([]
any
,
error
)
{
values
:=
make
([]
any
,
len
(
columns
))
for
i
:=
range
columns
{
switch
columns
[
i
]
{
case
usagecleanuptask
.
FieldFilters
:
values
[
i
]
=
new
([]
byte
)
case
usagecleanuptask
.
FieldID
,
usagecleanuptask
.
FieldCreatedBy
,
usagecleanuptask
.
FieldDeletedRows
,
usagecleanuptask
.
FieldCanceledBy
:
values
[
i
]
=
new
(
sql
.
NullInt64
)
case
usagecleanuptask
.
FieldStatus
,
usagecleanuptask
.
FieldErrorMessage
:
values
[
i
]
=
new
(
sql
.
NullString
)
case
usagecleanuptask
.
FieldCreatedAt
,
usagecleanuptask
.
FieldUpdatedAt
,
usagecleanuptask
.
FieldCanceledAt
,
usagecleanuptask
.
FieldStartedAt
,
usagecleanuptask
.
FieldFinishedAt
:
values
[
i
]
=
new
(
sql
.
NullTime
)
default
:
values
[
i
]
=
new
(
sql
.
UnknownType
)
}
}
return
values
,
nil
}
// assignValues assigns the values that were returned from sql.Rows (after scanning)
// to the UsageCleanupTask fields.
func
(
_m
*
UsageCleanupTask
)
assignValues
(
columns
[]
string
,
values
[]
any
)
error
{
if
m
,
n
:=
len
(
values
),
len
(
columns
);
m
<
n
{
return
fmt
.
Errorf
(
"mismatch number of scan values: %d != %d"
,
m
,
n
)
}
for
i
:=
range
columns
{
switch
columns
[
i
]
{
case
usagecleanuptask
.
FieldID
:
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
)
if
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field id"
,
value
)
}
_m
.
ID
=
int64
(
value
.
Int64
)
case
usagecleanuptask
.
FieldCreatedAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field created_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
CreatedAt
=
value
.
Time
}
case
usagecleanuptask
.
FieldUpdatedAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field updated_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
UpdatedAt
=
value
.
Time
}
case
usagecleanuptask
.
FieldStatus
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullString
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field status"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
Status
=
value
.
String
}
case
usagecleanuptask
.
FieldFilters
:
if
value
,
ok
:=
values
[
i
]
.
(
*
[]
byte
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field filters"
,
values
[
i
])
}
else
if
value
!=
nil
&&
len
(
*
value
)
>
0
{
if
err
:=
json
.
Unmarshal
(
*
value
,
&
_m
.
Filters
);
err
!=
nil
{
return
fmt
.
Errorf
(
"unmarshal field filters: %w"
,
err
)
}
}
case
usagecleanuptask
.
FieldCreatedBy
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field created_by"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
CreatedBy
=
value
.
Int64
}
case
usagecleanuptask
.
FieldDeletedRows
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field deleted_rows"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
DeletedRows
=
value
.
Int64
}
case
usagecleanuptask
.
FieldErrorMessage
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullString
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field error_message"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
ErrorMessage
=
new
(
string
)
*
_m
.
ErrorMessage
=
value
.
String
}
case
usagecleanuptask
.
FieldCanceledBy
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullInt64
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field canceled_by"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
CanceledBy
=
new
(
int64
)
*
_m
.
CanceledBy
=
value
.
Int64
}
case
usagecleanuptask
.
FieldCanceledAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field canceled_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
CanceledAt
=
new
(
time
.
Time
)
*
_m
.
CanceledAt
=
value
.
Time
}
case
usagecleanuptask
.
FieldStartedAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field started_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
StartedAt
=
new
(
time
.
Time
)
*
_m
.
StartedAt
=
value
.
Time
}
case
usagecleanuptask
.
FieldFinishedAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field finished_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
FinishedAt
=
new
(
time
.
Time
)
*
_m
.
FinishedAt
=
value
.
Time
}
default
:
_m
.
selectValues
.
Set
(
columns
[
i
],
values
[
i
])
}
}
return
nil
}
// Value returns the ent.Value that was dynamically selected and assigned to the UsageCleanupTask.
// This includes values selected through modifiers, order, etc.
func
(
_m
*
UsageCleanupTask
)
Value
(
name
string
)
(
ent
.
Value
,
error
)
{
return
_m
.
selectValues
.
Get
(
name
)
}
// Update returns a builder for updating this UsageCleanupTask.
// Note that you need to call UsageCleanupTask.Unwrap() before calling this method if this UsageCleanupTask
// was returned from a transaction, and the transaction was committed or rolled back.
func
(
_m
*
UsageCleanupTask
)
Update
()
*
UsageCleanupTaskUpdateOne
{
return
NewUsageCleanupTaskClient
(
_m
.
config
)
.
UpdateOne
(
_m
)
}
// Unwrap unwraps the UsageCleanupTask entity that was returned from a transaction after it was closed,
// so that all future queries will be executed through the driver which created the transaction.
func
(
_m
*
UsageCleanupTask
)
Unwrap
()
*
UsageCleanupTask
{
_tx
,
ok
:=
_m
.
config
.
driver
.
(
*
txDriver
)
if
!
ok
{
panic
(
"ent: UsageCleanupTask is not a transactional entity"
)
}
_m
.
config
.
driver
=
_tx
.
drv
return
_m
}
// String implements the fmt.Stringer.
func
(
_m
*
UsageCleanupTask
)
String
()
string
{
var
builder
strings
.
Builder
builder
.
WriteString
(
"UsageCleanupTask("
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"id=%v, "
,
_m
.
ID
))
builder
.
WriteString
(
"created_at="
)
builder
.
WriteString
(
_m
.
CreatedAt
.
Format
(
time
.
ANSIC
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"updated_at="
)
builder
.
WriteString
(
_m
.
UpdatedAt
.
Format
(
time
.
ANSIC
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"status="
)
builder
.
WriteString
(
_m
.
Status
)
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"filters="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
Filters
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"created_by="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
CreatedBy
))
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"deleted_rows="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
DeletedRows
))
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
ErrorMessage
;
v
!=
nil
{
builder
.
WriteString
(
"error_message="
)
builder
.
WriteString
(
*
v
)
}
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
CanceledBy
;
v
!=
nil
{
builder
.
WriteString
(
"canceled_by="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
*
v
))
}
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
CanceledAt
;
v
!=
nil
{
builder
.
WriteString
(
"canceled_at="
)
builder
.
WriteString
(
v
.
Format
(
time
.
ANSIC
))
}
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
StartedAt
;
v
!=
nil
{
builder
.
WriteString
(
"started_at="
)
builder
.
WriteString
(
v
.
Format
(
time
.
ANSIC
))
}
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
FinishedAt
;
v
!=
nil
{
builder
.
WriteString
(
"finished_at="
)
builder
.
WriteString
(
v
.
Format
(
time
.
ANSIC
))
}
builder
.
WriteByte
(
')'
)
return
builder
.
String
()
}
// UsageCleanupTasks is a parsable slice of UsageCleanupTask.
type
UsageCleanupTasks
[]
*
UsageCleanupTask
backend/ent/usagecleanuptask/usagecleanuptask.go
0 → 100644
View file @
2fe8932c
// Code generated by ent, DO NOT EDIT.
package
usagecleanuptask
import
(
"time"
"entgo.io/ent/dialect/sql"
)
const
(
// Label holds the string label denoting the usagecleanuptask type in the database.
Label
=
"usage_cleanup_task"
// FieldID holds the string denoting the id field in the database.
FieldID
=
"id"
// FieldCreatedAt holds the string denoting the created_at field in the database.
FieldCreatedAt
=
"created_at"
// FieldUpdatedAt holds the string denoting the updated_at field in the database.
FieldUpdatedAt
=
"updated_at"
// FieldStatus holds the string denoting the status field in the database.
FieldStatus
=
"status"
// FieldFilters holds the string denoting the filters field in the database.
FieldFilters
=
"filters"
// FieldCreatedBy holds the string denoting the created_by field in the database.
FieldCreatedBy
=
"created_by"
// FieldDeletedRows holds the string denoting the deleted_rows field in the database.
FieldDeletedRows
=
"deleted_rows"
// FieldErrorMessage holds the string denoting the error_message field in the database.
FieldErrorMessage
=
"error_message"
// FieldCanceledBy holds the string denoting the canceled_by field in the database.
FieldCanceledBy
=
"canceled_by"
// FieldCanceledAt holds the string denoting the canceled_at field in the database.
FieldCanceledAt
=
"canceled_at"
// FieldStartedAt holds the string denoting the started_at field in the database.
FieldStartedAt
=
"started_at"
// FieldFinishedAt holds the string denoting the finished_at field in the database.
FieldFinishedAt
=
"finished_at"
// Table holds the table name of the usagecleanuptask in the database.
Table
=
"usage_cleanup_tasks"
)
// Columns holds all SQL columns for usagecleanuptask fields.
var
Columns
=
[]
string
{
FieldID
,
FieldCreatedAt
,
FieldUpdatedAt
,
FieldStatus
,
FieldFilters
,
FieldCreatedBy
,
FieldDeletedRows
,
FieldErrorMessage
,
FieldCanceledBy
,
FieldCanceledAt
,
FieldStartedAt
,
FieldFinishedAt
,
}
// ValidColumn reports if the column name is valid (part of the table columns).
func
ValidColumn
(
column
string
)
bool
{
for
i
:=
range
Columns
{
if
column
==
Columns
[
i
]
{
return
true
}
}
return
false
}
var
(
// DefaultCreatedAt holds the default value on creation for the "created_at" field.
DefaultCreatedAt
func
()
time
.
Time
// DefaultUpdatedAt holds the default value on creation for the "updated_at" field.
DefaultUpdatedAt
func
()
time
.
Time
// UpdateDefaultUpdatedAt holds the default value on update for the "updated_at" field.
UpdateDefaultUpdatedAt
func
()
time
.
Time
// StatusValidator is a validator for the "status" field. It is called by the builders before save.
StatusValidator
func
(
string
)
error
// DefaultDeletedRows holds the default value on creation for the "deleted_rows" field.
DefaultDeletedRows
int64
)
// OrderOption defines the ordering options for the UsageCleanupTask queries.
type
OrderOption
func
(
*
sql
.
Selector
)
// ByID orders the results by the id field.
func
ByID
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldID
,
opts
...
)
.
ToFunc
()
}
// ByCreatedAt orders the results by the created_at field.
func
ByCreatedAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldCreatedAt
,
opts
...
)
.
ToFunc
()
}
// ByUpdatedAt orders the results by the updated_at field.
func
ByUpdatedAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldUpdatedAt
,
opts
...
)
.
ToFunc
()
}
// ByStatus orders the results by the status field.
func
ByStatus
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldStatus
,
opts
...
)
.
ToFunc
()
}
// ByCreatedBy orders the results by the created_by field.
func
ByCreatedBy
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldCreatedBy
,
opts
...
)
.
ToFunc
()
}
// ByDeletedRows orders the results by the deleted_rows field.
func
ByDeletedRows
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldDeletedRows
,
opts
...
)
.
ToFunc
()
}
// ByErrorMessage orders the results by the error_message field.
func
ByErrorMessage
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldErrorMessage
,
opts
...
)
.
ToFunc
()
}
// ByCanceledBy orders the results by the canceled_by field.
func
ByCanceledBy
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldCanceledBy
,
opts
...
)
.
ToFunc
()
}
// ByCanceledAt orders the results by the canceled_at field.
func
ByCanceledAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldCanceledAt
,
opts
...
)
.
ToFunc
()
}
// ByStartedAt orders the results by the started_at field.
func
ByStartedAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldStartedAt
,
opts
...
)
.
ToFunc
()
}
// ByFinishedAt orders the results by the finished_at field.
func
ByFinishedAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldFinishedAt
,
opts
...
)
.
ToFunc
()
}
backend/ent/usagecleanuptask/where.go
0 → 100644
View file @
2fe8932c
// Code generated by ent, DO NOT EDIT.
package
usagecleanuptask
import
(
"time"
"entgo.io/ent/dialect/sql"
"github.com/Wei-Shaw/sub2api/ent/predicate"
)
// ID filters vertices based on their ID field.
func
ID
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldID
,
id
))
}
// IDEQ applies the EQ predicate on the ID field.
func
IDEQ
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldID
,
id
))
}
// IDNEQ applies the NEQ predicate on the ID field.
func
IDNEQ
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldID
,
id
))
}
// IDIn applies the In predicate on the ID field.
func
IDIn
(
ids
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldID
,
ids
...
))
}
// IDNotIn applies the NotIn predicate on the ID field.
func
IDNotIn
(
ids
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldID
,
ids
...
))
}
// IDGT applies the GT predicate on the ID field.
func
IDGT
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldID
,
id
))
}
// IDGTE applies the GTE predicate on the ID field.
func
IDGTE
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldID
,
id
))
}
// IDLT applies the LT predicate on the ID field.
func
IDLT
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldID
,
id
))
}
// IDLTE applies the LTE predicate on the ID field.
func
IDLTE
(
id
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldID
,
id
))
}
// CreatedAt applies equality check predicate on the "created_at" field. It's identical to CreatedAtEQ.
func
CreatedAt
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCreatedAt
,
v
))
}
// UpdatedAt applies equality check predicate on the "updated_at" field. It's identical to UpdatedAtEQ.
func
UpdatedAt
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldUpdatedAt
,
v
))
}
// Status applies equality check predicate on the "status" field. It's identical to StatusEQ.
func
Status
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldStatus
,
v
))
}
// CreatedBy applies equality check predicate on the "created_by" field. It's identical to CreatedByEQ.
func
CreatedBy
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCreatedBy
,
v
))
}
// DeletedRows applies equality check predicate on the "deleted_rows" field. It's identical to DeletedRowsEQ.
func
DeletedRows
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldDeletedRows
,
v
))
}
// ErrorMessage applies equality check predicate on the "error_message" field. It's identical to ErrorMessageEQ.
func
ErrorMessage
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldErrorMessage
,
v
))
}
// CanceledBy applies equality check predicate on the "canceled_by" field. It's identical to CanceledByEQ.
func
CanceledBy
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCanceledBy
,
v
))
}
// CanceledAt applies equality check predicate on the "canceled_at" field. It's identical to CanceledAtEQ.
func
CanceledAt
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCanceledAt
,
v
))
}
// StartedAt applies equality check predicate on the "started_at" field. It's identical to StartedAtEQ.
func
StartedAt
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldStartedAt
,
v
))
}
// FinishedAt applies equality check predicate on the "finished_at" field. It's identical to FinishedAtEQ.
func
FinishedAt
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldFinishedAt
,
v
))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func
CreatedAtEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCreatedAt
,
v
))
}
// CreatedAtNEQ applies the NEQ predicate on the "created_at" field.
func
CreatedAtNEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldCreatedAt
,
v
))
}
// CreatedAtIn applies the In predicate on the "created_at" field.
func
CreatedAtIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldCreatedAt
,
vs
...
))
}
// CreatedAtNotIn applies the NotIn predicate on the "created_at" field.
func
CreatedAtNotIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldCreatedAt
,
vs
...
))
}
// CreatedAtGT applies the GT predicate on the "created_at" field.
func
CreatedAtGT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldCreatedAt
,
v
))
}
// CreatedAtGTE applies the GTE predicate on the "created_at" field.
func
CreatedAtGTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldCreatedAt
,
v
))
}
// CreatedAtLT applies the LT predicate on the "created_at" field.
func
CreatedAtLT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldCreatedAt
,
v
))
}
// CreatedAtLTE applies the LTE predicate on the "created_at" field.
func
CreatedAtLTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldCreatedAt
,
v
))
}
// UpdatedAtEQ applies the EQ predicate on the "updated_at" field.
func
UpdatedAtEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtNEQ applies the NEQ predicate on the "updated_at" field.
func
UpdatedAtNEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtIn applies the In predicate on the "updated_at" field.
func
UpdatedAtIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldUpdatedAt
,
vs
...
))
}
// UpdatedAtNotIn applies the NotIn predicate on the "updated_at" field.
func
UpdatedAtNotIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldUpdatedAt
,
vs
...
))
}
// UpdatedAtGT applies the GT predicate on the "updated_at" field.
func
UpdatedAtGT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtGTE applies the GTE predicate on the "updated_at" field.
func
UpdatedAtGTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtLT applies the LT predicate on the "updated_at" field.
func
UpdatedAtLT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldUpdatedAt
,
v
))
}
// UpdatedAtLTE applies the LTE predicate on the "updated_at" field.
func
UpdatedAtLTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldUpdatedAt
,
v
))
}
// StatusEQ applies the EQ predicate on the "status" field.
func
StatusEQ
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldStatus
,
v
))
}
// StatusNEQ applies the NEQ predicate on the "status" field.
func
StatusNEQ
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldStatus
,
v
))
}
// StatusIn applies the In predicate on the "status" field.
func
StatusIn
(
vs
...
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldStatus
,
vs
...
))
}
// StatusNotIn applies the NotIn predicate on the "status" field.
func
StatusNotIn
(
vs
...
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldStatus
,
vs
...
))
}
// StatusGT applies the GT predicate on the "status" field.
func
StatusGT
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldStatus
,
v
))
}
// StatusGTE applies the GTE predicate on the "status" field.
func
StatusGTE
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldStatus
,
v
))
}
// StatusLT applies the LT predicate on the "status" field.
func
StatusLT
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldStatus
,
v
))
}
// StatusLTE applies the LTE predicate on the "status" field.
func
StatusLTE
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldStatus
,
v
))
}
// StatusContains applies the Contains predicate on the "status" field.
func
StatusContains
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldContains
(
FieldStatus
,
v
))
}
// StatusHasPrefix applies the HasPrefix predicate on the "status" field.
func
StatusHasPrefix
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldHasPrefix
(
FieldStatus
,
v
))
}
// StatusHasSuffix applies the HasSuffix predicate on the "status" field.
func
StatusHasSuffix
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldHasSuffix
(
FieldStatus
,
v
))
}
// StatusEqualFold applies the EqualFold predicate on the "status" field.
func
StatusEqualFold
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEqualFold
(
FieldStatus
,
v
))
}
// StatusContainsFold applies the ContainsFold predicate on the "status" field.
func
StatusContainsFold
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldContainsFold
(
FieldStatus
,
v
))
}
// CreatedByEQ applies the EQ predicate on the "created_by" field.
func
CreatedByEQ
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCreatedBy
,
v
))
}
// CreatedByNEQ applies the NEQ predicate on the "created_by" field.
func
CreatedByNEQ
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldCreatedBy
,
v
))
}
// CreatedByIn applies the In predicate on the "created_by" field.
func
CreatedByIn
(
vs
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldCreatedBy
,
vs
...
))
}
// CreatedByNotIn applies the NotIn predicate on the "created_by" field.
func
CreatedByNotIn
(
vs
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldCreatedBy
,
vs
...
))
}
// CreatedByGT applies the GT predicate on the "created_by" field.
func
CreatedByGT
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldCreatedBy
,
v
))
}
// CreatedByGTE applies the GTE predicate on the "created_by" field.
func
CreatedByGTE
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldCreatedBy
,
v
))
}
// CreatedByLT applies the LT predicate on the "created_by" field.
func
CreatedByLT
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldCreatedBy
,
v
))
}
// CreatedByLTE applies the LTE predicate on the "created_by" field.
func
CreatedByLTE
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldCreatedBy
,
v
))
}
// DeletedRowsEQ applies the EQ predicate on the "deleted_rows" field.
func
DeletedRowsEQ
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldDeletedRows
,
v
))
}
// DeletedRowsNEQ applies the NEQ predicate on the "deleted_rows" field.
func
DeletedRowsNEQ
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldDeletedRows
,
v
))
}
// DeletedRowsIn applies the In predicate on the "deleted_rows" field.
func
DeletedRowsIn
(
vs
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldDeletedRows
,
vs
...
))
}
// DeletedRowsNotIn applies the NotIn predicate on the "deleted_rows" field.
func
DeletedRowsNotIn
(
vs
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldDeletedRows
,
vs
...
))
}
// DeletedRowsGT applies the GT predicate on the "deleted_rows" field.
func
DeletedRowsGT
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldDeletedRows
,
v
))
}
// DeletedRowsGTE applies the GTE predicate on the "deleted_rows" field.
func
DeletedRowsGTE
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldDeletedRows
,
v
))
}
// DeletedRowsLT applies the LT predicate on the "deleted_rows" field.
func
DeletedRowsLT
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldDeletedRows
,
v
))
}
// DeletedRowsLTE applies the LTE predicate on the "deleted_rows" field.
func
DeletedRowsLTE
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldDeletedRows
,
v
))
}
// ErrorMessageEQ applies the EQ predicate on the "error_message" field.
func
ErrorMessageEQ
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldErrorMessage
,
v
))
}
// ErrorMessageNEQ applies the NEQ predicate on the "error_message" field.
func
ErrorMessageNEQ
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldErrorMessage
,
v
))
}
// ErrorMessageIn applies the In predicate on the "error_message" field.
func
ErrorMessageIn
(
vs
...
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldErrorMessage
,
vs
...
))
}
// ErrorMessageNotIn applies the NotIn predicate on the "error_message" field.
func
ErrorMessageNotIn
(
vs
...
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldErrorMessage
,
vs
...
))
}
// ErrorMessageGT applies the GT predicate on the "error_message" field.
func
ErrorMessageGT
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldErrorMessage
,
v
))
}
// ErrorMessageGTE applies the GTE predicate on the "error_message" field.
func
ErrorMessageGTE
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldErrorMessage
,
v
))
}
// ErrorMessageLT applies the LT predicate on the "error_message" field.
func
ErrorMessageLT
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldErrorMessage
,
v
))
}
// ErrorMessageLTE applies the LTE predicate on the "error_message" field.
func
ErrorMessageLTE
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldErrorMessage
,
v
))
}
// ErrorMessageContains applies the Contains predicate on the "error_message" field.
func
ErrorMessageContains
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldContains
(
FieldErrorMessage
,
v
))
}
// ErrorMessageHasPrefix applies the HasPrefix predicate on the "error_message" field.
func
ErrorMessageHasPrefix
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldHasPrefix
(
FieldErrorMessage
,
v
))
}
// ErrorMessageHasSuffix applies the HasSuffix predicate on the "error_message" field.
func
ErrorMessageHasSuffix
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldHasSuffix
(
FieldErrorMessage
,
v
))
}
// ErrorMessageIsNil applies the IsNil predicate on the "error_message" field.
func
ErrorMessageIsNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIsNull
(
FieldErrorMessage
))
}
// ErrorMessageNotNil applies the NotNil predicate on the "error_message" field.
func
ErrorMessageNotNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotNull
(
FieldErrorMessage
))
}
// ErrorMessageEqualFold applies the EqualFold predicate on the "error_message" field.
func
ErrorMessageEqualFold
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEqualFold
(
FieldErrorMessage
,
v
))
}
// ErrorMessageContainsFold applies the ContainsFold predicate on the "error_message" field.
func
ErrorMessageContainsFold
(
v
string
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldContainsFold
(
FieldErrorMessage
,
v
))
}
// CanceledByEQ applies the EQ predicate on the "canceled_by" field.
func
CanceledByEQ
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCanceledBy
,
v
))
}
// CanceledByNEQ applies the NEQ predicate on the "canceled_by" field.
func
CanceledByNEQ
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldCanceledBy
,
v
))
}
// CanceledByIn applies the In predicate on the "canceled_by" field.
func
CanceledByIn
(
vs
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldCanceledBy
,
vs
...
))
}
// CanceledByNotIn applies the NotIn predicate on the "canceled_by" field.
func
CanceledByNotIn
(
vs
...
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldCanceledBy
,
vs
...
))
}
// CanceledByGT applies the GT predicate on the "canceled_by" field.
func
CanceledByGT
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldCanceledBy
,
v
))
}
// CanceledByGTE applies the GTE predicate on the "canceled_by" field.
func
CanceledByGTE
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldCanceledBy
,
v
))
}
// CanceledByLT applies the LT predicate on the "canceled_by" field.
func
CanceledByLT
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldCanceledBy
,
v
))
}
// CanceledByLTE applies the LTE predicate on the "canceled_by" field.
func
CanceledByLTE
(
v
int64
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldCanceledBy
,
v
))
}
// CanceledByIsNil applies the IsNil predicate on the "canceled_by" field.
func
CanceledByIsNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIsNull
(
FieldCanceledBy
))
}
// CanceledByNotNil applies the NotNil predicate on the "canceled_by" field.
func
CanceledByNotNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotNull
(
FieldCanceledBy
))
}
// CanceledAtEQ applies the EQ predicate on the "canceled_at" field.
func
CanceledAtEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldCanceledAt
,
v
))
}
// CanceledAtNEQ applies the NEQ predicate on the "canceled_at" field.
func
CanceledAtNEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldCanceledAt
,
v
))
}
// CanceledAtIn applies the In predicate on the "canceled_at" field.
func
CanceledAtIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldCanceledAt
,
vs
...
))
}
// CanceledAtNotIn applies the NotIn predicate on the "canceled_at" field.
func
CanceledAtNotIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldCanceledAt
,
vs
...
))
}
// CanceledAtGT applies the GT predicate on the "canceled_at" field.
func
CanceledAtGT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldCanceledAt
,
v
))
}
// CanceledAtGTE applies the GTE predicate on the "canceled_at" field.
func
CanceledAtGTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldCanceledAt
,
v
))
}
// CanceledAtLT applies the LT predicate on the "canceled_at" field.
func
CanceledAtLT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldCanceledAt
,
v
))
}
// CanceledAtLTE applies the LTE predicate on the "canceled_at" field.
func
CanceledAtLTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldCanceledAt
,
v
))
}
// CanceledAtIsNil applies the IsNil predicate on the "canceled_at" field.
func
CanceledAtIsNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIsNull
(
FieldCanceledAt
))
}
// CanceledAtNotNil applies the NotNil predicate on the "canceled_at" field.
func
CanceledAtNotNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotNull
(
FieldCanceledAt
))
}
// StartedAtEQ applies the EQ predicate on the "started_at" field.
func
StartedAtEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldStartedAt
,
v
))
}
// StartedAtNEQ applies the NEQ predicate on the "started_at" field.
func
StartedAtNEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldStartedAt
,
v
))
}
// StartedAtIn applies the In predicate on the "started_at" field.
func
StartedAtIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldStartedAt
,
vs
...
))
}
// StartedAtNotIn applies the NotIn predicate on the "started_at" field.
func
StartedAtNotIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldStartedAt
,
vs
...
))
}
// StartedAtGT applies the GT predicate on the "started_at" field.
func
StartedAtGT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldStartedAt
,
v
))
}
// StartedAtGTE applies the GTE predicate on the "started_at" field.
func
StartedAtGTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldStartedAt
,
v
))
}
// StartedAtLT applies the LT predicate on the "started_at" field.
func
StartedAtLT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldStartedAt
,
v
))
}
// StartedAtLTE applies the LTE predicate on the "started_at" field.
func
StartedAtLTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldStartedAt
,
v
))
}
// StartedAtIsNil applies the IsNil predicate on the "started_at" field.
func
StartedAtIsNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIsNull
(
FieldStartedAt
))
}
// StartedAtNotNil applies the NotNil predicate on the "started_at" field.
func
StartedAtNotNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotNull
(
FieldStartedAt
))
}
// FinishedAtEQ applies the EQ predicate on the "finished_at" field.
func
FinishedAtEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldEQ
(
FieldFinishedAt
,
v
))
}
// FinishedAtNEQ applies the NEQ predicate on the "finished_at" field.
func
FinishedAtNEQ
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNEQ
(
FieldFinishedAt
,
v
))
}
// FinishedAtIn applies the In predicate on the "finished_at" field.
func
FinishedAtIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIn
(
FieldFinishedAt
,
vs
...
))
}
// FinishedAtNotIn applies the NotIn predicate on the "finished_at" field.
func
FinishedAtNotIn
(
vs
...
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotIn
(
FieldFinishedAt
,
vs
...
))
}
// FinishedAtGT applies the GT predicate on the "finished_at" field.
func
FinishedAtGT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGT
(
FieldFinishedAt
,
v
))
}
// FinishedAtGTE applies the GTE predicate on the "finished_at" field.
func
FinishedAtGTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldGTE
(
FieldFinishedAt
,
v
))
}
// FinishedAtLT applies the LT predicate on the "finished_at" field.
func
FinishedAtLT
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLT
(
FieldFinishedAt
,
v
))
}
// FinishedAtLTE applies the LTE predicate on the "finished_at" field.
func
FinishedAtLTE
(
v
time
.
Time
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldLTE
(
FieldFinishedAt
,
v
))
}
// FinishedAtIsNil applies the IsNil predicate on the "finished_at" field.
func
FinishedAtIsNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldIsNull
(
FieldFinishedAt
))
}
// FinishedAtNotNil applies the NotNil predicate on the "finished_at" field.
func
FinishedAtNotNil
()
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
FieldNotNull
(
FieldFinishedAt
))
}
// And groups predicates with the AND operator between them.
func
And
(
predicates
...
predicate
.
UsageCleanupTask
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
AndPredicates
(
predicates
...
))
}
// Or groups predicates with the OR operator between them.
func
Or
(
predicates
...
predicate
.
UsageCleanupTask
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
OrPredicates
(
predicates
...
))
}
// Not applies the not operator on the given predicate.
func
Not
(
p
predicate
.
UsageCleanupTask
)
predicate
.
UsageCleanupTask
{
return
predicate
.
UsageCleanupTask
(
sql
.
NotPredicates
(
p
))
}
backend/ent/usagecleanuptask_create.go
0 → 100644
View file @
2fe8932c
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"context"
"encoding/json"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
)
// UsageCleanupTaskCreate is the builder for creating a UsageCleanupTask entity.
type
UsageCleanupTaskCreate
struct
{
config
mutation
*
UsageCleanupTaskMutation
hooks
[]
Hook
conflict
[]
sql
.
ConflictOption
}
// SetCreatedAt sets the "created_at" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetCreatedAt
(
v
time
.
Time
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetCreatedAt
(
v
)
return
_c
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableCreatedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetCreatedAt
(
*
v
)
}
return
_c
}
// SetUpdatedAt sets the "updated_at" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetUpdatedAt
(
v
time
.
Time
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetUpdatedAt
(
v
)
return
_c
}
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableUpdatedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetUpdatedAt
(
*
v
)
}
return
_c
}
// SetStatus sets the "status" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetStatus
(
v
string
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetStatus
(
v
)
return
_c
}
// SetFilters sets the "filters" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetFilters
(
v
)
return
_c
}
// SetCreatedBy sets the "created_by" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetCreatedBy
(
v
int64
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetCreatedBy
(
v
)
return
_c
}
// SetDeletedRows sets the "deleted_rows" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetDeletedRows
(
v
int64
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetDeletedRows
(
v
)
return
_c
}
// SetNillableDeletedRows sets the "deleted_rows" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableDeletedRows
(
v
*
int64
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetDeletedRows
(
*
v
)
}
return
_c
}
// SetErrorMessage sets the "error_message" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetErrorMessage
(
v
string
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetErrorMessage
(
v
)
return
_c
}
// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableErrorMessage
(
v
*
string
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetErrorMessage
(
*
v
)
}
return
_c
}
// SetCanceledBy sets the "canceled_by" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetCanceledBy
(
v
int64
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetCanceledBy
(
v
)
return
_c
}
// SetNillableCanceledBy sets the "canceled_by" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableCanceledBy
(
v
*
int64
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetCanceledBy
(
*
v
)
}
return
_c
}
// SetCanceledAt sets the "canceled_at" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetCanceledAt
(
v
time
.
Time
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetCanceledAt
(
v
)
return
_c
}
// SetNillableCanceledAt sets the "canceled_at" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableCanceledAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetCanceledAt
(
*
v
)
}
return
_c
}
// SetStartedAt sets the "started_at" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetStartedAt
(
v
time
.
Time
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetStartedAt
(
v
)
return
_c
}
// SetNillableStartedAt sets the "started_at" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableStartedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetStartedAt
(
*
v
)
}
return
_c
}
// SetFinishedAt sets the "finished_at" field.
func
(
_c
*
UsageCleanupTaskCreate
)
SetFinishedAt
(
v
time
.
Time
)
*
UsageCleanupTaskCreate
{
_c
.
mutation
.
SetFinishedAt
(
v
)
return
_c
}
// SetNillableFinishedAt sets the "finished_at" field if the given value is not nil.
func
(
_c
*
UsageCleanupTaskCreate
)
SetNillableFinishedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskCreate
{
if
v
!=
nil
{
_c
.
SetFinishedAt
(
*
v
)
}
return
_c
}
// Mutation returns the UsageCleanupTaskMutation object of the builder.
func
(
_c
*
UsageCleanupTaskCreate
)
Mutation
()
*
UsageCleanupTaskMutation
{
return
_c
.
mutation
}
// Save creates the UsageCleanupTask in the database.
func
(
_c
*
UsageCleanupTaskCreate
)
Save
(
ctx
context
.
Context
)
(
*
UsageCleanupTask
,
error
)
{
_c
.
defaults
()
return
withHooks
(
ctx
,
_c
.
sqlSave
,
_c
.
mutation
,
_c
.
hooks
)
}
// SaveX calls Save and panics if Save returns an error.
func
(
_c
*
UsageCleanupTaskCreate
)
SaveX
(
ctx
context
.
Context
)
*
UsageCleanupTask
{
v
,
err
:=
_c
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
v
}
// Exec executes the query.
func
(
_c
*
UsageCleanupTaskCreate
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_c
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_c
*
UsageCleanupTaskCreate
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_c
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// defaults sets the default values of the builder before save.
func
(
_c
*
UsageCleanupTaskCreate
)
defaults
()
{
if
_
,
ok
:=
_c
.
mutation
.
CreatedAt
();
!
ok
{
v
:=
usagecleanuptask
.
DefaultCreatedAt
()
_c
.
mutation
.
SetCreatedAt
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
UpdatedAt
();
!
ok
{
v
:=
usagecleanuptask
.
DefaultUpdatedAt
()
_c
.
mutation
.
SetUpdatedAt
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
DeletedRows
();
!
ok
{
v
:=
usagecleanuptask
.
DefaultDeletedRows
_c
.
mutation
.
SetDeletedRows
(
v
)
}
}
// check runs all checks and user-defined validators on the builder.
func
(
_c
*
UsageCleanupTaskCreate
)
check
()
error
{
if
_
,
ok
:=
_c
.
mutation
.
CreatedAt
();
!
ok
{
return
&
ValidationError
{
Name
:
"created_at"
,
err
:
errors
.
New
(
`ent: missing required field "UsageCleanupTask.created_at"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
UpdatedAt
();
!
ok
{
return
&
ValidationError
{
Name
:
"updated_at"
,
err
:
errors
.
New
(
`ent: missing required field "UsageCleanupTask.updated_at"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
Status
();
!
ok
{
return
&
ValidationError
{
Name
:
"status"
,
err
:
errors
.
New
(
`ent: missing required field "UsageCleanupTask.status"`
)}
}
if
v
,
ok
:=
_c
.
mutation
.
Status
();
ok
{
if
err
:=
usagecleanuptask
.
StatusValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"status"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageCleanupTask.status": %w`
,
err
)}
}
}
if
_
,
ok
:=
_c
.
mutation
.
Filters
();
!
ok
{
return
&
ValidationError
{
Name
:
"filters"
,
err
:
errors
.
New
(
`ent: missing required field "UsageCleanupTask.filters"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
CreatedBy
();
!
ok
{
return
&
ValidationError
{
Name
:
"created_by"
,
err
:
errors
.
New
(
`ent: missing required field "UsageCleanupTask.created_by"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
DeletedRows
();
!
ok
{
return
&
ValidationError
{
Name
:
"deleted_rows"
,
err
:
errors
.
New
(
`ent: missing required field "UsageCleanupTask.deleted_rows"`
)}
}
return
nil
}
func
(
_c
*
UsageCleanupTaskCreate
)
sqlSave
(
ctx
context
.
Context
)
(
*
UsageCleanupTask
,
error
)
{
if
err
:=
_c
.
check
();
err
!=
nil
{
return
nil
,
err
}
_node
,
_spec
:=
_c
.
createSpec
()
if
err
:=
sqlgraph
.
CreateNode
(
ctx
,
_c
.
driver
,
_spec
);
err
!=
nil
{
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
return
nil
,
err
}
id
:=
_spec
.
ID
.
Value
.
(
int64
)
_node
.
ID
=
int64
(
id
)
_c
.
mutation
.
id
=
&
_node
.
ID
_c
.
mutation
.
done
=
true
return
_node
,
nil
}
func
(
_c
*
UsageCleanupTaskCreate
)
createSpec
()
(
*
UsageCleanupTask
,
*
sqlgraph
.
CreateSpec
)
{
var
(
_node
=
&
UsageCleanupTask
{
config
:
_c
.
config
}
_spec
=
sqlgraph
.
NewCreateSpec
(
usagecleanuptask
.
Table
,
sqlgraph
.
NewFieldSpec
(
usagecleanuptask
.
FieldID
,
field
.
TypeInt64
))
)
_spec
.
OnConflict
=
_c
.
conflict
if
value
,
ok
:=
_c
.
mutation
.
CreatedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCreatedAt
,
field
.
TypeTime
,
value
)
_node
.
CreatedAt
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
UpdatedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldUpdatedAt
,
field
.
TypeTime
,
value
)
_node
.
UpdatedAt
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
Status
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldStatus
,
field
.
TypeString
,
value
)
_node
.
Status
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
Filters
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldFilters
,
field
.
TypeJSON
,
value
)
_node
.
Filters
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
CreatedBy
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCreatedBy
,
field
.
TypeInt64
,
value
)
_node
.
CreatedBy
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
DeletedRows
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldDeletedRows
,
field
.
TypeInt64
,
value
)
_node
.
DeletedRows
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
ErrorMessage
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldErrorMessage
,
field
.
TypeString
,
value
)
_node
.
ErrorMessage
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
CanceledBy
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCanceledBy
,
field
.
TypeInt64
,
value
)
_node
.
CanceledBy
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
CanceledAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCanceledAt
,
field
.
TypeTime
,
value
)
_node
.
CanceledAt
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
StartedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldStartedAt
,
field
.
TypeTime
,
value
)
_node
.
StartedAt
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
FinishedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldFinishedAt
,
field
.
TypeTime
,
value
)
_node
.
FinishedAt
=
&
value
}
return
_node
,
_spec
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.UsageCleanupTask.Create().
// SetCreatedAt(v).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.UsageCleanupTaskUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func
(
_c
*
UsageCleanupTaskCreate
)
OnConflict
(
opts
...
sql
.
ConflictOption
)
*
UsageCleanupTaskUpsertOne
{
_c
.
conflict
=
opts
return
&
UsageCleanupTaskUpsertOne
{
create
:
_c
,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.UsageCleanupTask.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func
(
_c
*
UsageCleanupTaskCreate
)
OnConflictColumns
(
columns
...
string
)
*
UsageCleanupTaskUpsertOne
{
_c
.
conflict
=
append
(
_c
.
conflict
,
sql
.
ConflictColumns
(
columns
...
))
return
&
UsageCleanupTaskUpsertOne
{
create
:
_c
,
}
}
type
(
// UsageCleanupTaskUpsertOne is the builder for "upsert"-ing
// one UsageCleanupTask node.
UsageCleanupTaskUpsertOne
struct
{
create
*
UsageCleanupTaskCreate
}
// UsageCleanupTaskUpsert is the "OnConflict" setter.
UsageCleanupTaskUpsert
struct
{
*
sql
.
UpdateSet
}
)
// SetUpdatedAt sets the "updated_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetUpdatedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldUpdatedAt
,
v
)
return
u
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateUpdatedAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldUpdatedAt
)
return
u
}
// SetStatus sets the "status" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetStatus
(
v
string
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldStatus
,
v
)
return
u
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateStatus
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldStatus
)
return
u
}
// SetFilters sets the "filters" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldFilters
,
v
)
return
u
}
// UpdateFilters sets the "filters" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateFilters
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldFilters
)
return
u
}
// SetCreatedBy sets the "created_by" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldCreatedBy
,
v
)
return
u
}
// UpdateCreatedBy sets the "created_by" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateCreatedBy
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldCreatedBy
)
return
u
}
// AddCreatedBy adds v to the "created_by" field.
func
(
u
*
UsageCleanupTaskUpsert
)
AddCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpsert
{
u
.
Add
(
usagecleanuptask
.
FieldCreatedBy
,
v
)
return
u
}
// SetDeletedRows sets the "deleted_rows" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldDeletedRows
,
v
)
return
u
}
// UpdateDeletedRows sets the "deleted_rows" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateDeletedRows
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldDeletedRows
)
return
u
}
// AddDeletedRows adds v to the "deleted_rows" field.
func
(
u
*
UsageCleanupTaskUpsert
)
AddDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpsert
{
u
.
Add
(
usagecleanuptask
.
FieldDeletedRows
,
v
)
return
u
}
// SetErrorMessage sets the "error_message" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetErrorMessage
(
v
string
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldErrorMessage
,
v
)
return
u
}
// UpdateErrorMessage sets the "error_message" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateErrorMessage
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldErrorMessage
)
return
u
}
// ClearErrorMessage clears the value of the "error_message" field.
func
(
u
*
UsageCleanupTaskUpsert
)
ClearErrorMessage
()
*
UsageCleanupTaskUpsert
{
u
.
SetNull
(
usagecleanuptask
.
FieldErrorMessage
)
return
u
}
// SetCanceledBy sets the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldCanceledBy
,
v
)
return
u
}
// UpdateCanceledBy sets the "canceled_by" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateCanceledBy
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldCanceledBy
)
return
u
}
// AddCanceledBy adds v to the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsert
)
AddCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpsert
{
u
.
Add
(
usagecleanuptask
.
FieldCanceledBy
,
v
)
return
u
}
// ClearCanceledBy clears the value of the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsert
)
ClearCanceledBy
()
*
UsageCleanupTaskUpsert
{
u
.
SetNull
(
usagecleanuptask
.
FieldCanceledBy
)
return
u
}
// SetCanceledAt sets the "canceled_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetCanceledAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldCanceledAt
,
v
)
return
u
}
// UpdateCanceledAt sets the "canceled_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateCanceledAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldCanceledAt
)
return
u
}
// ClearCanceledAt clears the value of the "canceled_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
ClearCanceledAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetNull
(
usagecleanuptask
.
FieldCanceledAt
)
return
u
}
// SetStartedAt sets the "started_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetStartedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldStartedAt
,
v
)
return
u
}
// UpdateStartedAt sets the "started_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateStartedAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldStartedAt
)
return
u
}
// ClearStartedAt clears the value of the "started_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
ClearStartedAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetNull
(
usagecleanuptask
.
FieldStartedAt
)
return
u
}
// SetFinishedAt sets the "finished_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
SetFinishedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsert
{
u
.
Set
(
usagecleanuptask
.
FieldFinishedAt
,
v
)
return
u
}
// UpdateFinishedAt sets the "finished_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsert
)
UpdateFinishedAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetExcluded
(
usagecleanuptask
.
FieldFinishedAt
)
return
u
}
// ClearFinishedAt clears the value of the "finished_at" field.
func
(
u
*
UsageCleanupTaskUpsert
)
ClearFinishedAt
()
*
UsageCleanupTaskUpsert
{
u
.
SetNull
(
usagecleanuptask
.
FieldFinishedAt
)
return
u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
// client.UsageCleanupTask.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateNewValues
()
*
UsageCleanupTaskUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWithNewValues
())
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
s
*
sql
.
UpdateSet
)
{
if
_
,
exists
:=
u
.
create
.
mutation
.
CreatedAt
();
exists
{
s
.
SetIgnore
(
usagecleanuptask
.
FieldCreatedAt
)
}
}))
return
u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.UsageCleanupTask.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func
(
u
*
UsageCleanupTaskUpsertOne
)
Ignore
()
*
UsageCleanupTaskUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWithIgnore
())
return
u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func
(
u
*
UsageCleanupTaskUpsertOne
)
DoNothing
()
*
UsageCleanupTaskUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
DoNothing
())
return
u
}
// Update allows overriding fields `UPDATE` values. See the UsageCleanupTaskCreate.OnConflict
// documentation for more info.
func
(
u
*
UsageCleanupTaskUpsertOne
)
Update
(
set
func
(
*
UsageCleanupTaskUpsert
))
*
UsageCleanupTaskUpsertOne
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
update
*
sql
.
UpdateSet
)
{
set
(
&
UsageCleanupTaskUpsert
{
UpdateSet
:
update
})
}))
return
u
}
// SetUpdatedAt sets the "updated_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetUpdatedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetUpdatedAt
(
v
)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateUpdatedAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateUpdatedAt
()
})
}
// SetStatus sets the "status" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetStatus
(
v
string
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetStatus
(
v
)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateStatus
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateStatus
()
})
}
// SetFilters sets the "filters" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetFilters
(
v
)
})
}
// UpdateFilters sets the "filters" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateFilters
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateFilters
()
})
}
// SetCreatedBy sets the "created_by" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetCreatedBy
(
v
)
})
}
// AddCreatedBy adds v to the "created_by" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
AddCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
AddCreatedBy
(
v
)
})
}
// UpdateCreatedBy sets the "created_by" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateCreatedBy
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateCreatedBy
()
})
}
// SetDeletedRows sets the "deleted_rows" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetDeletedRows
(
v
)
})
}
// AddDeletedRows adds v to the "deleted_rows" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
AddDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
AddDeletedRows
(
v
)
})
}
// UpdateDeletedRows sets the "deleted_rows" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateDeletedRows
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateDeletedRows
()
})
}
// SetErrorMessage sets the "error_message" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetErrorMessage
(
v
string
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetErrorMessage
(
v
)
})
}
// UpdateErrorMessage sets the "error_message" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateErrorMessage
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateErrorMessage
()
})
}
// ClearErrorMessage clears the value of the "error_message" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
ClearErrorMessage
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearErrorMessage
()
})
}
// SetCanceledBy sets the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetCanceledBy
(
v
)
})
}
// AddCanceledBy adds v to the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
AddCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
AddCanceledBy
(
v
)
})
}
// UpdateCanceledBy sets the "canceled_by" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateCanceledBy
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateCanceledBy
()
})
}
// ClearCanceledBy clears the value of the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
ClearCanceledBy
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearCanceledBy
()
})
}
// SetCanceledAt sets the "canceled_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetCanceledAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetCanceledAt
(
v
)
})
}
// UpdateCanceledAt sets the "canceled_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateCanceledAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateCanceledAt
()
})
}
// ClearCanceledAt clears the value of the "canceled_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
ClearCanceledAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearCanceledAt
()
})
}
// SetStartedAt sets the "started_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetStartedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetStartedAt
(
v
)
})
}
// UpdateStartedAt sets the "started_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateStartedAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateStartedAt
()
})
}
// ClearStartedAt clears the value of the "started_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
ClearStartedAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearStartedAt
()
})
}
// SetFinishedAt sets the "finished_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
SetFinishedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetFinishedAt
(
v
)
})
}
// UpdateFinishedAt sets the "finished_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertOne
)
UpdateFinishedAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateFinishedAt
()
})
}
// ClearFinishedAt clears the value of the "finished_at" field.
func
(
u
*
UsageCleanupTaskUpsertOne
)
ClearFinishedAt
()
*
UsageCleanupTaskUpsertOne
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearFinishedAt
()
})
}
// Exec executes the query.
func
(
u
*
UsageCleanupTaskUpsertOne
)
Exec
(
ctx
context
.
Context
)
error
{
if
len
(
u
.
create
.
conflict
)
==
0
{
return
errors
.
New
(
"ent: missing options for UsageCleanupTaskCreate.OnConflict"
)
}
return
u
.
create
.
Exec
(
ctx
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
u
*
UsageCleanupTaskUpsertOne
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
u
.
create
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// Exec executes the UPSERT query and returns the inserted/updated ID.
func
(
u
*
UsageCleanupTaskUpsertOne
)
ID
(
ctx
context
.
Context
)
(
id
int64
,
err
error
)
{
node
,
err
:=
u
.
create
.
Save
(
ctx
)
if
err
!=
nil
{
return
id
,
err
}
return
node
.
ID
,
nil
}
// IDX is like ID, but panics if an error occurs.
func
(
u
*
UsageCleanupTaskUpsertOne
)
IDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
u
.
ID
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
id
}
// UsageCleanupTaskCreateBulk is the builder for creating many UsageCleanupTask entities in bulk.
type
UsageCleanupTaskCreateBulk
struct
{
config
err
error
builders
[]
*
UsageCleanupTaskCreate
conflict
[]
sql
.
ConflictOption
}
// Save creates the UsageCleanupTask entities in the database.
func
(
_c
*
UsageCleanupTaskCreateBulk
)
Save
(
ctx
context
.
Context
)
([]
*
UsageCleanupTask
,
error
)
{
if
_c
.
err
!=
nil
{
return
nil
,
_c
.
err
}
specs
:=
make
([]
*
sqlgraph
.
CreateSpec
,
len
(
_c
.
builders
))
nodes
:=
make
([]
*
UsageCleanupTask
,
len
(
_c
.
builders
))
mutators
:=
make
([]
Mutator
,
len
(
_c
.
builders
))
for
i
:=
range
_c
.
builders
{
func
(
i
int
,
root
context
.
Context
)
{
builder
:=
_c
.
builders
[
i
]
builder
.
defaults
()
var
mut
Mutator
=
MutateFunc
(
func
(
ctx
context
.
Context
,
m
Mutation
)
(
Value
,
error
)
{
mutation
,
ok
:=
m
.
(
*
UsageCleanupTaskMutation
)
if
!
ok
{
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T"
,
m
)
}
if
err
:=
builder
.
check
();
err
!=
nil
{
return
nil
,
err
}
builder
.
mutation
=
mutation
var
err
error
nodes
[
i
],
specs
[
i
]
=
builder
.
createSpec
()
if
i
<
len
(
mutators
)
-
1
{
_
,
err
=
mutators
[
i
+
1
]
.
Mutate
(
root
,
_c
.
builders
[
i
+
1
]
.
mutation
)
}
else
{
spec
:=
&
sqlgraph
.
BatchCreateSpec
{
Nodes
:
specs
}
spec
.
OnConflict
=
_c
.
conflict
// Invoke the actual operation on the latest mutation in the chain.
if
err
=
sqlgraph
.
BatchCreate
(
ctx
,
_c
.
driver
,
spec
);
err
!=
nil
{
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
}
}
if
err
!=
nil
{
return
nil
,
err
}
mutation
.
id
=
&
nodes
[
i
]
.
ID
if
specs
[
i
]
.
ID
.
Value
!=
nil
{
id
:=
specs
[
i
]
.
ID
.
Value
.
(
int64
)
nodes
[
i
]
.
ID
=
int64
(
id
)
}
mutation
.
done
=
true
return
nodes
[
i
],
nil
})
for
i
:=
len
(
builder
.
hooks
)
-
1
;
i
>=
0
;
i
--
{
mut
=
builder
.
hooks
[
i
](
mut
)
}
mutators
[
i
]
=
mut
}(
i
,
ctx
)
}
if
len
(
mutators
)
>
0
{
if
_
,
err
:=
mutators
[
0
]
.
Mutate
(
ctx
,
_c
.
builders
[
0
]
.
mutation
);
err
!=
nil
{
return
nil
,
err
}
}
return
nodes
,
nil
}
// SaveX is like Save, but panics if an error occurs.
func
(
_c
*
UsageCleanupTaskCreateBulk
)
SaveX
(
ctx
context
.
Context
)
[]
*
UsageCleanupTask
{
v
,
err
:=
_c
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
v
}
// Exec executes the query.
func
(
_c
*
UsageCleanupTaskCreateBulk
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_c
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_c
*
UsageCleanupTaskCreateBulk
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_c
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// OnConflict allows configuring the `ON CONFLICT` / `ON DUPLICATE KEY` clause
// of the `INSERT` statement. For example:
//
// client.UsageCleanupTask.CreateBulk(builders...).
// OnConflict(
// // Update the row with the new values
// // the was proposed for insertion.
// sql.ResolveWithNewValues(),
// ).
// // Override some of the fields with custom
// // update values.
// Update(func(u *ent.UsageCleanupTaskUpsert) {
// SetCreatedAt(v+v).
// }).
// Exec(ctx)
func
(
_c
*
UsageCleanupTaskCreateBulk
)
OnConflict
(
opts
...
sql
.
ConflictOption
)
*
UsageCleanupTaskUpsertBulk
{
_c
.
conflict
=
opts
return
&
UsageCleanupTaskUpsertBulk
{
create
:
_c
,
}
}
// OnConflictColumns calls `OnConflict` and configures the columns
// as conflict target. Using this option is equivalent to using:
//
// client.UsageCleanupTask.Create().
// OnConflict(sql.ConflictColumns(columns...)).
// Exec(ctx)
func
(
_c
*
UsageCleanupTaskCreateBulk
)
OnConflictColumns
(
columns
...
string
)
*
UsageCleanupTaskUpsertBulk
{
_c
.
conflict
=
append
(
_c
.
conflict
,
sql
.
ConflictColumns
(
columns
...
))
return
&
UsageCleanupTaskUpsertBulk
{
create
:
_c
,
}
}
// UsageCleanupTaskUpsertBulk is the builder for "upsert"-ing
// a bulk of UsageCleanupTask nodes.
type
UsageCleanupTaskUpsertBulk
struct
{
create
*
UsageCleanupTaskCreateBulk
}
// UpdateNewValues updates the mutable fields using the new values that
// were set on create. Using this option is equivalent to using:
//
// client.UsageCleanupTask.Create().
// OnConflict(
// sql.ResolveWithNewValues(),
// ).
// Exec(ctx)
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateNewValues
()
*
UsageCleanupTaskUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWithNewValues
())
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
s
*
sql
.
UpdateSet
)
{
for
_
,
b
:=
range
u
.
create
.
builders
{
if
_
,
exists
:=
b
.
mutation
.
CreatedAt
();
exists
{
s
.
SetIgnore
(
usagecleanuptask
.
FieldCreatedAt
)
}
}
}))
return
u
}
// Ignore sets each column to itself in case of conflict.
// Using this option is equivalent to using:
//
// client.UsageCleanupTask.Create().
// OnConflict(sql.ResolveWithIgnore()).
// Exec(ctx)
func
(
u
*
UsageCleanupTaskUpsertBulk
)
Ignore
()
*
UsageCleanupTaskUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWithIgnore
())
return
u
}
// DoNothing configures the conflict_action to `DO NOTHING`.
// Supported only by SQLite and PostgreSQL.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
DoNothing
()
*
UsageCleanupTaskUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
DoNothing
())
return
u
}
// Update allows overriding fields `UPDATE` values. See the UsageCleanupTaskCreateBulk.OnConflict
// documentation for more info.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
Update
(
set
func
(
*
UsageCleanupTaskUpsert
))
*
UsageCleanupTaskUpsertBulk
{
u
.
create
.
conflict
=
append
(
u
.
create
.
conflict
,
sql
.
ResolveWith
(
func
(
update
*
sql
.
UpdateSet
)
{
set
(
&
UsageCleanupTaskUpsert
{
UpdateSet
:
update
})
}))
return
u
}
// SetUpdatedAt sets the "updated_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetUpdatedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetUpdatedAt
(
v
)
})
}
// UpdateUpdatedAt sets the "updated_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateUpdatedAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateUpdatedAt
()
})
}
// SetStatus sets the "status" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetStatus
(
v
string
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetStatus
(
v
)
})
}
// UpdateStatus sets the "status" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateStatus
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateStatus
()
})
}
// SetFilters sets the "filters" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetFilters
(
v
)
})
}
// UpdateFilters sets the "filters" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateFilters
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateFilters
()
})
}
// SetCreatedBy sets the "created_by" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetCreatedBy
(
v
)
})
}
// AddCreatedBy adds v to the "created_by" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
AddCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
AddCreatedBy
(
v
)
})
}
// UpdateCreatedBy sets the "created_by" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateCreatedBy
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateCreatedBy
()
})
}
// SetDeletedRows sets the "deleted_rows" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetDeletedRows
(
v
)
})
}
// AddDeletedRows adds v to the "deleted_rows" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
AddDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
AddDeletedRows
(
v
)
})
}
// UpdateDeletedRows sets the "deleted_rows" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateDeletedRows
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateDeletedRows
()
})
}
// SetErrorMessage sets the "error_message" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetErrorMessage
(
v
string
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetErrorMessage
(
v
)
})
}
// UpdateErrorMessage sets the "error_message" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateErrorMessage
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateErrorMessage
()
})
}
// ClearErrorMessage clears the value of the "error_message" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
ClearErrorMessage
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearErrorMessage
()
})
}
// SetCanceledBy sets the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetCanceledBy
(
v
)
})
}
// AddCanceledBy adds v to the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
AddCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
AddCanceledBy
(
v
)
})
}
// UpdateCanceledBy sets the "canceled_by" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateCanceledBy
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateCanceledBy
()
})
}
// ClearCanceledBy clears the value of the "canceled_by" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
ClearCanceledBy
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearCanceledBy
()
})
}
// SetCanceledAt sets the "canceled_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetCanceledAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetCanceledAt
(
v
)
})
}
// UpdateCanceledAt sets the "canceled_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateCanceledAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateCanceledAt
()
})
}
// ClearCanceledAt clears the value of the "canceled_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
ClearCanceledAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearCanceledAt
()
})
}
// SetStartedAt sets the "started_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetStartedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetStartedAt
(
v
)
})
}
// UpdateStartedAt sets the "started_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateStartedAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateStartedAt
()
})
}
// ClearStartedAt clears the value of the "started_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
ClearStartedAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearStartedAt
()
})
}
// SetFinishedAt sets the "finished_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
SetFinishedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
SetFinishedAt
(
v
)
})
}
// UpdateFinishedAt sets the "finished_at" field to the value that was provided on create.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
UpdateFinishedAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
UpdateFinishedAt
()
})
}
// ClearFinishedAt clears the value of the "finished_at" field.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
ClearFinishedAt
()
*
UsageCleanupTaskUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UsageCleanupTaskUpsert
)
{
s
.
ClearFinishedAt
()
})
}
// Exec executes the query.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
Exec
(
ctx
context
.
Context
)
error
{
if
u
.
create
.
err
!=
nil
{
return
u
.
create
.
err
}
for
i
,
b
:=
range
u
.
create
.
builders
{
if
len
(
b
.
conflict
)
!=
0
{
return
fmt
.
Errorf
(
"ent: OnConflict was set for builder %d. Set it on the UsageCleanupTaskCreateBulk instead"
,
i
)
}
}
if
len
(
u
.
create
.
conflict
)
==
0
{
return
errors
.
New
(
"ent: missing options for UsageCleanupTaskCreateBulk.OnConflict"
)
}
return
u
.
create
.
Exec
(
ctx
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
u
*
UsageCleanupTaskUpsertBulk
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
u
.
create
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
backend/ent/usagecleanuptask_delete.go
0 → 100644
View file @
2fe8932c
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"context"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
)
// UsageCleanupTaskDelete is the builder for deleting a UsageCleanupTask entity.
type
UsageCleanupTaskDelete
struct
{
config
hooks
[]
Hook
mutation
*
UsageCleanupTaskMutation
}
// Where appends a list predicates to the UsageCleanupTaskDelete builder.
func
(
_d
*
UsageCleanupTaskDelete
)
Where
(
ps
...
predicate
.
UsageCleanupTask
)
*
UsageCleanupTaskDelete
{
_d
.
mutation
.
Where
(
ps
...
)
return
_d
}
// Exec executes the deletion query and returns how many vertices were deleted.
func
(
_d
*
UsageCleanupTaskDelete
)
Exec
(
ctx
context
.
Context
)
(
int
,
error
)
{
return
withHooks
(
ctx
,
_d
.
sqlExec
,
_d
.
mutation
,
_d
.
hooks
)
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_d
*
UsageCleanupTaskDelete
)
ExecX
(
ctx
context
.
Context
)
int
{
n
,
err
:=
_d
.
Exec
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
n
}
func
(
_d
*
UsageCleanupTaskDelete
)
sqlExec
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
sqlgraph
.
NewDeleteSpec
(
usagecleanuptask
.
Table
,
sqlgraph
.
NewFieldSpec
(
usagecleanuptask
.
FieldID
,
field
.
TypeInt64
))
if
ps
:=
_d
.
mutation
.
predicates
;
len
(
ps
)
>
0
{
_spec
.
Predicate
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
affected
,
err
:=
sqlgraph
.
DeleteNodes
(
ctx
,
_d
.
driver
,
_spec
)
if
err
!=
nil
&&
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
_d
.
mutation
.
done
=
true
return
affected
,
err
}
// UsageCleanupTaskDeleteOne is the builder for deleting a single UsageCleanupTask entity.
type
UsageCleanupTaskDeleteOne
struct
{
_d
*
UsageCleanupTaskDelete
}
// Where appends a list predicates to the UsageCleanupTaskDelete builder.
func
(
_d
*
UsageCleanupTaskDeleteOne
)
Where
(
ps
...
predicate
.
UsageCleanupTask
)
*
UsageCleanupTaskDeleteOne
{
_d
.
_d
.
mutation
.
Where
(
ps
...
)
return
_d
}
// Exec executes the deletion query.
func
(
_d
*
UsageCleanupTaskDeleteOne
)
Exec
(
ctx
context
.
Context
)
error
{
n
,
err
:=
_d
.
_d
.
Exec
(
ctx
)
switch
{
case
err
!=
nil
:
return
err
case
n
==
0
:
return
&
NotFoundError
{
usagecleanuptask
.
Label
}
default
:
return
nil
}
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_d
*
UsageCleanupTaskDeleteOne
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_d
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
backend/ent/usagecleanuptask_query.go
0 → 100644
View file @
2fe8932c
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"context"
"fmt"
"math"
"entgo.io/ent"
"entgo.io/ent/dialect"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
)
// UsageCleanupTaskQuery is the builder for querying UsageCleanupTask entities.
type
UsageCleanupTaskQuery
struct
{
config
ctx
*
QueryContext
order
[]
usagecleanuptask
.
OrderOption
inters
[]
Interceptor
predicates
[]
predicate
.
UsageCleanupTask
modifiers
[]
func
(
*
sql
.
Selector
)
// intermediate query (i.e. traversal path).
sql
*
sql
.
Selector
path
func
(
context
.
Context
)
(
*
sql
.
Selector
,
error
)
}
// Where adds a new predicate for the UsageCleanupTaskQuery builder.
func
(
_q
*
UsageCleanupTaskQuery
)
Where
(
ps
...
predicate
.
UsageCleanupTask
)
*
UsageCleanupTaskQuery
{
_q
.
predicates
=
append
(
_q
.
predicates
,
ps
...
)
return
_q
}
// Limit the number of records to be returned by this query.
func
(
_q
*
UsageCleanupTaskQuery
)
Limit
(
limit
int
)
*
UsageCleanupTaskQuery
{
_q
.
ctx
.
Limit
=
&
limit
return
_q
}
// Offset to start from.
func
(
_q
*
UsageCleanupTaskQuery
)
Offset
(
offset
int
)
*
UsageCleanupTaskQuery
{
_q
.
ctx
.
Offset
=
&
offset
return
_q
}
// Unique configures the query builder to filter duplicate records on query.
// By default, unique is set to true, and can be disabled using this method.
func
(
_q
*
UsageCleanupTaskQuery
)
Unique
(
unique
bool
)
*
UsageCleanupTaskQuery
{
_q
.
ctx
.
Unique
=
&
unique
return
_q
}
// Order specifies how the records should be ordered.
func
(
_q
*
UsageCleanupTaskQuery
)
Order
(
o
...
usagecleanuptask
.
OrderOption
)
*
UsageCleanupTaskQuery
{
_q
.
order
=
append
(
_q
.
order
,
o
...
)
return
_q
}
// First returns the first UsageCleanupTask entity from the query.
// Returns a *NotFoundError when no UsageCleanupTask was found.
func
(
_q
*
UsageCleanupTaskQuery
)
First
(
ctx
context
.
Context
)
(
*
UsageCleanupTask
,
error
)
{
nodes
,
err
:=
_q
.
Limit
(
1
)
.
All
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryFirst
))
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
nodes
)
==
0
{
return
nil
,
&
NotFoundError
{
usagecleanuptask
.
Label
}
}
return
nodes
[
0
],
nil
}
// FirstX is like First, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
FirstX
(
ctx
context
.
Context
)
*
UsageCleanupTask
{
node
,
err
:=
_q
.
First
(
ctx
)
if
err
!=
nil
&&
!
IsNotFound
(
err
)
{
panic
(
err
)
}
return
node
}
// FirstID returns the first UsageCleanupTask ID from the query.
// Returns a *NotFoundError when no UsageCleanupTask ID was found.
func
(
_q
*
UsageCleanupTaskQuery
)
FirstID
(
ctx
context
.
Context
)
(
id
int64
,
err
error
)
{
var
ids
[]
int64
if
ids
,
err
=
_q
.
Limit
(
1
)
.
IDs
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryFirstID
));
err
!=
nil
{
return
}
if
len
(
ids
)
==
0
{
err
=
&
NotFoundError
{
usagecleanuptask
.
Label
}
return
}
return
ids
[
0
],
nil
}
// FirstIDX is like FirstID, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
FirstIDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
_q
.
FirstID
(
ctx
)
if
err
!=
nil
&&
!
IsNotFound
(
err
)
{
panic
(
err
)
}
return
id
}
// Only returns a single UsageCleanupTask entity found by the query, ensuring it only returns one.
// Returns a *NotSingularError when more than one UsageCleanupTask entity is found.
// Returns a *NotFoundError when no UsageCleanupTask entities are found.
func
(
_q
*
UsageCleanupTaskQuery
)
Only
(
ctx
context
.
Context
)
(
*
UsageCleanupTask
,
error
)
{
nodes
,
err
:=
_q
.
Limit
(
2
)
.
All
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryOnly
))
if
err
!=
nil
{
return
nil
,
err
}
switch
len
(
nodes
)
{
case
1
:
return
nodes
[
0
],
nil
case
0
:
return
nil
,
&
NotFoundError
{
usagecleanuptask
.
Label
}
default
:
return
nil
,
&
NotSingularError
{
usagecleanuptask
.
Label
}
}
}
// OnlyX is like Only, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
OnlyX
(
ctx
context
.
Context
)
*
UsageCleanupTask
{
node
,
err
:=
_q
.
Only
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
node
}
// OnlyID is like Only, but returns the only UsageCleanupTask ID in the query.
// Returns a *NotSingularError when more than one UsageCleanupTask ID is found.
// Returns a *NotFoundError when no entities are found.
func
(
_q
*
UsageCleanupTaskQuery
)
OnlyID
(
ctx
context
.
Context
)
(
id
int64
,
err
error
)
{
var
ids
[]
int64
if
ids
,
err
=
_q
.
Limit
(
2
)
.
IDs
(
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryOnlyID
));
err
!=
nil
{
return
}
switch
len
(
ids
)
{
case
1
:
id
=
ids
[
0
]
case
0
:
err
=
&
NotFoundError
{
usagecleanuptask
.
Label
}
default
:
err
=
&
NotSingularError
{
usagecleanuptask
.
Label
}
}
return
}
// OnlyIDX is like OnlyID, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
OnlyIDX
(
ctx
context
.
Context
)
int64
{
id
,
err
:=
_q
.
OnlyID
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
id
}
// All executes the query and returns a list of UsageCleanupTasks.
func
(
_q
*
UsageCleanupTaskQuery
)
All
(
ctx
context
.
Context
)
([]
*
UsageCleanupTask
,
error
)
{
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryAll
)
if
err
:=
_q
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
nil
,
err
}
qr
:=
querierAll
[[]
*
UsageCleanupTask
,
*
UsageCleanupTaskQuery
]()
return
withInterceptors
[[]
*
UsageCleanupTask
](
ctx
,
_q
,
qr
,
_q
.
inters
)
}
// AllX is like All, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
AllX
(
ctx
context
.
Context
)
[]
*
UsageCleanupTask
{
nodes
,
err
:=
_q
.
All
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
nodes
}
// IDs executes the query and returns a list of UsageCleanupTask IDs.
func
(
_q
*
UsageCleanupTaskQuery
)
IDs
(
ctx
context
.
Context
)
(
ids
[]
int64
,
err
error
)
{
if
_q
.
ctx
.
Unique
==
nil
&&
_q
.
path
!=
nil
{
_q
.
Unique
(
true
)
}
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryIDs
)
if
err
=
_q
.
Select
(
usagecleanuptask
.
FieldID
)
.
Scan
(
ctx
,
&
ids
);
err
!=
nil
{
return
nil
,
err
}
return
ids
,
nil
}
// IDsX is like IDs, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
IDsX
(
ctx
context
.
Context
)
[]
int64
{
ids
,
err
:=
_q
.
IDs
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
ids
}
// Count returns the count of the given query.
func
(
_q
*
UsageCleanupTaskQuery
)
Count
(
ctx
context
.
Context
)
(
int
,
error
)
{
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryCount
)
if
err
:=
_q
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
0
,
err
}
return
withInterceptors
[
int
](
ctx
,
_q
,
querierCount
[
*
UsageCleanupTaskQuery
](),
_q
.
inters
)
}
// CountX is like Count, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
CountX
(
ctx
context
.
Context
)
int
{
count
,
err
:=
_q
.
Count
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
count
}
// Exist returns true if the query has elements in the graph.
func
(
_q
*
UsageCleanupTaskQuery
)
Exist
(
ctx
context
.
Context
)
(
bool
,
error
)
{
ctx
=
setContextOp
(
ctx
,
_q
.
ctx
,
ent
.
OpQueryExist
)
switch
_
,
err
:=
_q
.
FirstID
(
ctx
);
{
case
IsNotFound
(
err
)
:
return
false
,
nil
case
err
!=
nil
:
return
false
,
fmt
.
Errorf
(
"ent: check existence: %w"
,
err
)
default
:
return
true
,
nil
}
}
// ExistX is like Exist, but panics if an error occurs.
func
(
_q
*
UsageCleanupTaskQuery
)
ExistX
(
ctx
context
.
Context
)
bool
{
exist
,
err
:=
_q
.
Exist
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
exist
}
// Clone returns a duplicate of the UsageCleanupTaskQuery builder, including all associated steps. It can be
// used to prepare common query builders and use them differently after the clone is made.
func
(
_q
*
UsageCleanupTaskQuery
)
Clone
()
*
UsageCleanupTaskQuery
{
if
_q
==
nil
{
return
nil
}
return
&
UsageCleanupTaskQuery
{
config
:
_q
.
config
,
ctx
:
_q
.
ctx
.
Clone
(),
order
:
append
([]
usagecleanuptask
.
OrderOption
{},
_q
.
order
...
),
inters
:
append
([]
Interceptor
{},
_q
.
inters
...
),
predicates
:
append
([]
predicate
.
UsageCleanupTask
{},
_q
.
predicates
...
),
// clone intermediate query.
sql
:
_q
.
sql
.
Clone
(),
path
:
_q
.
path
,
}
}
// GroupBy is used to group vertices by one or more fields/columns.
// It is often used with aggregate functions, like: count, max, mean, min, sum.
//
// Example:
//
// var v []struct {
// CreatedAt time.Time `json:"created_at,omitempty"`
// Count int `json:"count,omitempty"`
// }
//
// client.UsageCleanupTask.Query().
// GroupBy(usagecleanuptask.FieldCreatedAt).
// Aggregate(ent.Count()).
// Scan(ctx, &v)
func
(
_q
*
UsageCleanupTaskQuery
)
GroupBy
(
field
string
,
fields
...
string
)
*
UsageCleanupTaskGroupBy
{
_q
.
ctx
.
Fields
=
append
([]
string
{
field
},
fields
...
)
grbuild
:=
&
UsageCleanupTaskGroupBy
{
build
:
_q
}
grbuild
.
flds
=
&
_q
.
ctx
.
Fields
grbuild
.
label
=
usagecleanuptask
.
Label
grbuild
.
scan
=
grbuild
.
Scan
return
grbuild
}
// Select allows the selection one or more fields/columns for the given query,
// instead of selecting all fields in the entity.
//
// Example:
//
// var v []struct {
// CreatedAt time.Time `json:"created_at,omitempty"`
// }
//
// client.UsageCleanupTask.Query().
// Select(usagecleanuptask.FieldCreatedAt).
// Scan(ctx, &v)
func
(
_q
*
UsageCleanupTaskQuery
)
Select
(
fields
...
string
)
*
UsageCleanupTaskSelect
{
_q
.
ctx
.
Fields
=
append
(
_q
.
ctx
.
Fields
,
fields
...
)
sbuild
:=
&
UsageCleanupTaskSelect
{
UsageCleanupTaskQuery
:
_q
}
sbuild
.
label
=
usagecleanuptask
.
Label
sbuild
.
flds
,
sbuild
.
scan
=
&
_q
.
ctx
.
Fields
,
sbuild
.
Scan
return
sbuild
}
// Aggregate returns a UsageCleanupTaskSelect configured with the given aggregations.
func
(
_q
*
UsageCleanupTaskQuery
)
Aggregate
(
fns
...
AggregateFunc
)
*
UsageCleanupTaskSelect
{
return
_q
.
Select
()
.
Aggregate
(
fns
...
)
}
func
(
_q
*
UsageCleanupTaskQuery
)
prepareQuery
(
ctx
context
.
Context
)
error
{
for
_
,
inter
:=
range
_q
.
inters
{
if
inter
==
nil
{
return
fmt
.
Errorf
(
"ent: uninitialized interceptor (forgotten import ent/runtime?)"
)
}
if
trv
,
ok
:=
inter
.
(
Traverser
);
ok
{
if
err
:=
trv
.
Traverse
(
ctx
,
_q
);
err
!=
nil
{
return
err
}
}
}
for
_
,
f
:=
range
_q
.
ctx
.
Fields
{
if
!
usagecleanuptask
.
ValidColumn
(
f
)
{
return
&
ValidationError
{
Name
:
f
,
err
:
fmt
.
Errorf
(
"ent: invalid field %q for query"
,
f
)}
}
}
if
_q
.
path
!=
nil
{
prev
,
err
:=
_q
.
path
(
ctx
)
if
err
!=
nil
{
return
err
}
_q
.
sql
=
prev
}
return
nil
}
func
(
_q
*
UsageCleanupTaskQuery
)
sqlAll
(
ctx
context
.
Context
,
hooks
...
queryHook
)
([]
*
UsageCleanupTask
,
error
)
{
var
(
nodes
=
[]
*
UsageCleanupTask
{}
_spec
=
_q
.
querySpec
()
)
_spec
.
ScanValues
=
func
(
columns
[]
string
)
([]
any
,
error
)
{
return
(
*
UsageCleanupTask
)
.
scanValues
(
nil
,
columns
)
}
_spec
.
Assign
=
func
(
columns
[]
string
,
values
[]
any
)
error
{
node
:=
&
UsageCleanupTask
{
config
:
_q
.
config
}
nodes
=
append
(
nodes
,
node
)
return
node
.
assignValues
(
columns
,
values
)
}
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
for
i
:=
range
hooks
{
hooks
[
i
](
ctx
,
_spec
)
}
if
err
:=
sqlgraph
.
QueryNodes
(
ctx
,
_q
.
driver
,
_spec
);
err
!=
nil
{
return
nil
,
err
}
if
len
(
nodes
)
==
0
{
return
nodes
,
nil
}
return
nodes
,
nil
}
func
(
_q
*
UsageCleanupTaskQuery
)
sqlCount
(
ctx
context
.
Context
)
(
int
,
error
)
{
_spec
:=
_q
.
querySpec
()
if
len
(
_q
.
modifiers
)
>
0
{
_spec
.
Modifiers
=
_q
.
modifiers
}
_spec
.
Node
.
Columns
=
_q
.
ctx
.
Fields
if
len
(
_q
.
ctx
.
Fields
)
>
0
{
_spec
.
Unique
=
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
}
return
sqlgraph
.
CountNodes
(
ctx
,
_q
.
driver
,
_spec
)
}
func
(
_q
*
UsageCleanupTaskQuery
)
querySpec
()
*
sqlgraph
.
QuerySpec
{
_spec
:=
sqlgraph
.
NewQuerySpec
(
usagecleanuptask
.
Table
,
usagecleanuptask
.
Columns
,
sqlgraph
.
NewFieldSpec
(
usagecleanuptask
.
FieldID
,
field
.
TypeInt64
))
_spec
.
From
=
_q
.
sql
if
unique
:=
_q
.
ctx
.
Unique
;
unique
!=
nil
{
_spec
.
Unique
=
*
unique
}
else
if
_q
.
path
!=
nil
{
_spec
.
Unique
=
true
}
if
fields
:=
_q
.
ctx
.
Fields
;
len
(
fields
)
>
0
{
_spec
.
Node
.
Columns
=
make
([]
string
,
0
,
len
(
fields
))
_spec
.
Node
.
Columns
=
append
(
_spec
.
Node
.
Columns
,
usagecleanuptask
.
FieldID
)
for
i
:=
range
fields
{
if
fields
[
i
]
!=
usagecleanuptask
.
FieldID
{
_spec
.
Node
.
Columns
=
append
(
_spec
.
Node
.
Columns
,
fields
[
i
])
}
}
}
if
ps
:=
_q
.
predicates
;
len
(
ps
)
>
0
{
_spec
.
Predicate
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
if
limit
:=
_q
.
ctx
.
Limit
;
limit
!=
nil
{
_spec
.
Limit
=
*
limit
}
if
offset
:=
_q
.
ctx
.
Offset
;
offset
!=
nil
{
_spec
.
Offset
=
*
offset
}
if
ps
:=
_q
.
order
;
len
(
ps
)
>
0
{
_spec
.
Order
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
return
_spec
}
func
(
_q
*
UsageCleanupTaskQuery
)
sqlQuery
(
ctx
context
.
Context
)
*
sql
.
Selector
{
builder
:=
sql
.
Dialect
(
_q
.
driver
.
Dialect
())
t1
:=
builder
.
Table
(
usagecleanuptask
.
Table
)
columns
:=
_q
.
ctx
.
Fields
if
len
(
columns
)
==
0
{
columns
=
usagecleanuptask
.
Columns
}
selector
:=
builder
.
Select
(
t1
.
Columns
(
columns
...
)
...
)
.
From
(
t1
)
if
_q
.
sql
!=
nil
{
selector
=
_q
.
sql
selector
.
Select
(
selector
.
Columns
(
columns
...
)
...
)
}
if
_q
.
ctx
.
Unique
!=
nil
&&
*
_q
.
ctx
.
Unique
{
selector
.
Distinct
()
}
for
_
,
m
:=
range
_q
.
modifiers
{
m
(
selector
)
}
for
_
,
p
:=
range
_q
.
predicates
{
p
(
selector
)
}
for
_
,
p
:=
range
_q
.
order
{
p
(
selector
)
}
if
offset
:=
_q
.
ctx
.
Offset
;
offset
!=
nil
{
// limit is mandatory for offset clause. We start
// with default value, and override it below if needed.
selector
.
Offset
(
*
offset
)
.
Limit
(
math
.
MaxInt32
)
}
if
limit
:=
_q
.
ctx
.
Limit
;
limit
!=
nil
{
selector
.
Limit
(
*
limit
)
}
return
selector
}
// ForUpdate locks the selected rows against concurrent updates, and prevent them from being
// updated, deleted or "selected ... for update" by other sessions, until the transaction is
// either committed or rolled-back.
func
(
_q
*
UsageCleanupTaskQuery
)
ForUpdate
(
opts
...
sql
.
LockOption
)
*
UsageCleanupTaskQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForUpdate
(
opts
...
)
})
return
_q
}
// ForShare behaves similarly to ForUpdate, except that it acquires a shared mode lock
// on any rows that are read. Other sessions can read the rows, but cannot modify them
// until your transaction commits.
func
(
_q
*
UsageCleanupTaskQuery
)
ForShare
(
opts
...
sql
.
LockOption
)
*
UsageCleanupTaskQuery
{
if
_q
.
driver
.
Dialect
()
==
dialect
.
Postgres
{
_q
.
Unique
(
false
)
}
_q
.
modifiers
=
append
(
_q
.
modifiers
,
func
(
s
*
sql
.
Selector
)
{
s
.
ForShare
(
opts
...
)
})
return
_q
}
// UsageCleanupTaskGroupBy is the group-by builder for UsageCleanupTask entities.
type
UsageCleanupTaskGroupBy
struct
{
selector
build
*
UsageCleanupTaskQuery
}
// Aggregate adds the given aggregation functions to the group-by query.
func
(
_g
*
UsageCleanupTaskGroupBy
)
Aggregate
(
fns
...
AggregateFunc
)
*
UsageCleanupTaskGroupBy
{
_g
.
fns
=
append
(
_g
.
fns
,
fns
...
)
return
_g
}
// Scan applies the selector query and scans the result into the given value.
func
(
_g
*
UsageCleanupTaskGroupBy
)
Scan
(
ctx
context
.
Context
,
v
any
)
error
{
ctx
=
setContextOp
(
ctx
,
_g
.
build
.
ctx
,
ent
.
OpQueryGroupBy
)
if
err
:=
_g
.
build
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
err
}
return
scanWithInterceptors
[
*
UsageCleanupTaskQuery
,
*
UsageCleanupTaskGroupBy
](
ctx
,
_g
.
build
,
_g
,
_g
.
build
.
inters
,
v
)
}
func
(
_g
*
UsageCleanupTaskGroupBy
)
sqlScan
(
ctx
context
.
Context
,
root
*
UsageCleanupTaskQuery
,
v
any
)
error
{
selector
:=
root
.
sqlQuery
(
ctx
)
.
Select
()
aggregation
:=
make
([]
string
,
0
,
len
(
_g
.
fns
))
for
_
,
fn
:=
range
_g
.
fns
{
aggregation
=
append
(
aggregation
,
fn
(
selector
))
}
if
len
(
selector
.
SelectedColumns
())
==
0
{
columns
:=
make
([]
string
,
0
,
len
(
*
_g
.
flds
)
+
len
(
_g
.
fns
))
for
_
,
f
:=
range
*
_g
.
flds
{
columns
=
append
(
columns
,
selector
.
C
(
f
))
}
columns
=
append
(
columns
,
aggregation
...
)
selector
.
Select
(
columns
...
)
}
selector
.
GroupBy
(
selector
.
Columns
(
*
_g
.
flds
...
)
...
)
if
err
:=
selector
.
Err
();
err
!=
nil
{
return
err
}
rows
:=
&
sql
.
Rows
{}
query
,
args
:=
selector
.
Query
()
if
err
:=
_g
.
build
.
driver
.
Query
(
ctx
,
query
,
args
,
rows
);
err
!=
nil
{
return
err
}
defer
rows
.
Close
()
return
sql
.
ScanSlice
(
rows
,
v
)
}
// UsageCleanupTaskSelect is the builder for selecting fields of UsageCleanupTask entities.
type
UsageCleanupTaskSelect
struct
{
*
UsageCleanupTaskQuery
selector
}
// Aggregate adds the given aggregation functions to the selector query.
func
(
_s
*
UsageCleanupTaskSelect
)
Aggregate
(
fns
...
AggregateFunc
)
*
UsageCleanupTaskSelect
{
_s
.
fns
=
append
(
_s
.
fns
,
fns
...
)
return
_s
}
// Scan applies the selector query and scans the result into the given value.
func
(
_s
*
UsageCleanupTaskSelect
)
Scan
(
ctx
context
.
Context
,
v
any
)
error
{
ctx
=
setContextOp
(
ctx
,
_s
.
ctx
,
ent
.
OpQuerySelect
)
if
err
:=
_s
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
err
}
return
scanWithInterceptors
[
*
UsageCleanupTaskQuery
,
*
UsageCleanupTaskSelect
](
ctx
,
_s
.
UsageCleanupTaskQuery
,
_s
,
_s
.
inters
,
v
)
}
func
(
_s
*
UsageCleanupTaskSelect
)
sqlScan
(
ctx
context
.
Context
,
root
*
UsageCleanupTaskQuery
,
v
any
)
error
{
selector
:=
root
.
sqlQuery
(
ctx
)
aggregation
:=
make
([]
string
,
0
,
len
(
_s
.
fns
))
for
_
,
fn
:=
range
_s
.
fns
{
aggregation
=
append
(
aggregation
,
fn
(
selector
))
}
switch
n
:=
len
(
*
_s
.
selector
.
flds
);
{
case
n
==
0
&&
len
(
aggregation
)
>
0
:
selector
.
Select
(
aggregation
...
)
case
n
!=
0
&&
len
(
aggregation
)
>
0
:
selector
.
AppendSelect
(
aggregation
...
)
}
rows
:=
&
sql
.
Rows
{}
query
,
args
:=
selector
.
Query
()
if
err
:=
_s
.
driver
.
Query
(
ctx
,
query
,
args
,
rows
);
err
!=
nil
{
return
err
}
defer
rows
.
Close
()
return
sql
.
ScanSlice
(
rows
,
v
)
}
backend/ent/usagecleanuptask_update.go
0 → 100644
View file @
2fe8932c
// Code generated by ent, DO NOT EDIT.
package
ent
import
(
"context"
"encoding/json"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/dialect/sql/sqljson"
"entgo.io/ent/schema/field"
"github.com/Wei-Shaw/sub2api/ent/predicate"
"github.com/Wei-Shaw/sub2api/ent/usagecleanuptask"
)
// UsageCleanupTaskUpdate is the builder for updating UsageCleanupTask entities.
type
UsageCleanupTaskUpdate
struct
{
config
hooks
[]
Hook
mutation
*
UsageCleanupTaskMutation
}
// Where appends a list predicates to the UsageCleanupTaskUpdate builder.
func
(
_u
*
UsageCleanupTaskUpdate
)
Where
(
ps
...
predicate
.
UsageCleanupTask
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
Where
(
ps
...
)
return
_u
}
// SetUpdatedAt sets the "updated_at" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetUpdatedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
SetUpdatedAt
(
v
)
return
_u
}
// SetStatus sets the "status" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetStatus
(
v
string
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
SetStatus
(
v
)
return
_u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetNillableStatus
(
v
*
string
)
*
UsageCleanupTaskUpdate
{
if
v
!=
nil
{
_u
.
SetStatus
(
*
v
)
}
return
_u
}
// SetFilters sets the "filters" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
SetFilters
(
v
)
return
_u
}
// AppendFilters appends value to the "filters" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
AppendFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
AppendFilters
(
v
)
return
_u
}
// SetCreatedBy sets the "created_by" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
ResetCreatedBy
()
_u
.
mutation
.
SetCreatedBy
(
v
)
return
_u
}
// SetNillableCreatedBy sets the "created_by" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetNillableCreatedBy
(
v
*
int64
)
*
UsageCleanupTaskUpdate
{
if
v
!=
nil
{
_u
.
SetCreatedBy
(
*
v
)
}
return
_u
}
// AddCreatedBy adds value to the "created_by" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
AddCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
AddCreatedBy
(
v
)
return
_u
}
// SetDeletedRows sets the "deleted_rows" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
ResetDeletedRows
()
_u
.
mutation
.
SetDeletedRows
(
v
)
return
_u
}
// SetNillableDeletedRows sets the "deleted_rows" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetNillableDeletedRows
(
v
*
int64
)
*
UsageCleanupTaskUpdate
{
if
v
!=
nil
{
_u
.
SetDeletedRows
(
*
v
)
}
return
_u
}
// AddDeletedRows adds value to the "deleted_rows" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
AddDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
AddDeletedRows
(
v
)
return
_u
}
// SetErrorMessage sets the "error_message" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetErrorMessage
(
v
string
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
SetErrorMessage
(
v
)
return
_u
}
// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetNillableErrorMessage
(
v
*
string
)
*
UsageCleanupTaskUpdate
{
if
v
!=
nil
{
_u
.
SetErrorMessage
(
*
v
)
}
return
_u
}
// ClearErrorMessage clears the value of the "error_message" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
ClearErrorMessage
()
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
ClearErrorMessage
()
return
_u
}
// SetCanceledBy sets the "canceled_by" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
ResetCanceledBy
()
_u
.
mutation
.
SetCanceledBy
(
v
)
return
_u
}
// SetNillableCanceledBy sets the "canceled_by" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetNillableCanceledBy
(
v
*
int64
)
*
UsageCleanupTaskUpdate
{
if
v
!=
nil
{
_u
.
SetCanceledBy
(
*
v
)
}
return
_u
}
// AddCanceledBy adds value to the "canceled_by" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
AddCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
AddCanceledBy
(
v
)
return
_u
}
// ClearCanceledBy clears the value of the "canceled_by" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
ClearCanceledBy
()
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
ClearCanceledBy
()
return
_u
}
// SetCanceledAt sets the "canceled_at" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetCanceledAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
SetCanceledAt
(
v
)
return
_u
}
// SetNillableCanceledAt sets the "canceled_at" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetNillableCanceledAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskUpdate
{
if
v
!=
nil
{
_u
.
SetCanceledAt
(
*
v
)
}
return
_u
}
// ClearCanceledAt clears the value of the "canceled_at" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
ClearCanceledAt
()
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
ClearCanceledAt
()
return
_u
}
// SetStartedAt sets the "started_at" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetStartedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
SetStartedAt
(
v
)
return
_u
}
// SetNillableStartedAt sets the "started_at" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetNillableStartedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskUpdate
{
if
v
!=
nil
{
_u
.
SetStartedAt
(
*
v
)
}
return
_u
}
// ClearStartedAt clears the value of the "started_at" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
ClearStartedAt
()
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
ClearStartedAt
()
return
_u
}
// SetFinishedAt sets the "finished_at" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetFinishedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
SetFinishedAt
(
v
)
return
_u
}
// SetNillableFinishedAt sets the "finished_at" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdate
)
SetNillableFinishedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskUpdate
{
if
v
!=
nil
{
_u
.
SetFinishedAt
(
*
v
)
}
return
_u
}
// ClearFinishedAt clears the value of the "finished_at" field.
func
(
_u
*
UsageCleanupTaskUpdate
)
ClearFinishedAt
()
*
UsageCleanupTaskUpdate
{
_u
.
mutation
.
ClearFinishedAt
()
return
_u
}
// Mutation returns the UsageCleanupTaskMutation object of the builder.
func
(
_u
*
UsageCleanupTaskUpdate
)
Mutation
()
*
UsageCleanupTaskMutation
{
return
_u
.
mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func
(
_u
*
UsageCleanupTaskUpdate
)
Save
(
ctx
context
.
Context
)
(
int
,
error
)
{
_u
.
defaults
()
return
withHooks
(
ctx
,
_u
.
sqlSave
,
_u
.
mutation
,
_u
.
hooks
)
}
// SaveX is like Save, but panics if an error occurs.
func
(
_u
*
UsageCleanupTaskUpdate
)
SaveX
(
ctx
context
.
Context
)
int
{
affected
,
err
:=
_u
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
affected
}
// Exec executes the query.
func
(
_u
*
UsageCleanupTaskUpdate
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_u
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_u
*
UsageCleanupTaskUpdate
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_u
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// defaults sets the default values of the builder before save.
func
(
_u
*
UsageCleanupTaskUpdate
)
defaults
()
{
if
_
,
ok
:=
_u
.
mutation
.
UpdatedAt
();
!
ok
{
v
:=
usagecleanuptask
.
UpdateDefaultUpdatedAt
()
_u
.
mutation
.
SetUpdatedAt
(
v
)
}
}
// check runs all checks and user-defined validators on the builder.
func
(
_u
*
UsageCleanupTaskUpdate
)
check
()
error
{
if
v
,
ok
:=
_u
.
mutation
.
Status
();
ok
{
if
err
:=
usagecleanuptask
.
StatusValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"status"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageCleanupTask.status": %w`
,
err
)}
}
}
return
nil
}
func
(
_u
*
UsageCleanupTaskUpdate
)
sqlSave
(
ctx
context
.
Context
)
(
_node
int
,
err
error
)
{
if
err
:=
_u
.
check
();
err
!=
nil
{
return
_node
,
err
}
_spec
:=
sqlgraph
.
NewUpdateSpec
(
usagecleanuptask
.
Table
,
usagecleanuptask
.
Columns
,
sqlgraph
.
NewFieldSpec
(
usagecleanuptask
.
FieldID
,
field
.
TypeInt64
))
if
ps
:=
_u
.
mutation
.
predicates
;
len
(
ps
)
>
0
{
_spec
.
Predicate
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
if
value
,
ok
:=
_u
.
mutation
.
UpdatedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldUpdatedAt
,
field
.
TypeTime
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Status
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldStatus
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Filters
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldFilters
,
field
.
TypeJSON
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AppendedFilters
();
ok
{
_spec
.
AddModifier
(
func
(
u
*
sql
.
UpdateBuilder
)
{
sqljson
.
Append
(
u
,
usagecleanuptask
.
FieldFilters
,
value
)
})
}
if
value
,
ok
:=
_u
.
mutation
.
CreatedBy
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCreatedBy
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedCreatedBy
();
ok
{
_spec
.
AddField
(
usagecleanuptask
.
FieldCreatedBy
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
DeletedRows
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldDeletedRows
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedDeletedRows
();
ok
{
_spec
.
AddField
(
usagecleanuptask
.
FieldDeletedRows
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
ErrorMessage
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldErrorMessage
,
field
.
TypeString
,
value
)
}
if
_u
.
mutation
.
ErrorMessageCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldErrorMessage
,
field
.
TypeString
)
}
if
value
,
ok
:=
_u
.
mutation
.
CanceledBy
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCanceledBy
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedCanceledBy
();
ok
{
_spec
.
AddField
(
usagecleanuptask
.
FieldCanceledBy
,
field
.
TypeInt64
,
value
)
}
if
_u
.
mutation
.
CanceledByCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldCanceledBy
,
field
.
TypeInt64
)
}
if
value
,
ok
:=
_u
.
mutation
.
CanceledAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCanceledAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
CanceledAtCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldCanceledAt
,
field
.
TypeTime
)
}
if
value
,
ok
:=
_u
.
mutation
.
StartedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldStartedAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
StartedAtCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldStartedAt
,
field
.
TypeTime
)
}
if
value
,
ok
:=
_u
.
mutation
.
FinishedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldFinishedAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
FinishedAtCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldFinishedAt
,
field
.
TypeTime
)
}
if
_node
,
err
=
sqlgraph
.
UpdateNodes
(
ctx
,
_u
.
driver
,
_spec
);
err
!=
nil
{
if
_
,
ok
:=
err
.
(
*
sqlgraph
.
NotFoundError
);
ok
{
err
=
&
NotFoundError
{
usagecleanuptask
.
Label
}
}
else
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
return
0
,
err
}
_u
.
mutation
.
done
=
true
return
_node
,
nil
}
// UsageCleanupTaskUpdateOne is the builder for updating a single UsageCleanupTask entity.
type
UsageCleanupTaskUpdateOne
struct
{
config
fields
[]
string
hooks
[]
Hook
mutation
*
UsageCleanupTaskMutation
}
// SetUpdatedAt sets the "updated_at" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetUpdatedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
SetUpdatedAt
(
v
)
return
_u
}
// SetStatus sets the "status" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetStatus
(
v
string
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
SetStatus
(
v
)
return
_u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetNillableStatus
(
v
*
string
)
*
UsageCleanupTaskUpdateOne
{
if
v
!=
nil
{
_u
.
SetStatus
(
*
v
)
}
return
_u
}
// SetFilters sets the "filters" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
SetFilters
(
v
)
return
_u
}
// AppendFilters appends value to the "filters" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
AppendFilters
(
v
json
.
RawMessage
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
AppendFilters
(
v
)
return
_u
}
// SetCreatedBy sets the "created_by" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
ResetCreatedBy
()
_u
.
mutation
.
SetCreatedBy
(
v
)
return
_u
}
// SetNillableCreatedBy sets the "created_by" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetNillableCreatedBy
(
v
*
int64
)
*
UsageCleanupTaskUpdateOne
{
if
v
!=
nil
{
_u
.
SetCreatedBy
(
*
v
)
}
return
_u
}
// AddCreatedBy adds value to the "created_by" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
AddCreatedBy
(
v
int64
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
AddCreatedBy
(
v
)
return
_u
}
// SetDeletedRows sets the "deleted_rows" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
ResetDeletedRows
()
_u
.
mutation
.
SetDeletedRows
(
v
)
return
_u
}
// SetNillableDeletedRows sets the "deleted_rows" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetNillableDeletedRows
(
v
*
int64
)
*
UsageCleanupTaskUpdateOne
{
if
v
!=
nil
{
_u
.
SetDeletedRows
(
*
v
)
}
return
_u
}
// AddDeletedRows adds value to the "deleted_rows" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
AddDeletedRows
(
v
int64
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
AddDeletedRows
(
v
)
return
_u
}
// SetErrorMessage sets the "error_message" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetErrorMessage
(
v
string
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
SetErrorMessage
(
v
)
return
_u
}
// SetNillableErrorMessage sets the "error_message" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetNillableErrorMessage
(
v
*
string
)
*
UsageCleanupTaskUpdateOne
{
if
v
!=
nil
{
_u
.
SetErrorMessage
(
*
v
)
}
return
_u
}
// ClearErrorMessage clears the value of the "error_message" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
ClearErrorMessage
()
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
ClearErrorMessage
()
return
_u
}
// SetCanceledBy sets the "canceled_by" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
ResetCanceledBy
()
_u
.
mutation
.
SetCanceledBy
(
v
)
return
_u
}
// SetNillableCanceledBy sets the "canceled_by" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetNillableCanceledBy
(
v
*
int64
)
*
UsageCleanupTaskUpdateOne
{
if
v
!=
nil
{
_u
.
SetCanceledBy
(
*
v
)
}
return
_u
}
// AddCanceledBy adds value to the "canceled_by" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
AddCanceledBy
(
v
int64
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
AddCanceledBy
(
v
)
return
_u
}
// ClearCanceledBy clears the value of the "canceled_by" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
ClearCanceledBy
()
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
ClearCanceledBy
()
return
_u
}
// SetCanceledAt sets the "canceled_at" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetCanceledAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
SetCanceledAt
(
v
)
return
_u
}
// SetNillableCanceledAt sets the "canceled_at" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetNillableCanceledAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskUpdateOne
{
if
v
!=
nil
{
_u
.
SetCanceledAt
(
*
v
)
}
return
_u
}
// ClearCanceledAt clears the value of the "canceled_at" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
ClearCanceledAt
()
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
ClearCanceledAt
()
return
_u
}
// SetStartedAt sets the "started_at" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetStartedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
SetStartedAt
(
v
)
return
_u
}
// SetNillableStartedAt sets the "started_at" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetNillableStartedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskUpdateOne
{
if
v
!=
nil
{
_u
.
SetStartedAt
(
*
v
)
}
return
_u
}
// ClearStartedAt clears the value of the "started_at" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
ClearStartedAt
()
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
ClearStartedAt
()
return
_u
}
// SetFinishedAt sets the "finished_at" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetFinishedAt
(
v
time
.
Time
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
SetFinishedAt
(
v
)
return
_u
}
// SetNillableFinishedAt sets the "finished_at" field if the given value is not nil.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SetNillableFinishedAt
(
v
*
time
.
Time
)
*
UsageCleanupTaskUpdateOne
{
if
v
!=
nil
{
_u
.
SetFinishedAt
(
*
v
)
}
return
_u
}
// ClearFinishedAt clears the value of the "finished_at" field.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
ClearFinishedAt
()
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
ClearFinishedAt
()
return
_u
}
// Mutation returns the UsageCleanupTaskMutation object of the builder.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
Mutation
()
*
UsageCleanupTaskMutation
{
return
_u
.
mutation
}
// Where appends a list predicates to the UsageCleanupTaskUpdate builder.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
Where
(
ps
...
predicate
.
UsageCleanupTask
)
*
UsageCleanupTaskUpdateOne
{
_u
.
mutation
.
Where
(
ps
...
)
return
_u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
Select
(
field
string
,
fields
...
string
)
*
UsageCleanupTaskUpdateOne
{
_u
.
fields
=
append
([]
string
{
field
},
fields
...
)
return
_u
}
// Save executes the query and returns the updated UsageCleanupTask entity.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
Save
(
ctx
context
.
Context
)
(
*
UsageCleanupTask
,
error
)
{
_u
.
defaults
()
return
withHooks
(
ctx
,
_u
.
sqlSave
,
_u
.
mutation
,
_u
.
hooks
)
}
// SaveX is like Save, but panics if an error occurs.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
SaveX
(
ctx
context
.
Context
)
*
UsageCleanupTask
{
node
,
err
:=
_u
.
Save
(
ctx
)
if
err
!=
nil
{
panic
(
err
)
}
return
node
}
// Exec executes the query on the entity.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
Exec
(
ctx
context
.
Context
)
error
{
_
,
err
:=
_u
.
Save
(
ctx
)
return
err
}
// ExecX is like Exec, but panics if an error occurs.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
ExecX
(
ctx
context
.
Context
)
{
if
err
:=
_u
.
Exec
(
ctx
);
err
!=
nil
{
panic
(
err
)
}
}
// defaults sets the default values of the builder before save.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
defaults
()
{
if
_
,
ok
:=
_u
.
mutation
.
UpdatedAt
();
!
ok
{
v
:=
usagecleanuptask
.
UpdateDefaultUpdatedAt
()
_u
.
mutation
.
SetUpdatedAt
(
v
)
}
}
// check runs all checks and user-defined validators on the builder.
func
(
_u
*
UsageCleanupTaskUpdateOne
)
check
()
error
{
if
v
,
ok
:=
_u
.
mutation
.
Status
();
ok
{
if
err
:=
usagecleanuptask
.
StatusValidator
(
v
);
err
!=
nil
{
return
&
ValidationError
{
Name
:
"status"
,
err
:
fmt
.
Errorf
(
`ent: validator failed for field "UsageCleanupTask.status": %w`
,
err
)}
}
}
return
nil
}
func
(
_u
*
UsageCleanupTaskUpdateOne
)
sqlSave
(
ctx
context
.
Context
)
(
_node
*
UsageCleanupTask
,
err
error
)
{
if
err
:=
_u
.
check
();
err
!=
nil
{
return
_node
,
err
}
_spec
:=
sqlgraph
.
NewUpdateSpec
(
usagecleanuptask
.
Table
,
usagecleanuptask
.
Columns
,
sqlgraph
.
NewFieldSpec
(
usagecleanuptask
.
FieldID
,
field
.
TypeInt64
))
id
,
ok
:=
_u
.
mutation
.
ID
()
if
!
ok
{
return
nil
,
&
ValidationError
{
Name
:
"id"
,
err
:
errors
.
New
(
`ent: missing "UsageCleanupTask.id" for update`
)}
}
_spec
.
Node
.
ID
.
Value
=
id
if
fields
:=
_u
.
fields
;
len
(
fields
)
>
0
{
_spec
.
Node
.
Columns
=
make
([]
string
,
0
,
len
(
fields
))
_spec
.
Node
.
Columns
=
append
(
_spec
.
Node
.
Columns
,
usagecleanuptask
.
FieldID
)
for
_
,
f
:=
range
fields
{
if
!
usagecleanuptask
.
ValidColumn
(
f
)
{
return
nil
,
&
ValidationError
{
Name
:
f
,
err
:
fmt
.
Errorf
(
"ent: invalid field %q for query"
,
f
)}
}
if
f
!=
usagecleanuptask
.
FieldID
{
_spec
.
Node
.
Columns
=
append
(
_spec
.
Node
.
Columns
,
f
)
}
}
}
if
ps
:=
_u
.
mutation
.
predicates
;
len
(
ps
)
>
0
{
_spec
.
Predicate
=
func
(
selector
*
sql
.
Selector
)
{
for
i
:=
range
ps
{
ps
[
i
](
selector
)
}
}
}
if
value
,
ok
:=
_u
.
mutation
.
UpdatedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldUpdatedAt
,
field
.
TypeTime
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Status
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldStatus
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
Filters
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldFilters
,
field
.
TypeJSON
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AppendedFilters
();
ok
{
_spec
.
AddModifier
(
func
(
u
*
sql
.
UpdateBuilder
)
{
sqljson
.
Append
(
u
,
usagecleanuptask
.
FieldFilters
,
value
)
})
}
if
value
,
ok
:=
_u
.
mutation
.
CreatedBy
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCreatedBy
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedCreatedBy
();
ok
{
_spec
.
AddField
(
usagecleanuptask
.
FieldCreatedBy
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
DeletedRows
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldDeletedRows
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedDeletedRows
();
ok
{
_spec
.
AddField
(
usagecleanuptask
.
FieldDeletedRows
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
ErrorMessage
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldErrorMessage
,
field
.
TypeString
,
value
)
}
if
_u
.
mutation
.
ErrorMessageCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldErrorMessage
,
field
.
TypeString
)
}
if
value
,
ok
:=
_u
.
mutation
.
CanceledBy
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCanceledBy
,
field
.
TypeInt64
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
AddedCanceledBy
();
ok
{
_spec
.
AddField
(
usagecleanuptask
.
FieldCanceledBy
,
field
.
TypeInt64
,
value
)
}
if
_u
.
mutation
.
CanceledByCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldCanceledBy
,
field
.
TypeInt64
)
}
if
value
,
ok
:=
_u
.
mutation
.
CanceledAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldCanceledAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
CanceledAtCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldCanceledAt
,
field
.
TypeTime
)
}
if
value
,
ok
:=
_u
.
mutation
.
StartedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldStartedAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
StartedAtCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldStartedAt
,
field
.
TypeTime
)
}
if
value
,
ok
:=
_u
.
mutation
.
FinishedAt
();
ok
{
_spec
.
SetField
(
usagecleanuptask
.
FieldFinishedAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
FinishedAtCleared
()
{
_spec
.
ClearField
(
usagecleanuptask
.
FieldFinishedAt
,
field
.
TypeTime
)
}
_node
=
&
UsageCleanupTask
{
config
:
_u
.
config
}
_spec
.
Assign
=
_node
.
assignValues
_spec
.
ScanValues
=
_node
.
scanValues
if
err
=
sqlgraph
.
UpdateNode
(
ctx
,
_u
.
driver
,
_spec
);
err
!=
nil
{
if
_
,
ok
:=
err
.
(
*
sqlgraph
.
NotFoundError
);
ok
{
err
=
&
NotFoundError
{
usagecleanuptask
.
Label
}
}
else
if
sqlgraph
.
IsConstraintError
(
err
)
{
err
=
&
ConstraintError
{
msg
:
err
.
Error
(),
wrap
:
err
}
}
return
nil
,
err
}
_u
.
mutation
.
done
=
true
return
_node
,
nil
}
backend/ent/user.go
View file @
2fe8932c
...
...
@@ -39,6 +39,12 @@ type User struct {
Username
string
`json:"username,omitempty"`
// Notes holds the value of the "notes" field.
Notes
string
`json:"notes,omitempty"`
// TotpSecretEncrypted holds the value of the "totp_secret_encrypted" field.
TotpSecretEncrypted
*
string
`json:"totp_secret_encrypted,omitempty"`
// TotpEnabled holds the value of the "totp_enabled" field.
TotpEnabled
bool
`json:"totp_enabled,omitempty"`
// TotpEnabledAt holds the value of the "totp_enabled_at" field.
TotpEnabledAt
*
time
.
Time
`json:"totp_enabled_at,omitempty"`
// Edges holds the relations/edges for other nodes in the graph.
// The values are being populated by the UserQuery when eager-loading is set.
Edges
UserEdges
`json:"edges"`
...
...
@@ -156,13 +162,15 @@ func (*User) scanValues(columns []string) ([]any, error) {
values
:=
make
([]
any
,
len
(
columns
))
for
i
:=
range
columns
{
switch
columns
[
i
]
{
case
user
.
FieldTotpEnabled
:
values
[
i
]
=
new
(
sql
.
NullBool
)
case
user
.
FieldBalance
:
values
[
i
]
=
new
(
sql
.
NullFloat64
)
case
user
.
FieldID
,
user
.
FieldConcurrency
:
values
[
i
]
=
new
(
sql
.
NullInt64
)
case
user
.
FieldEmail
,
user
.
FieldPasswordHash
,
user
.
FieldRole
,
user
.
FieldStatus
,
user
.
FieldUsername
,
user
.
FieldNotes
:
case
user
.
FieldEmail
,
user
.
FieldPasswordHash
,
user
.
FieldRole
,
user
.
FieldStatus
,
user
.
FieldUsername
,
user
.
FieldNotes
,
user
.
FieldTotpSecretEncrypted
:
values
[
i
]
=
new
(
sql
.
NullString
)
case
user
.
FieldCreatedAt
,
user
.
FieldUpdatedAt
,
user
.
FieldDeletedAt
:
case
user
.
FieldCreatedAt
,
user
.
FieldUpdatedAt
,
user
.
FieldDeletedAt
,
user
.
FieldTotpEnabledAt
:
values
[
i
]
=
new
(
sql
.
NullTime
)
default
:
values
[
i
]
=
new
(
sql
.
UnknownType
)
...
...
@@ -252,6 +260,26 @@ func (_m *User) assignValues(columns []string, values []any) error {
}
else
if
value
.
Valid
{
_m
.
Notes
=
value
.
String
}
case
user
.
FieldTotpSecretEncrypted
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullString
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field totp_secret_encrypted"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
TotpSecretEncrypted
=
new
(
string
)
*
_m
.
TotpSecretEncrypted
=
value
.
String
}
case
user
.
FieldTotpEnabled
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullBool
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field totp_enabled"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
TotpEnabled
=
value
.
Bool
}
case
user
.
FieldTotpEnabledAt
:
if
value
,
ok
:=
values
[
i
]
.
(
*
sql
.
NullTime
);
!
ok
{
return
fmt
.
Errorf
(
"unexpected type %T for field totp_enabled_at"
,
values
[
i
])
}
else
if
value
.
Valid
{
_m
.
TotpEnabledAt
=
new
(
time
.
Time
)
*
_m
.
TotpEnabledAt
=
value
.
Time
}
default
:
_m
.
selectValues
.
Set
(
columns
[
i
],
values
[
i
])
}
...
...
@@ -367,6 +395,19 @@ func (_m *User) String() string {
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"notes="
)
builder
.
WriteString
(
_m
.
Notes
)
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
TotpSecretEncrypted
;
v
!=
nil
{
builder
.
WriteString
(
"totp_secret_encrypted="
)
builder
.
WriteString
(
*
v
)
}
builder
.
WriteString
(
", "
)
builder
.
WriteString
(
"totp_enabled="
)
builder
.
WriteString
(
fmt
.
Sprintf
(
"%v"
,
_m
.
TotpEnabled
))
builder
.
WriteString
(
", "
)
if
v
:=
_m
.
TotpEnabledAt
;
v
!=
nil
{
builder
.
WriteString
(
"totp_enabled_at="
)
builder
.
WriteString
(
v
.
Format
(
time
.
ANSIC
))
}
builder
.
WriteByte
(
')'
)
return
builder
.
String
()
}
...
...
backend/ent/user/user.go
View file @
2fe8932c
...
...
@@ -37,6 +37,12 @@ const (
FieldUsername
=
"username"
// FieldNotes holds the string denoting the notes field in the database.
FieldNotes
=
"notes"
// FieldTotpSecretEncrypted holds the string denoting the totp_secret_encrypted field in the database.
FieldTotpSecretEncrypted
=
"totp_secret_encrypted"
// FieldTotpEnabled holds the string denoting the totp_enabled field in the database.
FieldTotpEnabled
=
"totp_enabled"
// FieldTotpEnabledAt holds the string denoting the totp_enabled_at field in the database.
FieldTotpEnabledAt
=
"totp_enabled_at"
// EdgeAPIKeys holds the string denoting the api_keys edge name in mutations.
EdgeAPIKeys
=
"api_keys"
// EdgeRedeemCodes holds the string denoting the redeem_codes edge name in mutations.
...
...
@@ -134,6 +140,9 @@ var Columns = []string{
FieldStatus
,
FieldUsername
,
FieldNotes
,
FieldTotpSecretEncrypted
,
FieldTotpEnabled
,
FieldTotpEnabledAt
,
}
var
(
...
...
@@ -188,6 +197,8 @@ var (
UsernameValidator
func
(
string
)
error
// DefaultNotes holds the default value on creation for the "notes" field.
DefaultNotes
string
// DefaultTotpEnabled holds the default value on creation for the "totp_enabled" field.
DefaultTotpEnabled
bool
)
// OrderOption defines the ordering options for the User queries.
...
...
@@ -253,6 +264,21 @@ func ByNotes(opts ...sql.OrderTermOption) OrderOption {
return
sql
.
OrderByField
(
FieldNotes
,
opts
...
)
.
ToFunc
()
}
// ByTotpSecretEncrypted orders the results by the totp_secret_encrypted field.
func
ByTotpSecretEncrypted
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldTotpSecretEncrypted
,
opts
...
)
.
ToFunc
()
}
// ByTotpEnabled orders the results by the totp_enabled field.
func
ByTotpEnabled
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldTotpEnabled
,
opts
...
)
.
ToFunc
()
}
// ByTotpEnabledAt orders the results by the totp_enabled_at field.
func
ByTotpEnabledAt
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
sql
.
OrderByField
(
FieldTotpEnabledAt
,
opts
...
)
.
ToFunc
()
}
// ByAPIKeysCount orders the results by api_keys count.
func
ByAPIKeysCount
(
opts
...
sql
.
OrderTermOption
)
OrderOption
{
return
func
(
s
*
sql
.
Selector
)
{
...
...
backend/ent/user/where.go
View file @
2fe8932c
...
...
@@ -110,6 +110,21 @@ func Notes(v string) predicate.User {
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldNotes
,
v
))
}
// TotpSecretEncrypted applies equality check predicate on the "totp_secret_encrypted" field. It's identical to TotpSecretEncryptedEQ.
func
TotpSecretEncrypted
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpEnabled applies equality check predicate on the "totp_enabled" field. It's identical to TotpEnabledEQ.
func
TotpEnabled
(
v
bool
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldTotpEnabled
,
v
))
}
// TotpEnabledAt applies equality check predicate on the "totp_enabled_at" field. It's identical to TotpEnabledAtEQ.
func
TotpEnabledAt
(
v
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldTotpEnabledAt
,
v
))
}
// CreatedAtEQ applies the EQ predicate on the "created_at" field.
func
CreatedAtEQ
(
v
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldCreatedAt
,
v
))
...
...
@@ -710,6 +725,141 @@ func NotesContainsFold(v string) predicate.User {
return
predicate
.
User
(
sql
.
FieldContainsFold
(
FieldNotes
,
v
))
}
// TotpSecretEncryptedEQ applies the EQ predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedEQ
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedNEQ applies the NEQ predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedNEQ
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldNEQ
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedIn applies the In predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedIn
(
vs
...
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldIn
(
FieldTotpSecretEncrypted
,
vs
...
))
}
// TotpSecretEncryptedNotIn applies the NotIn predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedNotIn
(
vs
...
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldNotIn
(
FieldTotpSecretEncrypted
,
vs
...
))
}
// TotpSecretEncryptedGT applies the GT predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedGT
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldGT
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedGTE applies the GTE predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedGTE
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldGTE
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedLT applies the LT predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedLT
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldLT
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedLTE applies the LTE predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedLTE
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldLTE
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedContains applies the Contains predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedContains
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldContains
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedHasPrefix applies the HasPrefix predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedHasPrefix
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldHasPrefix
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedHasSuffix applies the HasSuffix predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedHasSuffix
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldHasSuffix
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedIsNil applies the IsNil predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedIsNil
()
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldIsNull
(
FieldTotpSecretEncrypted
))
}
// TotpSecretEncryptedNotNil applies the NotNil predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedNotNil
()
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldNotNull
(
FieldTotpSecretEncrypted
))
}
// TotpSecretEncryptedEqualFold applies the EqualFold predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedEqualFold
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEqualFold
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpSecretEncryptedContainsFold applies the ContainsFold predicate on the "totp_secret_encrypted" field.
func
TotpSecretEncryptedContainsFold
(
v
string
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldContainsFold
(
FieldTotpSecretEncrypted
,
v
))
}
// TotpEnabledEQ applies the EQ predicate on the "totp_enabled" field.
func
TotpEnabledEQ
(
v
bool
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldTotpEnabled
,
v
))
}
// TotpEnabledNEQ applies the NEQ predicate on the "totp_enabled" field.
func
TotpEnabledNEQ
(
v
bool
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldNEQ
(
FieldTotpEnabled
,
v
))
}
// TotpEnabledAtEQ applies the EQ predicate on the "totp_enabled_at" field.
func
TotpEnabledAtEQ
(
v
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldEQ
(
FieldTotpEnabledAt
,
v
))
}
// TotpEnabledAtNEQ applies the NEQ predicate on the "totp_enabled_at" field.
func
TotpEnabledAtNEQ
(
v
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldNEQ
(
FieldTotpEnabledAt
,
v
))
}
// TotpEnabledAtIn applies the In predicate on the "totp_enabled_at" field.
func
TotpEnabledAtIn
(
vs
...
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldIn
(
FieldTotpEnabledAt
,
vs
...
))
}
// TotpEnabledAtNotIn applies the NotIn predicate on the "totp_enabled_at" field.
func
TotpEnabledAtNotIn
(
vs
...
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldNotIn
(
FieldTotpEnabledAt
,
vs
...
))
}
// TotpEnabledAtGT applies the GT predicate on the "totp_enabled_at" field.
func
TotpEnabledAtGT
(
v
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldGT
(
FieldTotpEnabledAt
,
v
))
}
// TotpEnabledAtGTE applies the GTE predicate on the "totp_enabled_at" field.
func
TotpEnabledAtGTE
(
v
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldGTE
(
FieldTotpEnabledAt
,
v
))
}
// TotpEnabledAtLT applies the LT predicate on the "totp_enabled_at" field.
func
TotpEnabledAtLT
(
v
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldLT
(
FieldTotpEnabledAt
,
v
))
}
// TotpEnabledAtLTE applies the LTE predicate on the "totp_enabled_at" field.
func
TotpEnabledAtLTE
(
v
time
.
Time
)
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldLTE
(
FieldTotpEnabledAt
,
v
))
}
// TotpEnabledAtIsNil applies the IsNil predicate on the "totp_enabled_at" field.
func
TotpEnabledAtIsNil
()
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldIsNull
(
FieldTotpEnabledAt
))
}
// TotpEnabledAtNotNil applies the NotNil predicate on the "totp_enabled_at" field.
func
TotpEnabledAtNotNil
()
predicate
.
User
{
return
predicate
.
User
(
sql
.
FieldNotNull
(
FieldTotpEnabledAt
))
}
// HasAPIKeys applies the HasEdge predicate on the "api_keys" edge.
func
HasAPIKeys
()
predicate
.
User
{
return
predicate
.
User
(
func
(
s
*
sql
.
Selector
)
{
...
...
backend/ent/user_create.go
View file @
2fe8932c
...
...
@@ -167,6 +167,48 @@ func (_c *UserCreate) SetNillableNotes(v *string) *UserCreate {
return
_c
}
// SetTotpSecretEncrypted sets the "totp_secret_encrypted" field.
func
(
_c
*
UserCreate
)
SetTotpSecretEncrypted
(
v
string
)
*
UserCreate
{
_c
.
mutation
.
SetTotpSecretEncrypted
(
v
)
return
_c
}
// SetNillableTotpSecretEncrypted sets the "totp_secret_encrypted" field if the given value is not nil.
func
(
_c
*
UserCreate
)
SetNillableTotpSecretEncrypted
(
v
*
string
)
*
UserCreate
{
if
v
!=
nil
{
_c
.
SetTotpSecretEncrypted
(
*
v
)
}
return
_c
}
// SetTotpEnabled sets the "totp_enabled" field.
func
(
_c
*
UserCreate
)
SetTotpEnabled
(
v
bool
)
*
UserCreate
{
_c
.
mutation
.
SetTotpEnabled
(
v
)
return
_c
}
// SetNillableTotpEnabled sets the "totp_enabled" field if the given value is not nil.
func
(
_c
*
UserCreate
)
SetNillableTotpEnabled
(
v
*
bool
)
*
UserCreate
{
if
v
!=
nil
{
_c
.
SetTotpEnabled
(
*
v
)
}
return
_c
}
// SetTotpEnabledAt sets the "totp_enabled_at" field.
func
(
_c
*
UserCreate
)
SetTotpEnabledAt
(
v
time
.
Time
)
*
UserCreate
{
_c
.
mutation
.
SetTotpEnabledAt
(
v
)
return
_c
}
// SetNillableTotpEnabledAt sets the "totp_enabled_at" field if the given value is not nil.
func
(
_c
*
UserCreate
)
SetNillableTotpEnabledAt
(
v
*
time
.
Time
)
*
UserCreate
{
if
v
!=
nil
{
_c
.
SetTotpEnabledAt
(
*
v
)
}
return
_c
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func
(
_c
*
UserCreate
)
AddAPIKeyIDs
(
ids
...
int64
)
*
UserCreate
{
_c
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
...
...
@@ -362,6 +404,10 @@ func (_c *UserCreate) defaults() error {
v
:=
user
.
DefaultNotes
_c
.
mutation
.
SetNotes
(
v
)
}
if
_
,
ok
:=
_c
.
mutation
.
TotpEnabled
();
!
ok
{
v
:=
user
.
DefaultTotpEnabled
_c
.
mutation
.
SetTotpEnabled
(
v
)
}
return
nil
}
...
...
@@ -422,6 +468,9 @@ func (_c *UserCreate) check() error {
if
_
,
ok
:=
_c
.
mutation
.
Notes
();
!
ok
{
return
&
ValidationError
{
Name
:
"notes"
,
err
:
errors
.
New
(
`ent: missing required field "User.notes"`
)}
}
if
_
,
ok
:=
_c
.
mutation
.
TotpEnabled
();
!
ok
{
return
&
ValidationError
{
Name
:
"totp_enabled"
,
err
:
errors
.
New
(
`ent: missing required field "User.totp_enabled"`
)}
}
return
nil
}
...
...
@@ -493,6 +542,18 @@ func (_c *UserCreate) createSpec() (*User, *sqlgraph.CreateSpec) {
_spec
.
SetField
(
user
.
FieldNotes
,
field
.
TypeString
,
value
)
_node
.
Notes
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
TotpSecretEncrypted
();
ok
{
_spec
.
SetField
(
user
.
FieldTotpSecretEncrypted
,
field
.
TypeString
,
value
)
_node
.
TotpSecretEncrypted
=
&
value
}
if
value
,
ok
:=
_c
.
mutation
.
TotpEnabled
();
ok
{
_spec
.
SetField
(
user
.
FieldTotpEnabled
,
field
.
TypeBool
,
value
)
_node
.
TotpEnabled
=
value
}
if
value
,
ok
:=
_c
.
mutation
.
TotpEnabledAt
();
ok
{
_spec
.
SetField
(
user
.
FieldTotpEnabledAt
,
field
.
TypeTime
,
value
)
_node
.
TotpEnabledAt
=
&
value
}
if
nodes
:=
_c
.
mutation
.
APIKeysIDs
();
len
(
nodes
)
>
0
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
...
...
@@ -815,6 +876,54 @@ func (u *UserUpsert) UpdateNotes() *UserUpsert {
return
u
}
// SetTotpSecretEncrypted sets the "totp_secret_encrypted" field.
func
(
u
*
UserUpsert
)
SetTotpSecretEncrypted
(
v
string
)
*
UserUpsert
{
u
.
Set
(
user
.
FieldTotpSecretEncrypted
,
v
)
return
u
}
// UpdateTotpSecretEncrypted sets the "totp_secret_encrypted" field to the value that was provided on create.
func
(
u
*
UserUpsert
)
UpdateTotpSecretEncrypted
()
*
UserUpsert
{
u
.
SetExcluded
(
user
.
FieldTotpSecretEncrypted
)
return
u
}
// ClearTotpSecretEncrypted clears the value of the "totp_secret_encrypted" field.
func
(
u
*
UserUpsert
)
ClearTotpSecretEncrypted
()
*
UserUpsert
{
u
.
SetNull
(
user
.
FieldTotpSecretEncrypted
)
return
u
}
// SetTotpEnabled sets the "totp_enabled" field.
func
(
u
*
UserUpsert
)
SetTotpEnabled
(
v
bool
)
*
UserUpsert
{
u
.
Set
(
user
.
FieldTotpEnabled
,
v
)
return
u
}
// UpdateTotpEnabled sets the "totp_enabled" field to the value that was provided on create.
func
(
u
*
UserUpsert
)
UpdateTotpEnabled
()
*
UserUpsert
{
u
.
SetExcluded
(
user
.
FieldTotpEnabled
)
return
u
}
// SetTotpEnabledAt sets the "totp_enabled_at" field.
func
(
u
*
UserUpsert
)
SetTotpEnabledAt
(
v
time
.
Time
)
*
UserUpsert
{
u
.
Set
(
user
.
FieldTotpEnabledAt
,
v
)
return
u
}
// UpdateTotpEnabledAt sets the "totp_enabled_at" field to the value that was provided on create.
func
(
u
*
UserUpsert
)
UpdateTotpEnabledAt
()
*
UserUpsert
{
u
.
SetExcluded
(
user
.
FieldTotpEnabledAt
)
return
u
}
// ClearTotpEnabledAt clears the value of the "totp_enabled_at" field.
func
(
u
*
UserUpsert
)
ClearTotpEnabledAt
()
*
UserUpsert
{
u
.
SetNull
(
user
.
FieldTotpEnabledAt
)
return
u
}
// UpdateNewValues updates the mutable fields using the new values that were set on create.
// Using this option is equivalent to using:
//
...
...
@@ -1021,6 +1130,62 @@ func (u *UserUpsertOne) UpdateNotes() *UserUpsertOne {
})
}
// SetTotpSecretEncrypted sets the "totp_secret_encrypted" field.
func
(
u
*
UserUpsertOne
)
SetTotpSecretEncrypted
(
v
string
)
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
SetTotpSecretEncrypted
(
v
)
})
}
// UpdateTotpSecretEncrypted sets the "totp_secret_encrypted" field to the value that was provided on create.
func
(
u
*
UserUpsertOne
)
UpdateTotpSecretEncrypted
()
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
UpdateTotpSecretEncrypted
()
})
}
// ClearTotpSecretEncrypted clears the value of the "totp_secret_encrypted" field.
func
(
u
*
UserUpsertOne
)
ClearTotpSecretEncrypted
()
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
ClearTotpSecretEncrypted
()
})
}
// SetTotpEnabled sets the "totp_enabled" field.
func
(
u
*
UserUpsertOne
)
SetTotpEnabled
(
v
bool
)
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
SetTotpEnabled
(
v
)
})
}
// UpdateTotpEnabled sets the "totp_enabled" field to the value that was provided on create.
func
(
u
*
UserUpsertOne
)
UpdateTotpEnabled
()
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
UpdateTotpEnabled
()
})
}
// SetTotpEnabledAt sets the "totp_enabled_at" field.
func
(
u
*
UserUpsertOne
)
SetTotpEnabledAt
(
v
time
.
Time
)
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
SetTotpEnabledAt
(
v
)
})
}
// UpdateTotpEnabledAt sets the "totp_enabled_at" field to the value that was provided on create.
func
(
u
*
UserUpsertOne
)
UpdateTotpEnabledAt
()
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
UpdateTotpEnabledAt
()
})
}
// ClearTotpEnabledAt clears the value of the "totp_enabled_at" field.
func
(
u
*
UserUpsertOne
)
ClearTotpEnabledAt
()
*
UserUpsertOne
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
ClearTotpEnabledAt
()
})
}
// Exec executes the query.
func
(
u
*
UserUpsertOne
)
Exec
(
ctx
context
.
Context
)
error
{
if
len
(
u
.
create
.
conflict
)
==
0
{
...
...
@@ -1393,6 +1558,62 @@ func (u *UserUpsertBulk) UpdateNotes() *UserUpsertBulk {
})
}
// SetTotpSecretEncrypted sets the "totp_secret_encrypted" field.
func
(
u
*
UserUpsertBulk
)
SetTotpSecretEncrypted
(
v
string
)
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
SetTotpSecretEncrypted
(
v
)
})
}
// UpdateTotpSecretEncrypted sets the "totp_secret_encrypted" field to the value that was provided on create.
func
(
u
*
UserUpsertBulk
)
UpdateTotpSecretEncrypted
()
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
UpdateTotpSecretEncrypted
()
})
}
// ClearTotpSecretEncrypted clears the value of the "totp_secret_encrypted" field.
func
(
u
*
UserUpsertBulk
)
ClearTotpSecretEncrypted
()
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
ClearTotpSecretEncrypted
()
})
}
// SetTotpEnabled sets the "totp_enabled" field.
func
(
u
*
UserUpsertBulk
)
SetTotpEnabled
(
v
bool
)
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
SetTotpEnabled
(
v
)
})
}
// UpdateTotpEnabled sets the "totp_enabled" field to the value that was provided on create.
func
(
u
*
UserUpsertBulk
)
UpdateTotpEnabled
()
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
UpdateTotpEnabled
()
})
}
// SetTotpEnabledAt sets the "totp_enabled_at" field.
func
(
u
*
UserUpsertBulk
)
SetTotpEnabledAt
(
v
time
.
Time
)
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
SetTotpEnabledAt
(
v
)
})
}
// UpdateTotpEnabledAt sets the "totp_enabled_at" field to the value that was provided on create.
func
(
u
*
UserUpsertBulk
)
UpdateTotpEnabledAt
()
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
UpdateTotpEnabledAt
()
})
}
// ClearTotpEnabledAt clears the value of the "totp_enabled_at" field.
func
(
u
*
UserUpsertBulk
)
ClearTotpEnabledAt
()
*
UserUpsertBulk
{
return
u
.
Update
(
func
(
s
*
UserUpsert
)
{
s
.
ClearTotpEnabledAt
()
})
}
// Exec executes the query.
func
(
u
*
UserUpsertBulk
)
Exec
(
ctx
context
.
Context
)
error
{
if
u
.
create
.
err
!=
nil
{
...
...
backend/ent/user_update.go
View file @
2fe8932c
...
...
@@ -187,6 +187,60 @@ func (_u *UserUpdate) SetNillableNotes(v *string) *UserUpdate {
return
_u
}
// SetTotpSecretEncrypted sets the "totp_secret_encrypted" field.
func
(
_u
*
UserUpdate
)
SetTotpSecretEncrypted
(
v
string
)
*
UserUpdate
{
_u
.
mutation
.
SetTotpSecretEncrypted
(
v
)
return
_u
}
// SetNillableTotpSecretEncrypted sets the "totp_secret_encrypted" field if the given value is not nil.
func
(
_u
*
UserUpdate
)
SetNillableTotpSecretEncrypted
(
v
*
string
)
*
UserUpdate
{
if
v
!=
nil
{
_u
.
SetTotpSecretEncrypted
(
*
v
)
}
return
_u
}
// ClearTotpSecretEncrypted clears the value of the "totp_secret_encrypted" field.
func
(
_u
*
UserUpdate
)
ClearTotpSecretEncrypted
()
*
UserUpdate
{
_u
.
mutation
.
ClearTotpSecretEncrypted
()
return
_u
}
// SetTotpEnabled sets the "totp_enabled" field.
func
(
_u
*
UserUpdate
)
SetTotpEnabled
(
v
bool
)
*
UserUpdate
{
_u
.
mutation
.
SetTotpEnabled
(
v
)
return
_u
}
// SetNillableTotpEnabled sets the "totp_enabled" field if the given value is not nil.
func
(
_u
*
UserUpdate
)
SetNillableTotpEnabled
(
v
*
bool
)
*
UserUpdate
{
if
v
!=
nil
{
_u
.
SetTotpEnabled
(
*
v
)
}
return
_u
}
// SetTotpEnabledAt sets the "totp_enabled_at" field.
func
(
_u
*
UserUpdate
)
SetTotpEnabledAt
(
v
time
.
Time
)
*
UserUpdate
{
_u
.
mutation
.
SetTotpEnabledAt
(
v
)
return
_u
}
// SetNillableTotpEnabledAt sets the "totp_enabled_at" field if the given value is not nil.
func
(
_u
*
UserUpdate
)
SetNillableTotpEnabledAt
(
v
*
time
.
Time
)
*
UserUpdate
{
if
v
!=
nil
{
_u
.
SetTotpEnabledAt
(
*
v
)
}
return
_u
}
// ClearTotpEnabledAt clears the value of the "totp_enabled_at" field.
func
(
_u
*
UserUpdate
)
ClearTotpEnabledAt
()
*
UserUpdate
{
_u
.
mutation
.
ClearTotpEnabledAt
()
return
_u
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func
(
_u
*
UserUpdate
)
AddAPIKeyIDs
(
ids
...
int64
)
*
UserUpdate
{
_u
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
...
...
@@ -603,6 +657,21 @@ func (_u *UserUpdate) sqlSave(ctx context.Context) (_node int, err error) {
if
value
,
ok
:=
_u
.
mutation
.
Notes
();
ok
{
_spec
.
SetField
(
user
.
FieldNotes
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
TotpSecretEncrypted
();
ok
{
_spec
.
SetField
(
user
.
FieldTotpSecretEncrypted
,
field
.
TypeString
,
value
)
}
if
_u
.
mutation
.
TotpSecretEncryptedCleared
()
{
_spec
.
ClearField
(
user
.
FieldTotpSecretEncrypted
,
field
.
TypeString
)
}
if
value
,
ok
:=
_u
.
mutation
.
TotpEnabled
();
ok
{
_spec
.
SetField
(
user
.
FieldTotpEnabled
,
field
.
TypeBool
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
TotpEnabledAt
();
ok
{
_spec
.
SetField
(
user
.
FieldTotpEnabledAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
TotpEnabledAtCleared
()
{
_spec
.
ClearField
(
user
.
FieldTotpEnabledAt
,
field
.
TypeTime
)
}
if
_u
.
mutation
.
APIKeysCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
...
...
@@ -1147,6 +1216,60 @@ func (_u *UserUpdateOne) SetNillableNotes(v *string) *UserUpdateOne {
return
_u
}
// SetTotpSecretEncrypted sets the "totp_secret_encrypted" field.
func
(
_u
*
UserUpdateOne
)
SetTotpSecretEncrypted
(
v
string
)
*
UserUpdateOne
{
_u
.
mutation
.
SetTotpSecretEncrypted
(
v
)
return
_u
}
// SetNillableTotpSecretEncrypted sets the "totp_secret_encrypted" field if the given value is not nil.
func
(
_u
*
UserUpdateOne
)
SetNillableTotpSecretEncrypted
(
v
*
string
)
*
UserUpdateOne
{
if
v
!=
nil
{
_u
.
SetTotpSecretEncrypted
(
*
v
)
}
return
_u
}
// ClearTotpSecretEncrypted clears the value of the "totp_secret_encrypted" field.
func
(
_u
*
UserUpdateOne
)
ClearTotpSecretEncrypted
()
*
UserUpdateOne
{
_u
.
mutation
.
ClearTotpSecretEncrypted
()
return
_u
}
// SetTotpEnabled sets the "totp_enabled" field.
func
(
_u
*
UserUpdateOne
)
SetTotpEnabled
(
v
bool
)
*
UserUpdateOne
{
_u
.
mutation
.
SetTotpEnabled
(
v
)
return
_u
}
// SetNillableTotpEnabled sets the "totp_enabled" field if the given value is not nil.
func
(
_u
*
UserUpdateOne
)
SetNillableTotpEnabled
(
v
*
bool
)
*
UserUpdateOne
{
if
v
!=
nil
{
_u
.
SetTotpEnabled
(
*
v
)
}
return
_u
}
// SetTotpEnabledAt sets the "totp_enabled_at" field.
func
(
_u
*
UserUpdateOne
)
SetTotpEnabledAt
(
v
time
.
Time
)
*
UserUpdateOne
{
_u
.
mutation
.
SetTotpEnabledAt
(
v
)
return
_u
}
// SetNillableTotpEnabledAt sets the "totp_enabled_at" field if the given value is not nil.
func
(
_u
*
UserUpdateOne
)
SetNillableTotpEnabledAt
(
v
*
time
.
Time
)
*
UserUpdateOne
{
if
v
!=
nil
{
_u
.
SetTotpEnabledAt
(
*
v
)
}
return
_u
}
// ClearTotpEnabledAt clears the value of the "totp_enabled_at" field.
func
(
_u
*
UserUpdateOne
)
ClearTotpEnabledAt
()
*
UserUpdateOne
{
_u
.
mutation
.
ClearTotpEnabledAt
()
return
_u
}
// AddAPIKeyIDs adds the "api_keys" edge to the APIKey entity by IDs.
func
(
_u
*
UserUpdateOne
)
AddAPIKeyIDs
(
ids
...
int64
)
*
UserUpdateOne
{
_u
.
mutation
.
AddAPIKeyIDs
(
ids
...
)
...
...
@@ -1593,6 +1716,21 @@ func (_u *UserUpdateOne) sqlSave(ctx context.Context) (_node *User, err error) {
if
value
,
ok
:=
_u
.
mutation
.
Notes
();
ok
{
_spec
.
SetField
(
user
.
FieldNotes
,
field
.
TypeString
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
TotpSecretEncrypted
();
ok
{
_spec
.
SetField
(
user
.
FieldTotpSecretEncrypted
,
field
.
TypeString
,
value
)
}
if
_u
.
mutation
.
TotpSecretEncryptedCleared
()
{
_spec
.
ClearField
(
user
.
FieldTotpSecretEncrypted
,
field
.
TypeString
)
}
if
value
,
ok
:=
_u
.
mutation
.
TotpEnabled
();
ok
{
_spec
.
SetField
(
user
.
FieldTotpEnabled
,
field
.
TypeBool
,
value
)
}
if
value
,
ok
:=
_u
.
mutation
.
TotpEnabledAt
();
ok
{
_spec
.
SetField
(
user
.
FieldTotpEnabledAt
,
field
.
TypeTime
,
value
)
}
if
_u
.
mutation
.
TotpEnabledAtCleared
()
{
_spec
.
ClearField
(
user
.
FieldTotpEnabledAt
,
field
.
TypeTime
)
}
if
_u
.
mutation
.
APIKeysCleared
()
{
edge
:=
&
sqlgraph
.
EdgeSpec
{
Rel
:
sqlgraph
.
O2M
,
...
...
backend/go.mod
View file @
2fe8932c
module github.com/Wei-Shaw/sub2api
go 1.25.
5
go 1.25.
6
require (
entgo.io/ent v0.14.5
...
...
@@ -31,11 +31,13 @@ require (
ariga.io/atlas v0.32.1-0.20250325101103-175b25e1c1b9 // indirect
dario.cat/mergo v1.0.2 // indirect
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/DATA-DOG/go-sqlmock v1.5.2 // indirect
github.com/Microsoft/go-winio v0.6.2 // indirect
github.com/agext/levenshtein v1.2.3 // indirect
github.com/andybalholm/brotli v1.2.0 // indirect
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
github.com/bmatcuk/doublestar v1.3.4 // indirect
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
github.com/bytedance/sonic v1.9.1 // indirect
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
...
...
@@ -97,6 +99,7 @@ require (
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/ncruces/go-strftime v1.0.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.1 // indirect
...
...
@@ -104,9 +107,11 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/pquerna/otp v1.5.0 // indirect
github.com/quic-go/qpack v0.6.0 // indirect
github.com/quic-go/quic-go v0.57.1 // indirect
github.com/refraction-networking/utls v1.8.1 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/robfig/cron/v3 v3.0.1 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
...
...
@@ -139,7 +144,7 @@ require (
go.uber.org/automaxprocs v1.6.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/exp v0.0.0-202
30905200255-921286631fa9
// indirect
golang.org/x/exp v0.0.0-202
51023183803-a4bb9ffd2546
// indirect
golang.org/x/mod v0.30.0 // indirect
golang.org/x/sys v0.39.0 // indirect
golang.org/x/text v0.32.0 // indirect
...
...
@@ -148,4 +153,8 @@ require (
google.golang.org/grpc v1.75.1 // indirect
google.golang.org/protobuf v1.36.10 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
modernc.org/libc v1.67.6 // indirect
modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.11.0 // indirect
modernc.org/sqlite v1.44.1 // indirect
)
backend/go.sum
View file @
2fe8932c
...
...
@@ -20,6 +20,8 @@ github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew
github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4=
github.com/bmatcuk/doublestar v1.3.4 h1:gPypJ5xD31uhX6Tf54sDPUOBXTqKH4c9aPY66CyQrS0=
github.com/bmatcuk/doublestar v1.3.4/go.mod h1:wiQtGV+rzVYxB7WIlirSN++5HPtPlXEo9MEoZQC/PmE=
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc h1:biVzkmvwrH8WK8raXaxBx6fRVTlJILwEwQGL1I/ByEI=
github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs=
github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c=
github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA=
...
...
@@ -141,6 +143,7 @@ github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kisielk/sqlstruct v0.0.0-20201105191214-5f3e10d3ab46/go.mod h1:yyMNCyc/Ib3bDTKd379tNMpB/7/H5TjM2Y9QJ5THLbE=
github.com/klauspost/compress v1.18.2 h1:iiPHWW0YrcFgpBYhsA6D1+fqHssJscY/Tm/y2Uqnapk=
github.com/klauspost/compress v1.18.2/go.mod h1:R0h/fSBs8DE4ENlcrlib3PsXS61voFxhIs2DeRhCvJ4=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
...
...
@@ -199,6 +202,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
...
...
@@ -214,6 +219,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF4JjgDlrVEn3C11VoGHZN7m8qihwgMEtzYw=
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
github.com/pquerna/otp v1.5.0 h1:NMMR+WrmaqXU4EzdGJEE1aUUI0AMRzsp96fFFWNPwxs=
github.com/pquerna/otp v1.5.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g=
github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U=
github.com/quic-go/qpack v0.6.0 h1:g7W+BMYynC1LbYLSqRt8PBg5Tgwxn214ZZR34VIOjz8=
...
...
@@ -224,6 +231,8 @@ github.com/redis/go-redis/v9 v9.17.2 h1:P2EGsA4qVIM3Pp+aPocCJ7DguDHhqrXNhVcEp4Vi
github.com/redis/go-redis/v9 v9.17.2/go.mod h1:u410H11HMLoB+TP67dz8rL9s6QW2j76l0//kSOd3370=
github.com/refraction-networking/utls v1.8.1 h1:yNY1kapmQU8JeM1sSw2H2asfTIwWxIkrMJI0pRUOCAo=
github.com/refraction-networking/utls v1.8.1/go.mod h1:jkSOEkLqn+S/jtpEHPOsVv/4V4EVnelwbMQl4vCWXAM=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
...
...
@@ -338,6 +347,8 @@ golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU=
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
golang.org/x/mod v0.30.0 h1:fDEXFVZ/fmCKProc/yAXXUijritrDzahmwwefnjoPFk=
golang.org/x/mod v0.30.0/go.mod h1:lAsf5O2EvJeSFMiBxXDki7sCgAxEUcZHXoXMKT4GJKc=
golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU=
...
...
@@ -365,6 +376,7 @@ golang.org/x/tools v0.39.0 h1:ik4ho21kwuQln40uelmciQPp9SipgNDdrafrYA4TmQQ=
golang.org/x/tools v0.39.0/go.mod h1:JnefbkDPyD8UU2kI5fuf8ZX4/yUeh9W877ZeBONxUqQ=
golang.org/x/tools/go/expect v0.1.0-deprecated h1:jY2C5HGYR5lqex3gEniOQL0r7Dq5+VGVgY1nudX5lXY=
golang.org/x/tools/go/expect v0.1.0-deprecated/go.mod h1:eihoPOH+FgIqa3FpoTwguz/bVUSGBlGQU67vpBeOrBY=
golang.org/x/tools/go/expect v0.1.1-deprecated h1:jpBZDwmgPhXsKZC6WhL20P4b/wmnpsEAGHaNy0n/rJM=
golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated h1:1h2MnaIAIXISqTFKdENegdpAgUXz6NrPEsbIeWaBRvM=
golang.org/x/tools/go/packages/packagestest v0.1.1-deprecated/go.mod h1:RVAQXBGNv1ib0J382/DPCRS/BPnsGebyM1Gj5VSDpG8=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
...
...
@@ -387,4 +399,12 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools/v3 v3.5.2 h1:7koQfIKdy+I8UTetycgUqXWSDwpgv193Ka+qRsmBY8Q=
gotest.tools/v3 v3.5.2/go.mod h1:LtdLGcnqToBH83WByAAi/wiwSFCArdFIUV/xxN4pcjA=
modernc.org/libc v1.67.6 h1:eVOQvpModVLKOdT+LvBPjdQqfrZq+pC39BygcT+E7OI=
modernc.org/libc v1.67.6/go.mod h1:JAhxUVlolfYDErnwiqaLvUqc8nfb2r6S6slAgZOnaiE=
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
modernc.org/sqlite v1.44.1 h1:qybx/rNpfQipX/t47OxbHmkkJuv2JWifCMH8SVUiDas=
modernc.org/sqlite v1.44.1/go.mod h1:CzbrU2lSB1DKUusvwGz7rqEKIq+NUd8GWuBBZDs9/nA=
rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4=
backend/internal/config/config.go
View file @
2fe8932c
...
...
@@ -47,6 +47,7 @@ type Config struct {
Redis
RedisConfig
`mapstructure:"redis"`
Ops
OpsConfig
`mapstructure:"ops"`
JWT
JWTConfig
`mapstructure:"jwt"`
Totp
TotpConfig
`mapstructure:"totp"`
LinuxDo
LinuxDoConnectConfig
`mapstructure:"linuxdo_connect"`
Default
DefaultConfig
`mapstructure:"default"`
RateLimit
RateLimitConfig
`mapstructure:"rate_limit"`
...
...
@@ -55,6 +56,7 @@ type Config struct {
APIKeyAuth
APIKeyAuthCacheConfig
`mapstructure:"api_key_auth_cache"`
Dashboard
DashboardCacheConfig
`mapstructure:"dashboard_cache"`
DashboardAgg
DashboardAggregationConfig
`mapstructure:"dashboard_aggregation"`
UsageCleanup
UsageCleanupConfig
`mapstructure:"usage_cleanup"`
Concurrency
ConcurrencyConfig
`mapstructure:"concurrency"`
TokenRefresh
TokenRefreshConfig
`mapstructure:"token_refresh"`
RunMode
string
`mapstructure:"run_mode" yaml:"run_mode"`
...
...
@@ -257,8 +259,43 @@ type GatewayConfig struct {
// 是否允许对部分 400 错误触发 failover(默认关闭以避免改变语义)
FailoverOn400
bool
`mapstructure:"failover_on_400"`
// 账户切换最大次数(遇到上游错误时切换到其他账户的次数上限)
MaxAccountSwitches
int
`mapstructure:"max_account_switches"`
// Gemini 账户切换最大次数(Gemini 平台单独配置,因 API 限制更严格)
MaxAccountSwitchesGemini
int
`mapstructure:"max_account_switches_gemini"`
// Antigravity 429 fallback 限流时间(分钟),解析重置时间失败时使用
AntigravityFallbackCooldownMinutes
int
`mapstructure:"antigravity_fallback_cooldown_minutes"`
// Scheduling: 账号调度相关配置
Scheduling
GatewaySchedulingConfig
`mapstructure:"scheduling"`
// TLSFingerprint: TLS指纹伪装配置
TLSFingerprint
TLSFingerprintConfig
`mapstructure:"tls_fingerprint"`
}
// TLSFingerprintConfig TLS指纹伪装配置
// 用于模拟 Claude CLI (Node.js) 的 TLS 握手特征,避免被识别为非官方客户端
type
TLSFingerprintConfig
struct
{
// Enabled: 是否全局启用TLS指纹功能
Enabled
bool
`mapstructure:"enabled"`
// Profiles: 预定义的TLS指纹配置模板
// key 为模板名称,如 "claude_cli_v2", "chrome_120" 等
Profiles
map
[
string
]
TLSProfileConfig
`mapstructure:"profiles"`
}
// TLSProfileConfig 单个TLS指纹模板的配置
type
TLSProfileConfig
struct
{
// Name: 模板显示名称
Name
string
`mapstructure:"name"`
// EnableGREASE: 是否启用GREASE扩展(Chrome使用,Node.js不使用)
EnableGREASE
bool
`mapstructure:"enable_grease"`
// CipherSuites: TLS加密套件列表(空则使用内置默认值)
CipherSuites
[]
uint16
`mapstructure:"cipher_suites"`
// Curves: 椭圆曲线列表(空则使用内置默认值)
Curves
[]
uint16
`mapstructure:"curves"`
// PointFormats: 点格式列表(空则使用内置默认值)
PointFormats
[]
uint8
`mapstructure:"point_formats"`
}
// GatewaySchedulingConfig accounts scheduling configuration.
...
...
@@ -271,6 +308,9 @@ type GatewaySchedulingConfig struct {
FallbackWaitTimeout
time
.
Duration
`mapstructure:"fallback_wait_timeout"`
FallbackMaxWaiting
int
`mapstructure:"fallback_max_waiting"`
// 兜底层账户选择策略: "last_used"(按最后使用时间排序,默认) 或 "random"(随机)
FallbackSelectionMode
string
`mapstructure:"fallback_selection_mode"`
// 负载计算
LoadBatchEnabled
bool
`mapstructure:"load_batch_enabled"`
...
...
@@ -427,6 +467,16 @@ type JWTConfig struct {
ExpireHour
int
`mapstructure:"expire_hour"`
}
// TotpConfig TOTP 双因素认证配置
type
TotpConfig
struct
{
// EncryptionKey 用于加密 TOTP 密钥的 AES-256 密钥(32 字节 hex 编码)
// 如果为空,将自动生成一个随机密钥(仅适用于开发环境)
EncryptionKey
string
`mapstructure:"encryption_key"`
// EncryptionKeyConfigured 标记加密密钥是否为手动配置(非自动生成)
// 只有手动配置了密钥才允许在管理后台启用 TOTP 功能
EncryptionKeyConfigured
bool
`mapstructure:"-"`
}
type
TurnstileConfig
struct
{
Required
bool
`mapstructure:"required"`
}
...
...
@@ -493,6 +543,20 @@ type DashboardAggregationRetentionConfig struct {
DailyDays
int
`mapstructure:"daily_days"`
}
// UsageCleanupConfig 使用记录清理任务配置
type
UsageCleanupConfig
struct
{
// Enabled: 是否启用清理任务执行器
Enabled
bool
`mapstructure:"enabled"`
// MaxRangeDays: 单次任务允许的最大时间跨度(天)
MaxRangeDays
int
`mapstructure:"max_range_days"`
// BatchSize: 单批删除数量
BatchSize
int
`mapstructure:"batch_size"`
// WorkerIntervalSeconds: 后台任务轮询间隔(秒)
WorkerIntervalSeconds
int
`mapstructure:"worker_interval_seconds"`
// TaskTimeoutSeconds: 单次任务最大执行时长(秒)
TaskTimeoutSeconds
int
`mapstructure:"task_timeout_seconds"`
}
func
NormalizeRunMode
(
value
string
)
string
{
normalized
:=
strings
.
ToLower
(
strings
.
TrimSpace
(
value
))
switch
normalized
{
...
...
@@ -573,6 +637,20 @@ func Load() (*Config, error) {
log
.
Println
(
"Warning: JWT secret auto-generated. Consider setting a fixed secret for production."
)
}
// Auto-generate TOTP encryption key if not set (32 bytes = 64 hex chars for AES-256)
cfg
.
Totp
.
EncryptionKey
=
strings
.
TrimSpace
(
cfg
.
Totp
.
EncryptionKey
)
if
cfg
.
Totp
.
EncryptionKey
==
""
{
key
,
err
:=
generateJWTSecret
(
32
)
// Reuse the same random generation function
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"generate totp encryption key error: %w"
,
err
)
}
cfg
.
Totp
.
EncryptionKey
=
key
cfg
.
Totp
.
EncryptionKeyConfigured
=
false
log
.
Println
(
"Warning: TOTP encryption key auto-generated. Consider setting a fixed key for production."
)
}
else
{
cfg
.
Totp
.
EncryptionKeyConfigured
=
true
}
if
err
:=
cfg
.
Validate
();
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"validate config error: %w"
,
err
)
}
...
...
@@ -703,6 +781,9 @@ func setDefaults() {
viper
.
SetDefault
(
"jwt.secret"
,
""
)
viper
.
SetDefault
(
"jwt.expire_hour"
,
24
)
// TOTP
viper
.
SetDefault
(
"totp.encryption_key"
,
""
)
// Default
// Admin credentials are created via the setup flow (web wizard / CLI / AUTO_SETUP).
// Do not ship fixed defaults here to avoid insecure "known credentials" in production.
...
...
@@ -753,12 +834,22 @@ func setDefaults() {
viper
.
SetDefault
(
"dashboard_aggregation.retention.daily_days"
,
730
)
viper
.
SetDefault
(
"dashboard_aggregation.recompute_days"
,
2
)
// Usage cleanup task
viper
.
SetDefault
(
"usage_cleanup.enabled"
,
true
)
viper
.
SetDefault
(
"usage_cleanup.max_range_days"
,
31
)
viper
.
SetDefault
(
"usage_cleanup.batch_size"
,
5000
)
viper
.
SetDefault
(
"usage_cleanup.worker_interval_seconds"
,
10
)
viper
.
SetDefault
(
"usage_cleanup.task_timeout_seconds"
,
1800
)
// Gateway
viper
.
SetDefault
(
"gateway.response_header_timeout"
,
600
)
// 600秒(10分钟)等待上游响应头,LLM高负载时可能排队较久
viper
.
SetDefault
(
"gateway.log_upstream_error_body"
,
true
)
viper
.
SetDefault
(
"gateway.log_upstream_error_body_max_bytes"
,
2048
)
viper
.
SetDefault
(
"gateway.inject_beta_for_apikey"
,
false
)
viper
.
SetDefault
(
"gateway.failover_on_400"
,
false
)
viper
.
SetDefault
(
"gateway.max_account_switches"
,
10
)
viper
.
SetDefault
(
"gateway.max_account_switches_gemini"
,
3
)
viper
.
SetDefault
(
"gateway.antigravity_fallback_cooldown_minutes"
,
1
)
viper
.
SetDefault
(
"gateway.max_body_size"
,
int64
(
100
*
1024
*
1024
))
viper
.
SetDefault
(
"gateway.connection_pool_isolation"
,
ConnectionPoolIsolationAccountProxy
)
// HTTP 上游连接池配置(针对 5000+ 并发用户优化)
...
...
@@ -771,11 +862,12 @@ func setDefaults() {
viper
.
SetDefault
(
"gateway.concurrency_slot_ttl_minutes"
,
30
)
// 并发槽位过期时间(支持超长请求)
viper
.
SetDefault
(
"gateway.stream_data_interval_timeout"
,
180
)
viper
.
SetDefault
(
"gateway.stream_keepalive_interval"
,
10
)
viper
.
SetDefault
(
"gateway.max_line_size"
,
1
0
*
1024
*
1024
)
viper
.
SetDefault
(
"gateway.max_line_size"
,
4
0
*
1024
*
1024
)
viper
.
SetDefault
(
"gateway.scheduling.sticky_session_max_waiting"
,
3
)
viper
.
SetDefault
(
"gateway.scheduling.sticky_session_wait_timeout"
,
120
*
time
.
Second
)
viper
.
SetDefault
(
"gateway.scheduling.fallback_wait_timeout"
,
30
*
time
.
Second
)
viper
.
SetDefault
(
"gateway.scheduling.fallback_max_waiting"
,
100
)
viper
.
SetDefault
(
"gateway.scheduling.fallback_selection_mode"
,
"last_used"
)
viper
.
SetDefault
(
"gateway.scheduling.load_batch_enabled"
,
true
)
viper
.
SetDefault
(
"gateway.scheduling.slot_cleanup_interval"
,
30
*
time
.
Second
)
viper
.
SetDefault
(
"gateway.scheduling.db_fallback_enabled"
,
true
)
...
...
@@ -787,6 +879,8 @@ func setDefaults() {
viper
.
SetDefault
(
"gateway.scheduling.outbox_lag_rebuild_failures"
,
3
)
viper
.
SetDefault
(
"gateway.scheduling.outbox_backlog_rebuild_rows"
,
10000
)
viper
.
SetDefault
(
"gateway.scheduling.full_rebuild_interval_seconds"
,
300
)
// TLS指纹伪装配置(默认关闭,需要账号级别单独启用)
viper
.
SetDefault
(
"gateway.tls_fingerprint.enabled"
,
true
)
viper
.
SetDefault
(
"concurrency.ping_interval"
,
10
)
// TokenRefresh
...
...
@@ -989,6 +1083,33 @@ func (c *Config) Validate() error {
return
fmt
.
Errorf
(
"dashboard_aggregation.recompute_days must be non-negative"
)
}
}
if
c
.
UsageCleanup
.
Enabled
{
if
c
.
UsageCleanup
.
MaxRangeDays
<=
0
{
return
fmt
.
Errorf
(
"usage_cleanup.max_range_days must be positive"
)
}
if
c
.
UsageCleanup
.
BatchSize
<=
0
{
return
fmt
.
Errorf
(
"usage_cleanup.batch_size must be positive"
)
}
if
c
.
UsageCleanup
.
WorkerIntervalSeconds
<=
0
{
return
fmt
.
Errorf
(
"usage_cleanup.worker_interval_seconds must be positive"
)
}
if
c
.
UsageCleanup
.
TaskTimeoutSeconds
<=
0
{
return
fmt
.
Errorf
(
"usage_cleanup.task_timeout_seconds must be positive"
)
}
}
else
{
if
c
.
UsageCleanup
.
MaxRangeDays
<
0
{
return
fmt
.
Errorf
(
"usage_cleanup.max_range_days must be non-negative"
)
}
if
c
.
UsageCleanup
.
BatchSize
<
0
{
return
fmt
.
Errorf
(
"usage_cleanup.batch_size must be non-negative"
)
}
if
c
.
UsageCleanup
.
WorkerIntervalSeconds
<
0
{
return
fmt
.
Errorf
(
"usage_cleanup.worker_interval_seconds must be non-negative"
)
}
if
c
.
UsageCleanup
.
TaskTimeoutSeconds
<
0
{
return
fmt
.
Errorf
(
"usage_cleanup.task_timeout_seconds must be non-negative"
)
}
}
if
c
.
Gateway
.
MaxBodySize
<=
0
{
return
fmt
.
Errorf
(
"gateway.max_body_size must be positive"
)
}
...
...
backend/internal/config/config_test.go
View file @
2fe8932c
...
...
@@ -280,3 +280,573 @@ func TestValidateDashboardAggregationBackfillMaxDays(t *testing.T) {
t
.
Fatalf
(
"Validate() expected backfill_max_days error, got: %v"
,
err
)
}
}
func
TestLoadDefaultUsageCleanupConfig
(
t
*
testing
.
T
)
{
viper
.
Reset
()
cfg
,
err
:=
Load
()
if
err
!=
nil
{
t
.
Fatalf
(
"Load() error: %v"
,
err
)
}
if
!
cfg
.
UsageCleanup
.
Enabled
{
t
.
Fatalf
(
"UsageCleanup.Enabled = false, want true"
)
}
if
cfg
.
UsageCleanup
.
MaxRangeDays
!=
31
{
t
.
Fatalf
(
"UsageCleanup.MaxRangeDays = %d, want 31"
,
cfg
.
UsageCleanup
.
MaxRangeDays
)
}
if
cfg
.
UsageCleanup
.
BatchSize
!=
5000
{
t
.
Fatalf
(
"UsageCleanup.BatchSize = %d, want 5000"
,
cfg
.
UsageCleanup
.
BatchSize
)
}
if
cfg
.
UsageCleanup
.
WorkerIntervalSeconds
!=
10
{
t
.
Fatalf
(
"UsageCleanup.WorkerIntervalSeconds = %d, want 10"
,
cfg
.
UsageCleanup
.
WorkerIntervalSeconds
)
}
if
cfg
.
UsageCleanup
.
TaskTimeoutSeconds
!=
1800
{
t
.
Fatalf
(
"UsageCleanup.TaskTimeoutSeconds = %d, want 1800"
,
cfg
.
UsageCleanup
.
TaskTimeoutSeconds
)
}
}
func
TestValidateUsageCleanupConfigEnabled
(
t
*
testing
.
T
)
{
viper
.
Reset
()
cfg
,
err
:=
Load
()
if
err
!=
nil
{
t
.
Fatalf
(
"Load() error: %v"
,
err
)
}
cfg
.
UsageCleanup
.
Enabled
=
true
cfg
.
UsageCleanup
.
MaxRangeDays
=
0
err
=
cfg
.
Validate
()
if
err
==
nil
{
t
.
Fatalf
(
"Validate() expected error for usage_cleanup.max_range_days, got nil"
)
}
if
!
strings
.
Contains
(
err
.
Error
(),
"usage_cleanup.max_range_days"
)
{
t
.
Fatalf
(
"Validate() expected max_range_days error, got: %v"
,
err
)
}
}
func
TestValidateUsageCleanupConfigDisabled
(
t
*
testing
.
T
)
{
viper
.
Reset
()
cfg
,
err
:=
Load
()
if
err
!=
nil
{
t
.
Fatalf
(
"Load() error: %v"
,
err
)
}
cfg
.
UsageCleanup
.
Enabled
=
false
cfg
.
UsageCleanup
.
BatchSize
=
-
1
err
=
cfg
.
Validate
()
if
err
==
nil
{
t
.
Fatalf
(
"Validate() expected error for usage_cleanup.batch_size, got nil"
)
}
if
!
strings
.
Contains
(
err
.
Error
(),
"usage_cleanup.batch_size"
)
{
t
.
Fatalf
(
"Validate() expected batch_size error, got: %v"
,
err
)
}
}
func
TestConfigAddressHelpers
(
t
*
testing
.
T
)
{
server
:=
ServerConfig
{
Host
:
"127.0.0.1"
,
Port
:
9000
}
if
server
.
Address
()
!=
"127.0.0.1:9000"
{
t
.
Fatalf
(
"ServerConfig.Address() = %q"
,
server
.
Address
())
}
dbCfg
:=
DatabaseConfig
{
Host
:
"localhost"
,
Port
:
5432
,
User
:
"postgres"
,
Password
:
""
,
DBName
:
"sub2api"
,
SSLMode
:
"disable"
,
}
if
!
strings
.
Contains
(
dbCfg
.
DSN
(),
"password="
)
{
}
else
{
t
.
Fatalf
(
"DatabaseConfig.DSN() should not include password when empty"
)
}
dbCfg
.
Password
=
"secret"
if
!
strings
.
Contains
(
dbCfg
.
DSN
(),
"password=secret"
)
{
t
.
Fatalf
(
"DatabaseConfig.DSN() missing password"
)
}
dbCfg
.
Password
=
""
if
strings
.
Contains
(
dbCfg
.
DSNWithTimezone
(
"UTC"
),
"password="
)
{
t
.
Fatalf
(
"DatabaseConfig.DSNWithTimezone() should omit password when empty"
)
}
if
!
strings
.
Contains
(
dbCfg
.
DSNWithTimezone
(
""
),
"TimeZone=Asia/Shanghai"
)
{
t
.
Fatalf
(
"DatabaseConfig.DSNWithTimezone() should use default timezone"
)
}
if
!
strings
.
Contains
(
dbCfg
.
DSNWithTimezone
(
"UTC"
),
"TimeZone=UTC"
)
{
t
.
Fatalf
(
"DatabaseConfig.DSNWithTimezone() should use provided timezone"
)
}
redis
:=
RedisConfig
{
Host
:
"redis"
,
Port
:
6379
}
if
redis
.
Address
()
!=
"redis:6379"
{
t
.
Fatalf
(
"RedisConfig.Address() = %q"
,
redis
.
Address
())
}
}
func
TestNormalizeStringSlice
(
t
*
testing
.
T
)
{
values
:=
normalizeStringSlice
([]
string
{
" a "
,
""
,
"b"
,
" "
,
"c"
})
if
len
(
values
)
!=
3
||
values
[
0
]
!=
"a"
||
values
[
1
]
!=
"b"
||
values
[
2
]
!=
"c"
{
t
.
Fatalf
(
"normalizeStringSlice() unexpected result: %#v"
,
values
)
}
if
normalizeStringSlice
(
nil
)
!=
nil
{
t
.
Fatalf
(
"normalizeStringSlice(nil) expected nil slice"
)
}
}
func
TestGetServerAddressFromEnv
(
t
*
testing
.
T
)
{
t
.
Setenv
(
"SERVER_HOST"
,
"127.0.0.1"
)
t
.
Setenv
(
"SERVER_PORT"
,
"9090"
)
address
:=
GetServerAddress
()
if
address
!=
"127.0.0.1:9090"
{
t
.
Fatalf
(
"GetServerAddress() = %q"
,
address
)
}
}
func
TestValidateAbsoluteHTTPURL
(
t
*
testing
.
T
)
{
if
err
:=
ValidateAbsoluteHTTPURL
(
"https://example.com/path"
);
err
!=
nil
{
t
.
Fatalf
(
"ValidateAbsoluteHTTPURL valid url error: %v"
,
err
)
}
if
err
:=
ValidateAbsoluteHTTPURL
(
""
);
err
==
nil
{
t
.
Fatalf
(
"ValidateAbsoluteHTTPURL should reject empty url"
)
}
if
err
:=
ValidateAbsoluteHTTPURL
(
"/relative"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateAbsoluteHTTPURL should reject relative url"
)
}
if
err
:=
ValidateAbsoluteHTTPURL
(
"ftp://example.com"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateAbsoluteHTTPURL should reject ftp scheme"
)
}
if
err
:=
ValidateAbsoluteHTTPURL
(
"https://example.com/#frag"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateAbsoluteHTTPURL should reject fragment"
)
}
}
func
TestValidateFrontendRedirectURL
(
t
*
testing
.
T
)
{
if
err
:=
ValidateFrontendRedirectURL
(
"/auth/callback"
);
err
!=
nil
{
t
.
Fatalf
(
"ValidateFrontendRedirectURL relative error: %v"
,
err
)
}
if
err
:=
ValidateFrontendRedirectURL
(
"https://example.com/auth"
);
err
!=
nil
{
t
.
Fatalf
(
"ValidateFrontendRedirectURL absolute error: %v"
,
err
)
}
if
err
:=
ValidateFrontendRedirectURL
(
"example.com/path"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateFrontendRedirectURL should reject non-absolute url"
)
}
if
err
:=
ValidateFrontendRedirectURL
(
"//evil.com"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateFrontendRedirectURL should reject // prefix"
)
}
if
err
:=
ValidateFrontendRedirectURL
(
"javascript:alert(1)"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateFrontendRedirectURL should reject javascript scheme"
)
}
}
func
TestWarnIfInsecureURL
(
t
*
testing
.
T
)
{
warnIfInsecureURL
(
"test"
,
"http://example.com"
)
warnIfInsecureURL
(
"test"
,
"bad://url"
)
}
func
TestGenerateJWTSecretDefaultLength
(
t
*
testing
.
T
)
{
secret
,
err
:=
generateJWTSecret
(
0
)
if
err
!=
nil
{
t
.
Fatalf
(
"generateJWTSecret error: %v"
,
err
)
}
if
len
(
secret
)
==
0
{
t
.
Fatalf
(
"generateJWTSecret returned empty string"
)
}
}
func
TestValidateOpsCleanupScheduleRequired
(
t
*
testing
.
T
)
{
viper
.
Reset
()
cfg
,
err
:=
Load
()
if
err
!=
nil
{
t
.
Fatalf
(
"Load() error: %v"
,
err
)
}
cfg
.
Ops
.
Cleanup
.
Enabled
=
true
cfg
.
Ops
.
Cleanup
.
Schedule
=
""
err
=
cfg
.
Validate
()
if
err
==
nil
{
t
.
Fatalf
(
"Validate() expected error for ops.cleanup.schedule"
)
}
if
!
strings
.
Contains
(
err
.
Error
(),
"ops.cleanup.schedule"
)
{
t
.
Fatalf
(
"Validate() expected ops.cleanup.schedule error, got: %v"
,
err
)
}
}
func
TestValidateConcurrencyPingInterval
(
t
*
testing
.
T
)
{
viper
.
Reset
()
cfg
,
err
:=
Load
()
if
err
!=
nil
{
t
.
Fatalf
(
"Load() error: %v"
,
err
)
}
cfg
.
Concurrency
.
PingInterval
=
3
err
=
cfg
.
Validate
()
if
err
==
nil
{
t
.
Fatalf
(
"Validate() expected error for concurrency.ping_interval"
)
}
if
!
strings
.
Contains
(
err
.
Error
(),
"concurrency.ping_interval"
)
{
t
.
Fatalf
(
"Validate() expected concurrency.ping_interval error, got: %v"
,
err
)
}
}
func
TestProvideConfig
(
t
*
testing
.
T
)
{
viper
.
Reset
()
if
_
,
err
:=
ProvideConfig
();
err
!=
nil
{
t
.
Fatalf
(
"ProvideConfig() error: %v"
,
err
)
}
}
func
TestValidateConfigWithLinuxDoEnabled
(
t
*
testing
.
T
)
{
viper
.
Reset
()
cfg
,
err
:=
Load
()
if
err
!=
nil
{
t
.
Fatalf
(
"Load() error: %v"
,
err
)
}
cfg
.
Security
.
CSP
.
Enabled
=
true
cfg
.
Security
.
CSP
.
Policy
=
"default-src 'self'"
cfg
.
LinuxDo
.
Enabled
=
true
cfg
.
LinuxDo
.
ClientID
=
"client"
cfg
.
LinuxDo
.
ClientSecret
=
"secret"
cfg
.
LinuxDo
.
AuthorizeURL
=
"https://example.com/oauth2/authorize"
cfg
.
LinuxDo
.
TokenURL
=
"https://example.com/oauth2/token"
cfg
.
LinuxDo
.
UserInfoURL
=
"https://example.com/oauth2/userinfo"
cfg
.
LinuxDo
.
RedirectURL
=
"https://example.com/api/v1/auth/oauth/linuxdo/callback"
cfg
.
LinuxDo
.
FrontendRedirectURL
=
"/auth/linuxdo/callback"
cfg
.
LinuxDo
.
TokenAuthMethod
=
"client_secret_post"
if
err
:=
cfg
.
Validate
();
err
!=
nil
{
t
.
Fatalf
(
"Validate() unexpected error: %v"
,
err
)
}
}
func
TestValidateJWTSecretStrength
(
t
*
testing
.
T
)
{
if
!
isWeakJWTSecret
(
"change-me-in-production"
)
{
t
.
Fatalf
(
"isWeakJWTSecret should detect weak secret"
)
}
if
isWeakJWTSecret
(
"StrongSecretValue"
)
{
t
.
Fatalf
(
"isWeakJWTSecret should accept strong secret"
)
}
}
func
TestGenerateJWTSecretWithLength
(
t
*
testing
.
T
)
{
secret
,
err
:=
generateJWTSecret
(
16
)
if
err
!=
nil
{
t
.
Fatalf
(
"generateJWTSecret error: %v"
,
err
)
}
if
len
(
secret
)
==
0
{
t
.
Fatalf
(
"generateJWTSecret returned empty string"
)
}
}
func
TestValidateAbsoluteHTTPURLMissingHost
(
t
*
testing
.
T
)
{
if
err
:=
ValidateAbsoluteHTTPURL
(
"https://"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateAbsoluteHTTPURL should reject missing host"
)
}
}
func
TestValidateFrontendRedirectURLInvalidChars
(
t
*
testing
.
T
)
{
if
err
:=
ValidateFrontendRedirectURL
(
"/auth/
\n
callback"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateFrontendRedirectURL should reject invalid chars"
)
}
if
err
:=
ValidateFrontendRedirectURL
(
"http://"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateFrontendRedirectURL should reject missing host"
)
}
if
err
:=
ValidateFrontendRedirectURL
(
"mailto:user@example.com"
);
err
==
nil
{
t
.
Fatalf
(
"ValidateFrontendRedirectURL should reject mailto"
)
}
}
func
TestWarnIfInsecureURLHTTPS
(
t
*
testing
.
T
)
{
warnIfInsecureURL
(
"secure"
,
"https://example.com"
)
}
func
TestValidateConfigErrors
(
t
*
testing
.
T
)
{
buildValid
:=
func
(
t
*
testing
.
T
)
*
Config
{
t
.
Helper
()
viper
.
Reset
()
cfg
,
err
:=
Load
()
if
err
!=
nil
{
t
.
Fatalf
(
"Load() error: %v"
,
err
)
}
return
cfg
}
cases
:=
[]
struct
{
name
string
mutate
func
(
*
Config
)
wantErr
string
}{
{
name
:
"jwt expire hour positive"
,
mutate
:
func
(
c
*
Config
)
{
c
.
JWT
.
ExpireHour
=
0
},
wantErr
:
"jwt.expire_hour must be positive"
,
},
{
name
:
"jwt expire hour max"
,
mutate
:
func
(
c
*
Config
)
{
c
.
JWT
.
ExpireHour
=
200
},
wantErr
:
"jwt.expire_hour must be <= 168"
,
},
{
name
:
"csp policy required"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Security
.
CSP
.
Enabled
=
true
;
c
.
Security
.
CSP
.
Policy
=
""
},
wantErr
:
"security.csp.policy"
,
},
{
name
:
"linuxdo client id required"
,
mutate
:
func
(
c
*
Config
)
{
c
.
LinuxDo
.
Enabled
=
true
c
.
LinuxDo
.
ClientID
=
""
},
wantErr
:
"linuxdo_connect.client_id"
,
},
{
name
:
"linuxdo token auth method"
,
mutate
:
func
(
c
*
Config
)
{
c
.
LinuxDo
.
Enabled
=
true
c
.
LinuxDo
.
ClientID
=
"client"
c
.
LinuxDo
.
ClientSecret
=
"secret"
c
.
LinuxDo
.
AuthorizeURL
=
"https://example.com/authorize"
c
.
LinuxDo
.
TokenURL
=
"https://example.com/token"
c
.
LinuxDo
.
UserInfoURL
=
"https://example.com/userinfo"
c
.
LinuxDo
.
RedirectURL
=
"https://example.com/callback"
c
.
LinuxDo
.
FrontendRedirectURL
=
"/auth/callback"
c
.
LinuxDo
.
TokenAuthMethod
=
"invalid"
},
wantErr
:
"linuxdo_connect.token_auth_method"
,
},
{
name
:
"billing circuit breaker threshold"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Billing
.
CircuitBreaker
.
FailureThreshold
=
0
},
wantErr
:
"billing.circuit_breaker.failure_threshold"
,
},
{
name
:
"billing circuit breaker reset"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Billing
.
CircuitBreaker
.
ResetTimeoutSeconds
=
0
},
wantErr
:
"billing.circuit_breaker.reset_timeout_seconds"
,
},
{
name
:
"billing circuit breaker half open"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Billing
.
CircuitBreaker
.
HalfOpenRequests
=
0
},
wantErr
:
"billing.circuit_breaker.half_open_requests"
,
},
{
name
:
"database max open conns"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Database
.
MaxOpenConns
=
0
},
wantErr
:
"database.max_open_conns"
,
},
{
name
:
"database max lifetime"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Database
.
ConnMaxLifetimeMinutes
=
-
1
},
wantErr
:
"database.conn_max_lifetime_minutes"
,
},
{
name
:
"database idle exceeds open"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Database
.
MaxIdleConns
=
c
.
Database
.
MaxOpenConns
+
1
},
wantErr
:
"database.max_idle_conns cannot exceed"
,
},
{
name
:
"redis dial timeout"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Redis
.
DialTimeoutSeconds
=
0
},
wantErr
:
"redis.dial_timeout_seconds"
,
},
{
name
:
"redis read timeout"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Redis
.
ReadTimeoutSeconds
=
0
},
wantErr
:
"redis.read_timeout_seconds"
,
},
{
name
:
"redis write timeout"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Redis
.
WriteTimeoutSeconds
=
0
},
wantErr
:
"redis.write_timeout_seconds"
,
},
{
name
:
"redis pool size"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Redis
.
PoolSize
=
0
},
wantErr
:
"redis.pool_size"
,
},
{
name
:
"redis idle exceeds pool"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Redis
.
MinIdleConns
=
c
.
Redis
.
PoolSize
+
1
},
wantErr
:
"redis.min_idle_conns cannot exceed"
,
},
{
name
:
"dashboard cache disabled negative"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Dashboard
.
Enabled
=
false
;
c
.
Dashboard
.
StatsTTLSeconds
=
-
1
},
wantErr
:
"dashboard_cache.stats_ttl_seconds"
,
},
{
name
:
"dashboard cache fresh ttl positive"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Dashboard
.
Enabled
=
true
;
c
.
Dashboard
.
StatsFreshTTLSeconds
=
0
},
wantErr
:
"dashboard_cache.stats_fresh_ttl_seconds"
,
},
{
name
:
"dashboard aggregation enabled interval"
,
mutate
:
func
(
c
*
Config
)
{
c
.
DashboardAgg
.
Enabled
=
true
;
c
.
DashboardAgg
.
IntervalSeconds
=
0
},
wantErr
:
"dashboard_aggregation.interval_seconds"
,
},
{
name
:
"dashboard aggregation backfill positive"
,
mutate
:
func
(
c
*
Config
)
{
c
.
DashboardAgg
.
Enabled
=
true
c
.
DashboardAgg
.
BackfillEnabled
=
true
c
.
DashboardAgg
.
BackfillMaxDays
=
0
},
wantErr
:
"dashboard_aggregation.backfill_max_days"
,
},
{
name
:
"dashboard aggregation retention"
,
mutate
:
func
(
c
*
Config
)
{
c
.
DashboardAgg
.
Enabled
=
true
;
c
.
DashboardAgg
.
Retention
.
UsageLogsDays
=
0
},
wantErr
:
"dashboard_aggregation.retention.usage_logs_days"
,
},
{
name
:
"dashboard aggregation disabled interval"
,
mutate
:
func
(
c
*
Config
)
{
c
.
DashboardAgg
.
Enabled
=
false
;
c
.
DashboardAgg
.
IntervalSeconds
=
-
1
},
wantErr
:
"dashboard_aggregation.interval_seconds"
,
},
{
name
:
"usage cleanup max range"
,
mutate
:
func
(
c
*
Config
)
{
c
.
UsageCleanup
.
Enabled
=
true
;
c
.
UsageCleanup
.
MaxRangeDays
=
0
},
wantErr
:
"usage_cleanup.max_range_days"
,
},
{
name
:
"usage cleanup worker interval"
,
mutate
:
func
(
c
*
Config
)
{
c
.
UsageCleanup
.
Enabled
=
true
;
c
.
UsageCleanup
.
WorkerIntervalSeconds
=
0
},
wantErr
:
"usage_cleanup.worker_interval_seconds"
,
},
{
name
:
"usage cleanup batch size"
,
mutate
:
func
(
c
*
Config
)
{
c
.
UsageCleanup
.
Enabled
=
true
;
c
.
UsageCleanup
.
BatchSize
=
0
},
wantErr
:
"usage_cleanup.batch_size"
,
},
{
name
:
"usage cleanup disabled negative"
,
mutate
:
func
(
c
*
Config
)
{
c
.
UsageCleanup
.
Enabled
=
false
;
c
.
UsageCleanup
.
BatchSize
=
-
1
},
wantErr
:
"usage_cleanup.batch_size"
,
},
{
name
:
"gateway max body size"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
MaxBodySize
=
0
},
wantErr
:
"gateway.max_body_size"
,
},
{
name
:
"gateway max idle conns"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
MaxIdleConns
=
0
},
wantErr
:
"gateway.max_idle_conns"
,
},
{
name
:
"gateway max idle conns per host"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
MaxIdleConnsPerHost
=
0
},
wantErr
:
"gateway.max_idle_conns_per_host"
,
},
{
name
:
"gateway idle timeout"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
IdleConnTimeoutSeconds
=
0
},
wantErr
:
"gateway.idle_conn_timeout_seconds"
,
},
{
name
:
"gateway max upstream clients"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
MaxUpstreamClients
=
0
},
wantErr
:
"gateway.max_upstream_clients"
,
},
{
name
:
"gateway client idle ttl"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
ClientIdleTTLSeconds
=
0
},
wantErr
:
"gateway.client_idle_ttl_seconds"
,
},
{
name
:
"gateway concurrency slot ttl"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
ConcurrencySlotTTLMinutes
=
0
},
wantErr
:
"gateway.concurrency_slot_ttl_minutes"
,
},
{
name
:
"gateway max conns per host"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
MaxConnsPerHost
=
-
1
},
wantErr
:
"gateway.max_conns_per_host"
,
},
{
name
:
"gateway connection isolation"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
ConnectionPoolIsolation
=
"invalid"
},
wantErr
:
"gateway.connection_pool_isolation"
,
},
{
name
:
"gateway stream keepalive range"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
StreamKeepaliveInterval
=
4
},
wantErr
:
"gateway.stream_keepalive_interval"
,
},
{
name
:
"gateway stream data interval range"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
StreamDataIntervalTimeout
=
5
},
wantErr
:
"gateway.stream_data_interval_timeout"
,
},
{
name
:
"gateway stream data interval negative"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
StreamDataIntervalTimeout
=
-
1
},
wantErr
:
"gateway.stream_data_interval_timeout must be non-negative"
,
},
{
name
:
"gateway max line size"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
MaxLineSize
=
1024
},
wantErr
:
"gateway.max_line_size must be at least"
,
},
{
name
:
"gateway max line size negative"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
MaxLineSize
=
-
1
},
wantErr
:
"gateway.max_line_size must be non-negative"
,
},
{
name
:
"gateway scheduling sticky waiting"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
Scheduling
.
StickySessionMaxWaiting
=
0
},
wantErr
:
"gateway.scheduling.sticky_session_max_waiting"
,
},
{
name
:
"gateway scheduling outbox poll"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
Scheduling
.
OutboxPollIntervalSeconds
=
0
},
wantErr
:
"gateway.scheduling.outbox_poll_interval_seconds"
,
},
{
name
:
"gateway scheduling outbox failures"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
Scheduling
.
OutboxLagRebuildFailures
=
0
},
wantErr
:
"gateway.scheduling.outbox_lag_rebuild_failures"
,
},
{
name
:
"gateway outbox lag rebuild"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Gateway
.
Scheduling
.
OutboxLagWarnSeconds
=
10
c
.
Gateway
.
Scheduling
.
OutboxLagRebuildSeconds
=
5
},
wantErr
:
"gateway.scheduling.outbox_lag_rebuild_seconds"
,
},
{
name
:
"ops metrics collector ttl"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Ops
.
MetricsCollectorCache
.
TTL
=
-
1
},
wantErr
:
"ops.metrics_collector_cache.ttl"
,
},
{
name
:
"ops cleanup retention"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Ops
.
Cleanup
.
ErrorLogRetentionDays
=
-
1
},
wantErr
:
"ops.cleanup.error_log_retention_days"
,
},
{
name
:
"ops cleanup minute retention"
,
mutate
:
func
(
c
*
Config
)
{
c
.
Ops
.
Cleanup
.
MinuteMetricsRetentionDays
=
-
1
},
wantErr
:
"ops.cleanup.minute_metrics_retention_days"
,
},
}
for
_
,
tt
:=
range
cases
{
t
.
Run
(
tt
.
name
,
func
(
t
*
testing
.
T
)
{
cfg
:=
buildValid
(
t
)
tt
.
mutate
(
cfg
)
err
:=
cfg
.
Validate
()
if
err
==
nil
||
!
strings
.
Contains
(
err
.
Error
(),
tt
.
wantErr
)
{
t
.
Fatalf
(
"Validate() error = %v, want %q"
,
err
,
tt
.
wantErr
)
}
})
}
}
backend/internal/handler/admin/account_handler.go
View file @
2fe8932c
...
...
@@ -45,6 +45,7 @@ type AccountHandler struct {
concurrencyService
*
service
.
ConcurrencyService
crsSyncService
*
service
.
CRSSyncService
sessionLimitCache
service
.
SessionLimitCache
tokenCacheInvalidator
service
.
TokenCacheInvalidator
}
// NewAccountHandler creates a new admin account handler
...
...
@@ -60,6 +61,7 @@ func NewAccountHandler(
concurrencyService
*
service
.
ConcurrencyService
,
crsSyncService
*
service
.
CRSSyncService
,
sessionLimitCache
service
.
SessionLimitCache
,
tokenCacheInvalidator
service
.
TokenCacheInvalidator
,
)
*
AccountHandler
{
return
&
AccountHandler
{
adminService
:
adminService
,
...
...
@@ -73,6 +75,7 @@ func NewAccountHandler(
concurrencyService
:
concurrencyService
,
crsSyncService
:
crsSyncService
,
sessionLimitCache
:
sessionLimitCache
,
tokenCacheInvalidator
:
tokenCacheInvalidator
,
}
}
...
...
@@ -173,6 +176,7 @@ func (h *AccountHandler) List(c *gin.Context) {
// 识别需要查询窗口费用和会话数的账号(Anthropic OAuth/SetupToken 且启用了相应功能)
windowCostAccountIDs
:=
make
([]
int64
,
0
)
sessionLimitAccountIDs
:=
make
([]
int64
,
0
)
sessionIdleTimeouts
:=
make
(
map
[
int64
]
time
.
Duration
)
// 各账号的会话空闲超时配置
for
i
:=
range
accounts
{
acc
:=
&
accounts
[
i
]
if
acc
.
IsAnthropicOAuthOrSetupToken
()
{
...
...
@@ -181,6 +185,7 @@ func (h *AccountHandler) List(c *gin.Context) {
}
if
acc
.
GetMaxSessions
()
>
0
{
sessionLimitAccountIDs
=
append
(
sessionLimitAccountIDs
,
acc
.
ID
)
sessionIdleTimeouts
[
acc
.
ID
]
=
time
.
Duration
(
acc
.
GetSessionIdleTimeoutMinutes
())
*
time
.
Minute
}
}
}
...
...
@@ -189,9 +194,9 @@ func (h *AccountHandler) List(c *gin.Context) {
var
windowCosts
map
[
int64
]
float64
var
activeSessions
map
[
int64
]
int
// 获取活跃会话数(批量查询)
// 获取活跃会话数(批量查询
,传入各账号的 idleTimeout 配置
)
if
len
(
sessionLimitAccountIDs
)
>
0
&&
h
.
sessionLimitCache
!=
nil
{
activeSessions
,
_
=
h
.
sessionLimitCache
.
GetActiveSessionCountBatch
(
c
.
Request
.
Context
(),
sessionLimitAccountIDs
)
activeSessions
,
_
=
h
.
sessionLimitCache
.
GetActiveSessionCountBatch
(
c
.
Request
.
Context
(),
sessionLimitAccountIDs
,
sessionIdleTimeouts
)
if
activeSessions
==
nil
{
activeSessions
=
make
(
map
[
int64
]
int
)
}
...
...
@@ -211,12 +216,8 @@ func (h *AccountHandler) List(c *gin.Context) {
}
accCopy
:=
acc
// 闭包捕获
g
.
Go
(
func
()
error
{
var
startTime
time
.
Time
if
accCopy
.
SessionWindowStart
!=
nil
{
startTime
=
*
accCopy
.
SessionWindowStart
}
else
{
startTime
=
time
.
Now
()
.
Add
(
-
5
*
time
.
Hour
)
}
// 使用统一的窗口开始时间计算逻辑(考虑窗口过期情况)
startTime
:=
accCopy
.
GetCurrentWindowStartTime
()
stats
,
err
:=
h
.
accountUsageService
.
GetAccountWindowStats
(
gctx
,
accCopy
.
ID
,
startTime
)
if
err
==
nil
&&
stats
!=
nil
{
mu
.
Lock
()
...
...
@@ -545,6 +546,41 @@ func (h *AccountHandler) Refresh(c *gin.Context) {
newCredentials
[
k
]
=
v
}
}
// 特殊处理 project_id:如果新值为空但旧值非空,保留旧值
// 这确保了即使 LoadCodeAssist 失败,project_id 也不会丢失
if
newProjectID
,
_
:=
newCredentials
[
"project_id"
]
.
(
string
);
newProjectID
==
""
{
if
oldProjectID
:=
strings
.
TrimSpace
(
account
.
GetCredential
(
"project_id"
));
oldProjectID
!=
""
{
newCredentials
[
"project_id"
]
=
oldProjectID
}
}
// 如果 project_id 获取失败,更新凭证但不标记为 error
// LoadCodeAssist 失败可能是临时网络问题,给它机会在下次自动刷新时重试
if
tokenInfo
.
ProjectIDMissing
{
// 先更新凭证(token 本身刷新成功了)
_
,
updateErr
:=
h
.
adminService
.
UpdateAccount
(
c
.
Request
.
Context
(),
accountID
,
&
service
.
UpdateAccountInput
{
Credentials
:
newCredentials
,
})
if
updateErr
!=
nil
{
response
.
InternalError
(
c
,
"Failed to update credentials: "
+
updateErr
.
Error
())
return
}
// 不标记为 error,只返回警告信息
response
.
Success
(
c
,
gin
.
H
{
"message"
:
"Token refreshed successfully, but project_id could not be retrieved (will retry automatically)"
,
"warning"
:
"missing_project_id_temporary"
,
})
return
}
// 成功获取到 project_id,如果之前是 missing_project_id 错误则清除
if
account
.
Status
==
service
.
StatusError
&&
strings
.
Contains
(
account
.
ErrorMessage
,
"missing_project_id:"
)
{
if
_
,
clearErr
:=
h
.
adminService
.
ClearAccountError
(
c
.
Request
.
Context
(),
accountID
);
clearErr
!=
nil
{
response
.
InternalError
(
c
,
"Failed to clear account error: "
+
clearErr
.
Error
())
return
}
}
}
else
{
// Use Anthropic/Claude OAuth service to refresh token
tokenInfo
,
err
:=
h
.
oauthService
.
RefreshAccountToken
(
c
.
Request
.
Context
(),
account
)
...
...
@@ -580,6 +616,14 @@ func (h *AccountHandler) Refresh(c *gin.Context) {
return
}
// 刷新成功后,清除 token 缓存,确保下次请求使用新 token
if
h
.
tokenCacheInvalidator
!=
nil
{
if
invalidateErr
:=
h
.
tokenCacheInvalidator
.
InvalidateToken
(
c
.
Request
.
Context
(),
updatedAccount
);
invalidateErr
!=
nil
{
// 缓存失效失败只记录日志,不影响主流程
_
=
c
.
Error
(
invalidateErr
)
}
}
response
.
Success
(
c
,
dto
.
AccountFromService
(
updatedAccount
))
}
...
...
@@ -629,6 +673,15 @@ func (h *AccountHandler) ClearError(c *gin.Context) {
return
}
// 清除错误后,同时清除 token 缓存,确保下次请求会获取最新的 token(触发刷新或从 DB 读取)
// 这解决了管理员重置账号状态后,旧的失效 token 仍在缓存中导致立即再次 401 的问题
if
h
.
tokenCacheInvalidator
!=
nil
&&
account
.
IsOAuth
()
{
if
invalidateErr
:=
h
.
tokenCacheInvalidator
.
InvalidateToken
(
c
.
Request
.
Context
(),
account
);
invalidateErr
!=
nil
{
// 缓存失效失败只记录日志,不影响主流程
_
=
c
.
Error
(
invalidateErr
)
}
}
response
.
Success
(
c
,
dto
.
AccountFromService
(
account
))
}
...
...
backend/internal/handler/admin/admin_basic_handlers_test.go
0 → 100644
View file @
2fe8932c
package
admin
import
(
"bytes"
"encoding/json"
"net/http"
"net/http/httptest"
"testing"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/require"
)
func
setupAdminRouter
()
(
*
gin
.
Engine
,
*
stubAdminService
)
{
gin
.
SetMode
(
gin
.
TestMode
)
router
:=
gin
.
New
()
adminSvc
:=
newStubAdminService
()
userHandler
:=
NewUserHandler
(
adminSvc
)
groupHandler
:=
NewGroupHandler
(
adminSvc
)
proxyHandler
:=
NewProxyHandler
(
adminSvc
)
redeemHandler
:=
NewRedeemHandler
(
adminSvc
)
router
.
GET
(
"/api/v1/admin/users"
,
userHandler
.
List
)
router
.
GET
(
"/api/v1/admin/users/:id"
,
userHandler
.
GetByID
)
router
.
POST
(
"/api/v1/admin/users"
,
userHandler
.
Create
)
router
.
PUT
(
"/api/v1/admin/users/:id"
,
userHandler
.
Update
)
router
.
DELETE
(
"/api/v1/admin/users/:id"
,
userHandler
.
Delete
)
router
.
POST
(
"/api/v1/admin/users/:id/balance"
,
userHandler
.
UpdateBalance
)
router
.
GET
(
"/api/v1/admin/users/:id/api-keys"
,
userHandler
.
GetUserAPIKeys
)
router
.
GET
(
"/api/v1/admin/users/:id/usage"
,
userHandler
.
GetUserUsage
)
router
.
GET
(
"/api/v1/admin/groups"
,
groupHandler
.
List
)
router
.
GET
(
"/api/v1/admin/groups/all"
,
groupHandler
.
GetAll
)
router
.
GET
(
"/api/v1/admin/groups/:id"
,
groupHandler
.
GetByID
)
router
.
POST
(
"/api/v1/admin/groups"
,
groupHandler
.
Create
)
router
.
PUT
(
"/api/v1/admin/groups/:id"
,
groupHandler
.
Update
)
router
.
DELETE
(
"/api/v1/admin/groups/:id"
,
groupHandler
.
Delete
)
router
.
GET
(
"/api/v1/admin/groups/:id/stats"
,
groupHandler
.
GetStats
)
router
.
GET
(
"/api/v1/admin/groups/:id/api-keys"
,
groupHandler
.
GetGroupAPIKeys
)
router
.
GET
(
"/api/v1/admin/proxies"
,
proxyHandler
.
List
)
router
.
GET
(
"/api/v1/admin/proxies/all"
,
proxyHandler
.
GetAll
)
router
.
GET
(
"/api/v1/admin/proxies/:id"
,
proxyHandler
.
GetByID
)
router
.
POST
(
"/api/v1/admin/proxies"
,
proxyHandler
.
Create
)
router
.
PUT
(
"/api/v1/admin/proxies/:id"
,
proxyHandler
.
Update
)
router
.
DELETE
(
"/api/v1/admin/proxies/:id"
,
proxyHandler
.
Delete
)
router
.
POST
(
"/api/v1/admin/proxies/batch-delete"
,
proxyHandler
.
BatchDelete
)
router
.
POST
(
"/api/v1/admin/proxies/:id/test"
,
proxyHandler
.
Test
)
router
.
GET
(
"/api/v1/admin/proxies/:id/stats"
,
proxyHandler
.
GetStats
)
router
.
GET
(
"/api/v1/admin/proxies/:id/accounts"
,
proxyHandler
.
GetProxyAccounts
)
router
.
GET
(
"/api/v1/admin/redeem-codes"
,
redeemHandler
.
List
)
router
.
GET
(
"/api/v1/admin/redeem-codes/:id"
,
redeemHandler
.
GetByID
)
router
.
POST
(
"/api/v1/admin/redeem-codes"
,
redeemHandler
.
Generate
)
router
.
DELETE
(
"/api/v1/admin/redeem-codes/:id"
,
redeemHandler
.
Delete
)
router
.
POST
(
"/api/v1/admin/redeem-codes/batch-delete"
,
redeemHandler
.
BatchDelete
)
router
.
POST
(
"/api/v1/admin/redeem-codes/:id/expire"
,
redeemHandler
.
Expire
)
router
.
GET
(
"/api/v1/admin/redeem-codes/:id/stats"
,
redeemHandler
.
GetStats
)
return
router
,
adminSvc
}
func
TestUserHandlerEndpoints
(
t
*
testing
.
T
)
{
router
,
_
:=
setupAdminRouter
()
rec
:=
httptest
.
NewRecorder
()
req
:=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/api/v1/admin/users?page=1&page_size=20"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/api/v1/admin/users/1"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
createBody
:=
map
[
string
]
any
{
"email"
:
"new@example.com"
,
"password"
:
"pass123"
,
"balance"
:
1
,
"concurrency"
:
2
}
body
,
_
:=
json
.
Marshal
(
createBody
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodPost
,
"/api/v1/admin/users"
,
bytes
.
NewReader
(
body
))
req
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
updateBody
:=
map
[
string
]
any
{
"email"
:
"updated@example.com"
}
body
,
_
=
json
.
Marshal
(
updateBody
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodPut
,
"/api/v1/admin/users/1"
,
bytes
.
NewReader
(
body
))
req
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodDelete
,
"/api/v1/admin/users/1"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodPost
,
"/api/v1/admin/users/1/balance"
,
bytes
.
NewBufferString
(
`{"balance":1,"operation":"add"}`
))
req
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/api/v1/admin/users/1/api-keys"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/api/v1/admin/users/1/usage?period=today"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
}
func
TestGroupHandlerEndpoints
(
t
*
testing
.
T
)
{
router
,
_
:=
setupAdminRouter
()
rec
:=
httptest
.
NewRecorder
()
req
:=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/api/v1/admin/groups"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/api/v1/admin/groups/all"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/api/v1/admin/groups/2"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
body
,
_
:=
json
.
Marshal
(
map
[
string
]
any
{
"name"
:
"new"
,
"platform"
:
"anthropic"
,
"subscription_type"
:
"standard"
})
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodPost
,
"/api/v1/admin/groups"
,
bytes
.
NewReader
(
body
))
req
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
body
,
_
=
json
.
Marshal
(
map
[
string
]
any
{
"name"
:
"update"
})
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodPut
,
"/api/v1/admin/groups/2"
,
bytes
.
NewReader
(
body
))
req
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodDelete
,
"/api/v1/admin/groups/2"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/api/v1/admin/groups/2/stats"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/api/v1/admin/groups/2/api-keys"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
}
func
TestProxyHandlerEndpoints
(
t
*
testing
.
T
)
{
router
,
_
:=
setupAdminRouter
()
rec
:=
httptest
.
NewRecorder
()
req
:=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/api/v1/admin/proxies"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/api/v1/admin/proxies/all"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/api/v1/admin/proxies/4"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
body
,
_
:=
json
.
Marshal
(
map
[
string
]
any
{
"name"
:
"proxy"
,
"protocol"
:
"http"
,
"host"
:
"localhost"
,
"port"
:
8080
})
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodPost
,
"/api/v1/admin/proxies"
,
bytes
.
NewReader
(
body
))
req
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
body
,
_
=
json
.
Marshal
(
map
[
string
]
any
{
"name"
:
"proxy2"
})
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodPut
,
"/api/v1/admin/proxies/4"
,
bytes
.
NewReader
(
body
))
req
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodDelete
,
"/api/v1/admin/proxies/4"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodPost
,
"/api/v1/admin/proxies/batch-delete"
,
bytes
.
NewBufferString
(
`{"ids":[1,2]}`
))
req
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodPost
,
"/api/v1/admin/proxies/4/test"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/api/v1/admin/proxies/4/stats"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/api/v1/admin/proxies/4/accounts"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
}
func
TestRedeemHandlerEndpoints
(
t
*
testing
.
T
)
{
router
,
_
:=
setupAdminRouter
()
rec
:=
httptest
.
NewRecorder
()
req
:=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/api/v1/admin/redeem-codes"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/api/v1/admin/redeem-codes/5"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
body
,
_
:=
json
.
Marshal
(
map
[
string
]
any
{
"count"
:
1
,
"type"
:
"balance"
,
"value"
:
10
})
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodPost
,
"/api/v1/admin/redeem-codes"
,
bytes
.
NewReader
(
body
))
req
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodDelete
,
"/api/v1/admin/redeem-codes/5"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodPost
,
"/api/v1/admin/redeem-codes/batch-delete"
,
bytes
.
NewBufferString
(
`{"ids":[1,2]}`
))
req
.
Header
.
Set
(
"Content-Type"
,
"application/json"
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodPost
,
"/api/v1/admin/redeem-codes/5/expire"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
rec
=
httptest
.
NewRecorder
()
req
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/api/v1/admin/redeem-codes/5/stats"
,
nil
)
router
.
ServeHTTP
(
rec
,
req
)
require
.
Equal
(
t
,
http
.
StatusOK
,
rec
.
Code
)
}
backend/internal/handler/admin/admin_helpers_test.go
0 → 100644
View file @
2fe8932c
package
admin
import
(
"encoding/json"
"net/http"
"net/http/httptest"
"net/netip"
"testing"
"time"
"github.com/Wei-Shaw/sub2api/internal/service"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/require"
)
func
TestParseTimeRange
(
t
*
testing
.
T
)
{
gin
.
SetMode
(
gin
.
TestMode
)
w
:=
httptest
.
NewRecorder
()
c
,
_
:=
gin
.
CreateTestContext
(
w
)
req
:=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/?start_date=2024-01-01&end_date=2024-01-02&timezone=UTC"
,
nil
)
c
.
Request
=
req
start
,
end
:=
parseTimeRange
(
c
)
require
.
Equal
(
t
,
time
.
Date
(
2024
,
1
,
1
,
0
,
0
,
0
,
0
,
time
.
UTC
),
start
)
require
.
Equal
(
t
,
time
.
Date
(
2024
,
1
,
3
,
0
,
0
,
0
,
0
,
time
.
UTC
),
end
)
req
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/?start_date=bad&timezone=UTC"
,
nil
)
c
.
Request
=
req
start
,
end
=
parseTimeRange
(
c
)
require
.
False
(
t
,
start
.
IsZero
())
require
.
False
(
t
,
end
.
IsZero
())
}
func
TestParseOpsViewParam
(
t
*
testing
.
T
)
{
gin
.
SetMode
(
gin
.
TestMode
)
w
:=
httptest
.
NewRecorder
()
c
,
_
:=
gin
.
CreateTestContext
(
w
)
c
.
Request
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/?view=excluded"
,
nil
)
require
.
Equal
(
t
,
opsListViewExcluded
,
parseOpsViewParam
(
c
))
c2
,
_
:=
gin
.
CreateTestContext
(
w
)
c2
.
Request
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/?view=all"
,
nil
)
require
.
Equal
(
t
,
opsListViewAll
,
parseOpsViewParam
(
c2
))
c3
,
_
:=
gin
.
CreateTestContext
(
w
)
c3
.
Request
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/?view=unknown"
,
nil
)
require
.
Equal
(
t
,
opsListViewErrors
,
parseOpsViewParam
(
c3
))
require
.
Equal
(
t
,
""
,
parseOpsViewParam
(
nil
))
}
func
TestParseOpsDuration
(
t
*
testing
.
T
)
{
dur
,
ok
:=
parseOpsDuration
(
"1h"
)
require
.
True
(
t
,
ok
)
require
.
Equal
(
t
,
time
.
Hour
,
dur
)
_
,
ok
=
parseOpsDuration
(
"invalid"
)
require
.
False
(
t
,
ok
)
}
func
TestParseOpsTimeRange
(
t
*
testing
.
T
)
{
gin
.
SetMode
(
gin
.
TestMode
)
w
:=
httptest
.
NewRecorder
()
c
,
_
:=
gin
.
CreateTestContext
(
w
)
now
:=
time
.
Now
()
.
UTC
()
startStr
:=
now
.
Add
(
-
time
.
Hour
)
.
Format
(
time
.
RFC3339
)
endStr
:=
now
.
Format
(
time
.
RFC3339
)
c
.
Request
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/?start_time="
+
startStr
+
"&end_time="
+
endStr
,
nil
)
start
,
end
,
err
:=
parseOpsTimeRange
(
c
,
"1h"
)
require
.
NoError
(
t
,
err
)
require
.
True
(
t
,
start
.
Before
(
end
))
c2
,
_
:=
gin
.
CreateTestContext
(
w
)
c2
.
Request
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/?start_time=bad"
,
nil
)
_
,
_
,
err
=
parseOpsTimeRange
(
c2
,
"1h"
)
require
.
Error
(
t
,
err
)
}
func
TestParseOpsRealtimeWindow
(
t
*
testing
.
T
)
{
dur
,
label
,
ok
:=
parseOpsRealtimeWindow
(
"5m"
)
require
.
True
(
t
,
ok
)
require
.
Equal
(
t
,
5
*
time
.
Minute
,
dur
)
require
.
Equal
(
t
,
"5min"
,
label
)
_
,
_
,
ok
=
parseOpsRealtimeWindow
(
"invalid"
)
require
.
False
(
t
,
ok
)
}
func
TestPickThroughputBucketSeconds
(
t
*
testing
.
T
)
{
require
.
Equal
(
t
,
60
,
pickThroughputBucketSeconds
(
30
*
time
.
Minute
))
require
.
Equal
(
t
,
300
,
pickThroughputBucketSeconds
(
6
*
time
.
Hour
))
require
.
Equal
(
t
,
3600
,
pickThroughputBucketSeconds
(
48
*
time
.
Hour
))
}
func
TestParseOpsQueryMode
(
t
*
testing
.
T
)
{
gin
.
SetMode
(
gin
.
TestMode
)
w
:=
httptest
.
NewRecorder
()
c
,
_
:=
gin
.
CreateTestContext
(
w
)
c
.
Request
=
httptest
.
NewRequest
(
http
.
MethodGet
,
"/?mode=raw"
,
nil
)
require
.
Equal
(
t
,
service
.
ParseOpsQueryMode
(
"raw"
),
parseOpsQueryMode
(
c
))
require
.
Equal
(
t
,
service
.
OpsQueryMode
(
""
),
parseOpsQueryMode
(
nil
))
}
func
TestOpsAlertRuleValidation
(
t
*
testing
.
T
)
{
raw
:=
map
[
string
]
json
.
RawMessage
{
"name"
:
json
.
RawMessage
(
`"High error rate"`
),
"metric_type"
:
json
.
RawMessage
(
`"error_rate"`
),
"operator"
:
json
.
RawMessage
(
`">"`
),
"threshold"
:
json
.
RawMessage
(
`90`
),
}
validated
,
err
:=
validateOpsAlertRulePayload
(
raw
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
"High error rate"
,
validated
.
Name
)
_
,
err
=
validateOpsAlertRulePayload
(
map
[
string
]
json
.
RawMessage
{})
require
.
Error
(
t
,
err
)
require
.
True
(
t
,
isPercentOrRateMetric
(
"error_rate"
))
require
.
False
(
t
,
isPercentOrRateMetric
(
"concurrency_queue_depth"
))
}
func
TestOpsWSHelpers
(
t
*
testing
.
T
)
{
prefixes
,
invalid
:=
parseTrustedProxyList
(
"10.0.0.0/8,invalid"
)
require
.
Len
(
t
,
prefixes
,
1
)
require
.
Len
(
t
,
invalid
,
1
)
host
:=
hostWithoutPort
(
"example.com:443"
)
require
.
Equal
(
t
,
"example.com"
,
host
)
addr
:=
netip
.
MustParseAddr
(
"10.0.0.1"
)
require
.
True
(
t
,
isAddrInTrustedProxies
(
addr
,
prefixes
))
require
.
False
(
t
,
isAddrInTrustedProxies
(
netip
.
MustParseAddr
(
"192.168.0.1"
),
prefixes
))
}
Prev
1
2
3
4
5
6
…
14
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment