fix(lint): 修复所有 Go 命名规范问题
- 全局替换 ApiKey → APIKey(类型、字段、方法、变量) - 修复所有 initialism 命名(API, SMTP, HTML, URL 等) - 添加所有缺失的包注释 - 修复导出符号的注释格式 主要修改: - ApiKey → APIKey(所有出现的地方) - ApiKeyID → APIKeyID - ApiKeyIDs → APIKeyIDs - TestSmtpConnection → TestSMTPConnection - HtmlURL → HTMLURL - 添加 20+ 个包注释 - 修复 10+ 个导出符号注释格式 验证结果: - ✓ golangci-lint: 0 issues - ✓ 单元测试: 通过 - ✓ 集成测试: 通过
This commit is contained in:
@@ -18,33 +18,33 @@ import (
|
||||
"github.com/Wei-Shaw/sub2api/ent/user"
|
||||
)
|
||||
|
||||
// ApiKeyUpdate is the builder for updating ApiKey entities.
|
||||
type ApiKeyUpdate struct {
|
||||
// APIKeyUpdate is the builder for updating APIKey entities.
|
||||
type APIKeyUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *ApiKeyMutation
|
||||
mutation *APIKeyMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ApiKeyUpdate builder.
|
||||
func (_u *ApiKeyUpdate) Where(ps ...predicate.ApiKey) *ApiKeyUpdate {
|
||||
// Where appends a list predicates to the APIKeyUpdate builder.
|
||||
func (_u *APIKeyUpdate) Where(ps ...predicate.APIKey) *APIKeyUpdate {
|
||||
_u.mutation.Where(ps...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_u *ApiKeyUpdate) SetUpdatedAt(v time.Time) *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) SetUpdatedAt(v time.Time) *APIKeyUpdate {
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetDeletedAt sets the "deleted_at" field.
|
||||
func (_u *ApiKeyUpdate) SetDeletedAt(v time.Time) *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) SetDeletedAt(v time.Time) *APIKeyUpdate {
|
||||
_u.mutation.SetDeletedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
||||
func (_u *ApiKeyUpdate) SetNillableDeletedAt(v *time.Time) *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) SetNillableDeletedAt(v *time.Time) *APIKeyUpdate {
|
||||
if v != nil {
|
||||
_u.SetDeletedAt(*v)
|
||||
}
|
||||
@@ -52,19 +52,19 @@ func (_u *ApiKeyUpdate) SetNillableDeletedAt(v *time.Time) *ApiKeyUpdate {
|
||||
}
|
||||
|
||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||
func (_u *ApiKeyUpdate) ClearDeletedAt() *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) ClearDeletedAt() *APIKeyUpdate {
|
||||
_u.mutation.ClearDeletedAt()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (_u *ApiKeyUpdate) SetUserID(v int64) *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) SetUserID(v int64) *APIKeyUpdate {
|
||||
_u.mutation.SetUserID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||
func (_u *ApiKeyUpdate) SetNillableUserID(v *int64) *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) SetNillableUserID(v *int64) *APIKeyUpdate {
|
||||
if v != nil {
|
||||
_u.SetUserID(*v)
|
||||
}
|
||||
@@ -72,13 +72,13 @@ func (_u *ApiKeyUpdate) SetNillableUserID(v *int64) *ApiKeyUpdate {
|
||||
}
|
||||
|
||||
// SetKey sets the "key" field.
|
||||
func (_u *ApiKeyUpdate) SetKey(v string) *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) SetKey(v string) *APIKeyUpdate {
|
||||
_u.mutation.SetKey(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableKey sets the "key" field if the given value is not nil.
|
||||
func (_u *ApiKeyUpdate) SetNillableKey(v *string) *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) SetNillableKey(v *string) *APIKeyUpdate {
|
||||
if v != nil {
|
||||
_u.SetKey(*v)
|
||||
}
|
||||
@@ -86,13 +86,13 @@ func (_u *ApiKeyUpdate) SetNillableKey(v *string) *ApiKeyUpdate {
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *ApiKeyUpdate) SetName(v string) *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) SetName(v string) *APIKeyUpdate {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *ApiKeyUpdate) SetNillableName(v *string) *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) SetNillableName(v *string) *APIKeyUpdate {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
@@ -100,13 +100,13 @@ func (_u *ApiKeyUpdate) SetNillableName(v *string) *ApiKeyUpdate {
|
||||
}
|
||||
|
||||
// SetGroupID sets the "group_id" field.
|
||||
func (_u *ApiKeyUpdate) SetGroupID(v int64) *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) SetGroupID(v int64) *APIKeyUpdate {
|
||||
_u.mutation.SetGroupID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableGroupID sets the "group_id" field if the given value is not nil.
|
||||
func (_u *ApiKeyUpdate) SetNillableGroupID(v *int64) *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) SetNillableGroupID(v *int64) *APIKeyUpdate {
|
||||
if v != nil {
|
||||
_u.SetGroupID(*v)
|
||||
}
|
||||
@@ -114,19 +114,19 @@ func (_u *ApiKeyUpdate) SetNillableGroupID(v *int64) *ApiKeyUpdate {
|
||||
}
|
||||
|
||||
// ClearGroupID clears the value of the "group_id" field.
|
||||
func (_u *ApiKeyUpdate) ClearGroupID() *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) ClearGroupID() *APIKeyUpdate {
|
||||
_u.mutation.ClearGroupID()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_u *ApiKeyUpdate) SetStatus(v string) *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) SetStatus(v string) *APIKeyUpdate {
|
||||
_u.mutation.SetStatus(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (_u *ApiKeyUpdate) SetNillableStatus(v *string) *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) SetNillableStatus(v *string) *APIKeyUpdate {
|
||||
if v != nil {
|
||||
_u.SetStatus(*v)
|
||||
}
|
||||
@@ -134,23 +134,23 @@ func (_u *ApiKeyUpdate) SetNillableStatus(v *string) *ApiKeyUpdate {
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (_u *ApiKeyUpdate) SetUser(v *User) *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) SetUser(v *User) *APIKeyUpdate {
|
||||
return _u.SetUserID(v.ID)
|
||||
}
|
||||
|
||||
// SetGroup sets the "group" edge to the Group entity.
|
||||
func (_u *ApiKeyUpdate) SetGroup(v *Group) *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) SetGroup(v *Group) *APIKeyUpdate {
|
||||
return _u.SetGroupID(v.ID)
|
||||
}
|
||||
|
||||
// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
|
||||
func (_u *ApiKeyUpdate) AddUsageLogIDs(ids ...int64) *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) AddUsageLogIDs(ids ...int64) *APIKeyUpdate {
|
||||
_u.mutation.AddUsageLogIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
|
||||
func (_u *ApiKeyUpdate) AddUsageLogs(v ...*UsageLog) *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) AddUsageLogs(v ...*UsageLog) *APIKeyUpdate {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
@@ -158,37 +158,37 @@ func (_u *ApiKeyUpdate) AddUsageLogs(v ...*UsageLog) *ApiKeyUpdate {
|
||||
return _u.AddUsageLogIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the ApiKeyMutation object of the builder.
|
||||
func (_u *ApiKeyUpdate) Mutation() *ApiKeyMutation {
|
||||
// Mutation returns the APIKeyMutation object of the builder.
|
||||
func (_u *APIKeyUpdate) Mutation() *APIKeyMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the User entity.
|
||||
func (_u *ApiKeyUpdate) ClearUser() *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) ClearUser() *APIKeyUpdate {
|
||||
_u.mutation.ClearUser()
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearGroup clears the "group" edge to the Group entity.
|
||||
func (_u *ApiKeyUpdate) ClearGroup() *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) ClearGroup() *APIKeyUpdate {
|
||||
_u.mutation.ClearGroup()
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUsageLogs clears all "usage_logs" edges to the UsageLog entity.
|
||||
func (_u *ApiKeyUpdate) ClearUsageLogs() *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) ClearUsageLogs() *APIKeyUpdate {
|
||||
_u.mutation.ClearUsageLogs()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveUsageLogIDs removes the "usage_logs" edge to UsageLog entities by IDs.
|
||||
func (_u *ApiKeyUpdate) RemoveUsageLogIDs(ids ...int64) *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) RemoveUsageLogIDs(ids ...int64) *APIKeyUpdate {
|
||||
_u.mutation.RemoveUsageLogIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveUsageLogs removes "usage_logs" edges to UsageLog entities.
|
||||
func (_u *ApiKeyUpdate) RemoveUsageLogs(v ...*UsageLog) *ApiKeyUpdate {
|
||||
func (_u *APIKeyUpdate) RemoveUsageLogs(v ...*UsageLog) *APIKeyUpdate {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
@@ -197,7 +197,7 @@ func (_u *ApiKeyUpdate) RemoveUsageLogs(v ...*UsageLog) *ApiKeyUpdate {
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (_u *ApiKeyUpdate) Save(ctx context.Context) (int, error) {
|
||||
func (_u *APIKeyUpdate) Save(ctx context.Context) (int, error) {
|
||||
if err := _u.defaults(); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
@@ -205,7 +205,7 @@ func (_u *ApiKeyUpdate) Save(ctx context.Context) (int, error) {
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *ApiKeyUpdate) SaveX(ctx context.Context) int {
|
||||
func (_u *APIKeyUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -214,20 +214,20 @@ func (_u *ApiKeyUpdate) SaveX(ctx context.Context) int {
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_u *ApiKeyUpdate) Exec(ctx context.Context) error {
|
||||
func (_u *APIKeyUpdate) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *ApiKeyUpdate) ExecX(ctx context.Context) {
|
||||
func (_u *APIKeyUpdate) 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 *ApiKeyUpdate) defaults() error {
|
||||
func (_u *APIKeyUpdate) defaults() error {
|
||||
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||
if apikey.UpdateDefaultUpdatedAt == nil {
|
||||
return fmt.Errorf("ent: uninitialized apikey.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
|
||||
@@ -239,29 +239,29 @@ func (_u *ApiKeyUpdate) defaults() error {
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *ApiKeyUpdate) check() error {
|
||||
func (_u *APIKeyUpdate) check() error {
|
||||
if v, ok := _u.mutation.Key(); ok {
|
||||
if err := apikey.KeyValidator(v); err != nil {
|
||||
return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "ApiKey.key": %w`, err)}
|
||||
return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "APIKey.key": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Name(); ok {
|
||||
if err := apikey.NameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ApiKey.name": %w`, err)}
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "APIKey.name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Status(); ok {
|
||||
if err := apikey.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "ApiKey.status": %w`, err)}
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "APIKey.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "ApiKey.user"`)
|
||||
return errors.New(`ent: clearing a required unique edge "APIKey.user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *ApiKeyUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
func (_u *APIKeyUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
@@ -406,28 +406,28 @@ func (_u *ApiKeyUpdate) sqlSave(ctx context.Context) (_node int, err error) {
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
// ApiKeyUpdateOne is the builder for updating a single ApiKey entity.
|
||||
type ApiKeyUpdateOne struct {
|
||||
// APIKeyUpdateOne is the builder for updating a single APIKey entity.
|
||||
type APIKeyUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *ApiKeyMutation
|
||||
mutation *APIKeyMutation
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_u *ApiKeyUpdateOne) SetUpdatedAt(v time.Time) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) SetUpdatedAt(v time.Time) *APIKeyUpdateOne {
|
||||
_u.mutation.SetUpdatedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetDeletedAt sets the "deleted_at" field.
|
||||
func (_u *ApiKeyUpdateOne) SetDeletedAt(v time.Time) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) SetDeletedAt(v time.Time) *APIKeyUpdateOne {
|
||||
_u.mutation.SetDeletedAt(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableDeletedAt sets the "deleted_at" field if the given value is not nil.
|
||||
func (_u *ApiKeyUpdateOne) SetNillableDeletedAt(v *time.Time) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) SetNillableDeletedAt(v *time.Time) *APIKeyUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetDeletedAt(*v)
|
||||
}
|
||||
@@ -435,19 +435,19 @@ func (_u *ApiKeyUpdateOne) SetNillableDeletedAt(v *time.Time) *ApiKeyUpdateOne {
|
||||
}
|
||||
|
||||
// ClearDeletedAt clears the value of the "deleted_at" field.
|
||||
func (_u *ApiKeyUpdateOne) ClearDeletedAt() *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) ClearDeletedAt() *APIKeyUpdateOne {
|
||||
_u.mutation.ClearDeletedAt()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetUserID sets the "user_id" field.
|
||||
func (_u *ApiKeyUpdateOne) SetUserID(v int64) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) SetUserID(v int64) *APIKeyUpdateOne {
|
||||
_u.mutation.SetUserID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableUserID sets the "user_id" field if the given value is not nil.
|
||||
func (_u *ApiKeyUpdateOne) SetNillableUserID(v *int64) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) SetNillableUserID(v *int64) *APIKeyUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetUserID(*v)
|
||||
}
|
||||
@@ -455,13 +455,13 @@ func (_u *ApiKeyUpdateOne) SetNillableUserID(v *int64) *ApiKeyUpdateOne {
|
||||
}
|
||||
|
||||
// SetKey sets the "key" field.
|
||||
func (_u *ApiKeyUpdateOne) SetKey(v string) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) SetKey(v string) *APIKeyUpdateOne {
|
||||
_u.mutation.SetKey(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableKey sets the "key" field if the given value is not nil.
|
||||
func (_u *ApiKeyUpdateOne) SetNillableKey(v *string) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) SetNillableKey(v *string) *APIKeyUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetKey(*v)
|
||||
}
|
||||
@@ -469,13 +469,13 @@ func (_u *ApiKeyUpdateOne) SetNillableKey(v *string) *ApiKeyUpdateOne {
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_u *ApiKeyUpdateOne) SetName(v string) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) SetName(v string) *APIKeyUpdateOne {
|
||||
_u.mutation.SetName(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableName sets the "name" field if the given value is not nil.
|
||||
func (_u *ApiKeyUpdateOne) SetNillableName(v *string) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) SetNillableName(v *string) *APIKeyUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetName(*v)
|
||||
}
|
||||
@@ -483,13 +483,13 @@ func (_u *ApiKeyUpdateOne) SetNillableName(v *string) *ApiKeyUpdateOne {
|
||||
}
|
||||
|
||||
// SetGroupID sets the "group_id" field.
|
||||
func (_u *ApiKeyUpdateOne) SetGroupID(v int64) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) SetGroupID(v int64) *APIKeyUpdateOne {
|
||||
_u.mutation.SetGroupID(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableGroupID sets the "group_id" field if the given value is not nil.
|
||||
func (_u *ApiKeyUpdateOne) SetNillableGroupID(v *int64) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) SetNillableGroupID(v *int64) *APIKeyUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetGroupID(*v)
|
||||
}
|
||||
@@ -497,19 +497,19 @@ func (_u *ApiKeyUpdateOne) SetNillableGroupID(v *int64) *ApiKeyUpdateOne {
|
||||
}
|
||||
|
||||
// ClearGroupID clears the value of the "group_id" field.
|
||||
func (_u *ApiKeyUpdateOne) ClearGroupID() *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) ClearGroupID() *APIKeyUpdateOne {
|
||||
_u.mutation.ClearGroupID()
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_u *ApiKeyUpdateOne) SetStatus(v string) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) SetStatus(v string) *APIKeyUpdateOne {
|
||||
_u.mutation.SetStatus(v)
|
||||
return _u
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (_u *ApiKeyUpdateOne) SetNillableStatus(v *string) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) SetNillableStatus(v *string) *APIKeyUpdateOne {
|
||||
if v != nil {
|
||||
_u.SetStatus(*v)
|
||||
}
|
||||
@@ -517,23 +517,23 @@ func (_u *ApiKeyUpdateOne) SetNillableStatus(v *string) *ApiKeyUpdateOne {
|
||||
}
|
||||
|
||||
// SetUser sets the "user" edge to the User entity.
|
||||
func (_u *ApiKeyUpdateOne) SetUser(v *User) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) SetUser(v *User) *APIKeyUpdateOne {
|
||||
return _u.SetUserID(v.ID)
|
||||
}
|
||||
|
||||
// SetGroup sets the "group" edge to the Group entity.
|
||||
func (_u *ApiKeyUpdateOne) SetGroup(v *Group) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) SetGroup(v *Group) *APIKeyUpdateOne {
|
||||
return _u.SetGroupID(v.ID)
|
||||
}
|
||||
|
||||
// AddUsageLogIDs adds the "usage_logs" edge to the UsageLog entity by IDs.
|
||||
func (_u *ApiKeyUpdateOne) AddUsageLogIDs(ids ...int64) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) AddUsageLogIDs(ids ...int64) *APIKeyUpdateOne {
|
||||
_u.mutation.AddUsageLogIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// AddUsageLogs adds the "usage_logs" edges to the UsageLog entity.
|
||||
func (_u *ApiKeyUpdateOne) AddUsageLogs(v ...*UsageLog) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) AddUsageLogs(v ...*UsageLog) *APIKeyUpdateOne {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
@@ -541,37 +541,37 @@ func (_u *ApiKeyUpdateOne) AddUsageLogs(v ...*UsageLog) *ApiKeyUpdateOne {
|
||||
return _u.AddUsageLogIDs(ids...)
|
||||
}
|
||||
|
||||
// Mutation returns the ApiKeyMutation object of the builder.
|
||||
func (_u *ApiKeyUpdateOne) Mutation() *ApiKeyMutation {
|
||||
// Mutation returns the APIKeyMutation object of the builder.
|
||||
func (_u *APIKeyUpdateOne) Mutation() *APIKeyMutation {
|
||||
return _u.mutation
|
||||
}
|
||||
|
||||
// ClearUser clears the "user" edge to the User entity.
|
||||
func (_u *ApiKeyUpdateOne) ClearUser() *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) ClearUser() *APIKeyUpdateOne {
|
||||
_u.mutation.ClearUser()
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearGroup clears the "group" edge to the Group entity.
|
||||
func (_u *ApiKeyUpdateOne) ClearGroup() *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) ClearGroup() *APIKeyUpdateOne {
|
||||
_u.mutation.ClearGroup()
|
||||
return _u
|
||||
}
|
||||
|
||||
// ClearUsageLogs clears all "usage_logs" edges to the UsageLog entity.
|
||||
func (_u *ApiKeyUpdateOne) ClearUsageLogs() *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) ClearUsageLogs() *APIKeyUpdateOne {
|
||||
_u.mutation.ClearUsageLogs()
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveUsageLogIDs removes the "usage_logs" edge to UsageLog entities by IDs.
|
||||
func (_u *ApiKeyUpdateOne) RemoveUsageLogIDs(ids ...int64) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) RemoveUsageLogIDs(ids ...int64) *APIKeyUpdateOne {
|
||||
_u.mutation.RemoveUsageLogIDs(ids...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// RemoveUsageLogs removes "usage_logs" edges to UsageLog entities.
|
||||
func (_u *ApiKeyUpdateOne) RemoveUsageLogs(v ...*UsageLog) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) RemoveUsageLogs(v ...*UsageLog) *APIKeyUpdateOne {
|
||||
ids := make([]int64, len(v))
|
||||
for i := range v {
|
||||
ids[i] = v[i].ID
|
||||
@@ -579,21 +579,21 @@ func (_u *ApiKeyUpdateOne) RemoveUsageLogs(v ...*UsageLog) *ApiKeyUpdateOne {
|
||||
return _u.RemoveUsageLogIDs(ids...)
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the ApiKeyUpdate builder.
|
||||
func (_u *ApiKeyUpdateOne) Where(ps ...predicate.ApiKey) *ApiKeyUpdateOne {
|
||||
// Where appends a list predicates to the APIKeyUpdate builder.
|
||||
func (_u *APIKeyUpdateOne) Where(ps ...predicate.APIKey) *APIKeyUpdateOne {
|
||||
_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 *ApiKeyUpdateOne) Select(field string, fields ...string) *ApiKeyUpdateOne {
|
||||
func (_u *APIKeyUpdateOne) Select(field string, fields ...string) *APIKeyUpdateOne {
|
||||
_u.fields = append([]string{field}, fields...)
|
||||
return _u
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated ApiKey entity.
|
||||
func (_u *ApiKeyUpdateOne) Save(ctx context.Context) (*ApiKey, error) {
|
||||
// Save executes the query and returns the updated APIKey entity.
|
||||
func (_u *APIKeyUpdateOne) Save(ctx context.Context) (*APIKey, error) {
|
||||
if err := _u.defaults(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -601,7 +601,7 @@ func (_u *ApiKeyUpdateOne) Save(ctx context.Context) (*ApiKey, error) {
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_u *ApiKeyUpdateOne) SaveX(ctx context.Context) *ApiKey {
|
||||
func (_u *APIKeyUpdateOne) SaveX(ctx context.Context) *APIKey {
|
||||
node, err := _u.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@@ -610,20 +610,20 @@ func (_u *ApiKeyUpdateOne) SaveX(ctx context.Context) *ApiKey {
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (_u *ApiKeyUpdateOne) Exec(ctx context.Context) error {
|
||||
func (_u *APIKeyUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := _u.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_u *ApiKeyUpdateOne) ExecX(ctx context.Context) {
|
||||
func (_u *APIKeyUpdateOne) 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 *ApiKeyUpdateOne) defaults() error {
|
||||
func (_u *APIKeyUpdateOne) defaults() error {
|
||||
if _, ok := _u.mutation.UpdatedAt(); !ok {
|
||||
if apikey.UpdateDefaultUpdatedAt == nil {
|
||||
return fmt.Errorf("ent: uninitialized apikey.UpdateDefaultUpdatedAt (forgotten import ent/runtime?)")
|
||||
@@ -635,36 +635,36 @@ func (_u *ApiKeyUpdateOne) defaults() error {
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_u *ApiKeyUpdateOne) check() error {
|
||||
func (_u *APIKeyUpdateOne) check() error {
|
||||
if v, ok := _u.mutation.Key(); ok {
|
||||
if err := apikey.KeyValidator(v); err != nil {
|
||||
return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "ApiKey.key": %w`, err)}
|
||||
return &ValidationError{Name: "key", err: fmt.Errorf(`ent: validator failed for field "APIKey.key": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Name(); ok {
|
||||
if err := apikey.NameValidator(v); err != nil {
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "ApiKey.name": %w`, err)}
|
||||
return &ValidationError{Name: "name", err: fmt.Errorf(`ent: validator failed for field "APIKey.name": %w`, err)}
|
||||
}
|
||||
}
|
||||
if v, ok := _u.mutation.Status(); ok {
|
||||
if err := apikey.StatusValidator(v); err != nil {
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "ApiKey.status": %w`, err)}
|
||||
return &ValidationError{Name: "status", err: fmt.Errorf(`ent: validator failed for field "APIKey.status": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _u.mutation.UserCleared() && len(_u.mutation.UserIDs()) > 0 {
|
||||
return errors.New(`ent: clearing a required unique edge "ApiKey.user"`)
|
||||
return errors.New(`ent: clearing a required unique edge "APIKey.user"`)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_u *ApiKeyUpdateOne) sqlSave(ctx context.Context) (_node *ApiKey, err error) {
|
||||
func (_u *APIKeyUpdateOne) sqlSave(ctx context.Context) (_node *APIKey, err error) {
|
||||
if err := _u.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(apikey.Table, apikey.Columns, sqlgraph.NewFieldSpec(apikey.FieldID, field.TypeInt64))
|
||||
id, ok := _u.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "ApiKey.id" for update`)}
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "APIKey.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := _u.fields; len(fields) > 0 {
|
||||
@@ -807,7 +807,7 @@ func (_u *ApiKeyUpdateOne) sqlSave(ctx context.Context) (_node *ApiKey, err erro
|
||||
}
|
||||
_spec.Edges.Add = append(_spec.Edges.Add, edge)
|
||||
}
|
||||
_node = &ApiKey{config: _u.config}
|
||||
_node = &APIKey{config: _u.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user