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
c86d445c
Commit
c86d445c
authored
Jan 04, 2026
by
IanShaw027
Browse files
fix(frontend): sync with main and finalize i18n & component optimizations
parents
6c036d7b
e78c8646
Changes
186
Expand all
Hide whitespace changes
Inline
Side-by-side
backend/ent/hook/hook.go
View file @
c86d445c
...
...
@@ -9,6 +9,18 @@ import (
"github.com/Wei-Shaw/sub2api/ent"
)
// The APIKeyFunc type is an adapter to allow the use of ordinary
// function as APIKey mutator.
type
APIKeyFunc
func
(
context
.
Context
,
*
ent
.
APIKeyMutation
)
(
ent
.
Value
,
error
)
// Mutate calls f(ctx, m).
func
(
f
APIKeyFunc
)
Mutate
(
ctx
context
.
Context
,
m
ent
.
Mutation
)
(
ent
.
Value
,
error
)
{
if
mv
,
ok
:=
m
.
(
*
ent
.
APIKeyMutation
);
ok
{
return
f
(
ctx
,
mv
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.APIKeyMutation"
,
m
)
}
// The AccountFunc type is an adapter to allow the use of ordinary
// function as Account mutator.
type
AccountFunc
func
(
context
.
Context
,
*
ent
.
AccountMutation
)
(
ent
.
Value
,
error
)
...
...
@@ -33,18 +45,6 @@ func (f AccountGroupFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.AccountGroupMutation"
,
m
)
}
// The ApiKeyFunc type is an adapter to allow the use of ordinary
// function as ApiKey mutator.
type
ApiKeyFunc
func
(
context
.
Context
,
*
ent
.
ApiKeyMutation
)
(
ent
.
Value
,
error
)
// Mutate calls f(ctx, m).
func
(
f
ApiKeyFunc
)
Mutate
(
ctx
context
.
Context
,
m
ent
.
Mutation
)
(
ent
.
Value
,
error
)
{
if
mv
,
ok
:=
m
.
(
*
ent
.
ApiKeyMutation
);
ok
{
return
f
(
ctx
,
mv
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected mutation type %T. expect *ent.ApiKeyMutation"
,
m
)
}
// The GroupFunc type is an adapter to allow the use of ordinary
// function as Group mutator.
type
GroupFunc
func
(
context
.
Context
,
*
ent
.
GroupMutation
)
(
ent
.
Value
,
error
)
...
...
backend/ent/intercept/intercept.go
View file @
c86d445c
...
...
@@ -80,6 +80,33 @@ func (f TraverseFunc) Traverse(ctx context.Context, q ent.Query) error {
return
f
(
ctx
,
query
)
}
// The APIKeyFunc type is an adapter to allow the use of ordinary function as a Querier.
type
APIKeyFunc
func
(
context
.
Context
,
*
ent
.
APIKeyQuery
)
(
ent
.
Value
,
error
)
// Query calls f(ctx, q).
func
(
f
APIKeyFunc
)
Query
(
ctx
context
.
Context
,
q
ent
.
Query
)
(
ent
.
Value
,
error
)
{
if
q
,
ok
:=
q
.
(
*
ent
.
APIKeyQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.APIKeyQuery"
,
q
)
}
// The TraverseAPIKey type is an adapter to allow the use of ordinary function as Traverser.
type
TraverseAPIKey
func
(
context
.
Context
,
*
ent
.
APIKeyQuery
)
error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func
(
f
TraverseAPIKey
)
Intercept
(
next
ent
.
Querier
)
ent
.
Querier
{
return
next
}
// Traverse calls f(ctx, q).
func
(
f
TraverseAPIKey
)
Traverse
(
ctx
context
.
Context
,
q
ent
.
Query
)
error
{
if
q
,
ok
:=
q
.
(
*
ent
.
APIKeyQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.APIKeyQuery"
,
q
)
}
// The AccountFunc type is an adapter to allow the use of ordinary function as a Querier.
type
AccountFunc
func
(
context
.
Context
,
*
ent
.
AccountQuery
)
(
ent
.
Value
,
error
)
...
...
@@ -134,33 +161,6 @@ func (f TraverseAccountGroup) Traverse(ctx context.Context, q ent.Query) error {
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.AccountGroupQuery"
,
q
)
}
// The ApiKeyFunc type is an adapter to allow the use of ordinary function as a Querier.
type
ApiKeyFunc
func
(
context
.
Context
,
*
ent
.
ApiKeyQuery
)
(
ent
.
Value
,
error
)
// Query calls f(ctx, q).
func
(
f
ApiKeyFunc
)
Query
(
ctx
context
.
Context
,
q
ent
.
Query
)
(
ent
.
Value
,
error
)
{
if
q
,
ok
:=
q
.
(
*
ent
.
ApiKeyQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
nil
,
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.ApiKeyQuery"
,
q
)
}
// The TraverseApiKey type is an adapter to allow the use of ordinary function as Traverser.
type
TraverseApiKey
func
(
context
.
Context
,
*
ent
.
ApiKeyQuery
)
error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func
(
f
TraverseApiKey
)
Intercept
(
next
ent
.
Querier
)
ent
.
Querier
{
return
next
}
// Traverse calls f(ctx, q).
func
(
f
TraverseApiKey
)
Traverse
(
ctx
context
.
Context
,
q
ent
.
Query
)
error
{
if
q
,
ok
:=
q
.
(
*
ent
.
ApiKeyQuery
);
ok
{
return
f
(
ctx
,
q
)
}
return
fmt
.
Errorf
(
"unexpected query type %T. expect *ent.ApiKeyQuery"
,
q
)
}
// The GroupFunc type is an adapter to allow the use of ordinary function as a Querier.
type
GroupFunc
func
(
context
.
Context
,
*
ent
.
GroupQuery
)
(
ent
.
Value
,
error
)
...
...
@@ -434,12 +434,12 @@ func (f TraverseUserSubscription) Traverse(ctx context.Context, q ent.Query) err
// NewQuery returns the generic Query interface for the given typed query.
func
NewQuery
(
q
ent
.
Query
)
(
Query
,
error
)
{
switch
q
:=
q
.
(
type
)
{
case
*
ent
.
APIKeyQuery
:
return
&
query
[
*
ent
.
APIKeyQuery
,
predicate
.
APIKey
,
apikey
.
OrderOption
]{
typ
:
ent
.
TypeAPIKey
,
tq
:
q
},
nil
case
*
ent
.
AccountQuery
:
return
&
query
[
*
ent
.
AccountQuery
,
predicate
.
Account
,
account
.
OrderOption
]{
typ
:
ent
.
TypeAccount
,
tq
:
q
},
nil
case
*
ent
.
AccountGroupQuery
:
return
&
query
[
*
ent
.
AccountGroupQuery
,
predicate
.
AccountGroup
,
accountgroup
.
OrderOption
]{
typ
:
ent
.
TypeAccountGroup
,
tq
:
q
},
nil
case
*
ent
.
ApiKeyQuery
:
return
&
query
[
*
ent
.
ApiKeyQuery
,
predicate
.
ApiKey
,
apikey
.
OrderOption
]{
typ
:
ent
.
TypeApiKey
,
tq
:
q
},
nil
case
*
ent
.
GroupQuery
:
return
&
query
[
*
ent
.
GroupQuery
,
predicate
.
Group
,
group
.
OrderOption
]{
typ
:
ent
.
TypeGroup
,
tq
:
q
},
nil
case
*
ent
.
ProxyQuery
:
...
...
backend/ent/migrate/schema.go
View file @
c86d445c
...
...
@@ -9,6 +9,60 @@ import (
)
var
(
// APIKeysColumns holds the columns for the "api_keys" table.
APIKeysColumns
=
[]
*
schema
.
Column
{
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
{
Name
:
"created_at"
,
Type
:
field
.
TypeTime
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"updated_at"
,
Type
:
field
.
TypeTime
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"deleted_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"key"
,
Type
:
field
.
TypeString
,
Unique
:
true
,
Size
:
128
},
{
Name
:
"name"
,
Type
:
field
.
TypeString
,
Size
:
100
},
{
Name
:
"status"
,
Type
:
field
.
TypeString
,
Size
:
20
,
Default
:
"active"
},
{
Name
:
"group_id"
,
Type
:
field
.
TypeInt64
,
Nullable
:
true
},
{
Name
:
"user_id"
,
Type
:
field
.
TypeInt64
},
}
// APIKeysTable holds the schema information for the "api_keys" table.
APIKeysTable
=
&
schema
.
Table
{
Name
:
"api_keys"
,
Columns
:
APIKeysColumns
,
PrimaryKey
:
[]
*
schema
.
Column
{
APIKeysColumns
[
0
]},
ForeignKeys
:
[]
*
schema
.
ForeignKey
{
{
Symbol
:
"api_keys_groups_api_keys"
,
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
7
]},
RefColumns
:
[]
*
schema
.
Column
{
GroupsColumns
[
0
]},
OnDelete
:
schema
.
SetNull
,
},
{
Symbol
:
"api_keys_users_api_keys"
,
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
8
]},
RefColumns
:
[]
*
schema
.
Column
{
UsersColumns
[
0
]},
OnDelete
:
schema
.
NoAction
,
},
},
Indexes
:
[]
*
schema
.
Index
{
{
Name
:
"apikey_user_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
8
]},
},
{
Name
:
"apikey_group_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
7
]},
},
{
Name
:
"apikey_status"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
6
]},
},
{
Name
:
"apikey_deleted_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
3
]},
},
},
}
// AccountsColumns holds the columns for the "accounts" table.
AccountsColumns
=
[]
*
schema
.
Column
{
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
...
...
@@ -144,60 +198,6 @@ var (
},
},
}
// APIKeysColumns holds the columns for the "api_keys" table.
APIKeysColumns
=
[]
*
schema
.
Column
{
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
{
Name
:
"created_at"
,
Type
:
field
.
TypeTime
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"updated_at"
,
Type
:
field
.
TypeTime
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"deleted_at"
,
Type
:
field
.
TypeTime
,
Nullable
:
true
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"key"
,
Type
:
field
.
TypeString
,
Unique
:
true
,
Size
:
128
},
{
Name
:
"name"
,
Type
:
field
.
TypeString
,
Size
:
100
},
{
Name
:
"status"
,
Type
:
field
.
TypeString
,
Size
:
20
,
Default
:
"active"
},
{
Name
:
"group_id"
,
Type
:
field
.
TypeInt64
,
Nullable
:
true
},
{
Name
:
"user_id"
,
Type
:
field
.
TypeInt64
},
}
// APIKeysTable holds the schema information for the "api_keys" table.
APIKeysTable
=
&
schema
.
Table
{
Name
:
"api_keys"
,
Columns
:
APIKeysColumns
,
PrimaryKey
:
[]
*
schema
.
Column
{
APIKeysColumns
[
0
]},
ForeignKeys
:
[]
*
schema
.
ForeignKey
{
{
Symbol
:
"api_keys_groups_api_keys"
,
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
7
]},
RefColumns
:
[]
*
schema
.
Column
{
GroupsColumns
[
0
]},
OnDelete
:
schema
.
SetNull
,
},
{
Symbol
:
"api_keys_users_api_keys"
,
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
8
]},
RefColumns
:
[]
*
schema
.
Column
{
UsersColumns
[
0
]},
OnDelete
:
schema
.
NoAction
,
},
},
Indexes
:
[]
*
schema
.
Index
{
{
Name
:
"apikey_user_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
8
]},
},
{
Name
:
"apikey_group_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
7
]},
},
{
Name
:
"apikey_status"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
6
]},
},
{
Name
:
"apikey_deleted_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
APIKeysColumns
[
3
]},
},
},
}
// GroupsColumns holds the columns for the "groups" table.
GroupsColumns
=
[]
*
schema
.
Column
{
{
Name
:
"id"
,
Type
:
field
.
TypeInt64
,
Increment
:
true
},
...
...
@@ -368,8 +368,8 @@ var (
{
Name
:
"duration_ms"
,
Type
:
field
.
TypeInt
,
Nullable
:
true
},
{
Name
:
"first_token_ms"
,
Type
:
field
.
TypeInt
,
Nullable
:
true
},
{
Name
:
"created_at"
,
Type
:
field
.
TypeTime
,
SchemaType
:
map
[
string
]
string
{
"postgres"
:
"timestamptz"
}},
{
Name
:
"account_id"
,
Type
:
field
.
TypeInt64
},
{
Name
:
"api_key_id"
,
Type
:
field
.
TypeInt64
},
{
Name
:
"account_id"
,
Type
:
field
.
TypeInt64
},
{
Name
:
"group_id"
,
Type
:
field
.
TypeInt64
,
Nullable
:
true
},
{
Name
:
"user_id"
,
Type
:
field
.
TypeInt64
},
{
Name
:
"subscription_id"
,
Type
:
field
.
TypeInt64
,
Nullable
:
true
},
...
...
@@ -381,15 +381,15 @@ var (
PrimaryKey
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
0
]},
ForeignKeys
:
[]
*
schema
.
ForeignKey
{
{
Symbol
:
"usage_logs_a
ccount
s_usage_logs"
,
Symbol
:
"usage_logs_a
pi_key
s_usage_logs"
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
21
]},
RefColumns
:
[]
*
schema
.
Column
{
A
ccount
sColumns
[
0
]},
RefColumns
:
[]
*
schema
.
Column
{
A
PIKey
sColumns
[
0
]},
OnDelete
:
schema
.
NoAction
,
},
{
Symbol
:
"usage_logs_a
pi_key
s_usage_logs"
,
Symbol
:
"usage_logs_a
ccount
s_usage_logs"
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
22
]},
RefColumns
:
[]
*
schema
.
Column
{
A
PIKey
sColumns
[
0
]},
RefColumns
:
[]
*
schema
.
Column
{
A
ccount
sColumns
[
0
]},
OnDelete
:
schema
.
NoAction
,
},
{
...
...
@@ -420,12 +420,12 @@ var (
{
Name
:
"usagelog_api_key_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
2
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
1
]},
},
{
Name
:
"usagelog_account_id"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
1
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
2
]},
},
{
Name
:
"usagelog_group_id"
,
...
...
@@ -460,7 +460,7 @@ var (
{
Name
:
"usagelog_api_key_id_created_at"
,
Unique
:
false
,
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
2
],
UsageLogsColumns
[
20
]},
Columns
:
[]
*
schema
.
Column
{
UsageLogsColumns
[
2
1
],
UsageLogsColumns
[
20
]},
},
},
}
...
...
@@ -702,9 +702,9 @@ var (
}
// Tables holds all the tables in the schema.
Tables
=
[]
*
schema
.
Table
{
APIKeysTable
,
AccountsTable
,
AccountGroupsTable
,
APIKeysTable
,
GroupsTable
,
ProxiesTable
,
RedeemCodesTable
,
...
...
@@ -719,6 +719,11 @@ var (
)
func
init
()
{
APIKeysTable
.
ForeignKeys
[
0
]
.
RefTable
=
GroupsTable
APIKeysTable
.
ForeignKeys
[
1
]
.
RefTable
=
UsersTable
APIKeysTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"api_keys"
,
}
AccountsTable
.
ForeignKeys
[
0
]
.
RefTable
=
ProxiesTable
AccountsTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"accounts"
,
...
...
@@ -728,11 +733,6 @@ func init() {
AccountGroupsTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"account_groups"
,
}
APIKeysTable
.
ForeignKeys
[
0
]
.
RefTable
=
GroupsTable
APIKeysTable
.
ForeignKeys
[
1
]
.
RefTable
=
UsersTable
APIKeysTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"api_keys"
,
}
GroupsTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"groups"
,
}
...
...
@@ -747,8 +747,8 @@ func init() {
SettingsTable
.
Annotation
=
&
entsql
.
Annotation
{
Table
:
"settings"
,
}
UsageLogsTable
.
ForeignKeys
[
0
]
.
RefTable
=
A
ccount
sTable
UsageLogsTable
.
ForeignKeys
[
1
]
.
RefTable
=
A
PIKey
sTable
UsageLogsTable
.
ForeignKeys
[
0
]
.
RefTable
=
A
PIKey
sTable
UsageLogsTable
.
ForeignKeys
[
1
]
.
RefTable
=
A
ccount
sTable
UsageLogsTable
.
ForeignKeys
[
2
]
.
RefTable
=
GroupsTable
UsageLogsTable
.
ForeignKeys
[
3
]
.
RefTable
=
UsersTable
UsageLogsTable
.
ForeignKeys
[
4
]
.
RefTable
=
UserSubscriptionsTable
...
...
backend/ent/mutation.go
View file @
c86d445c
This diff is collapsed.
Click to expand it.
backend/ent/predicate/predicate.go
View file @
c86d445c
...
...
@@ -6,15 +6,15 @@ import (
"entgo.io/ent/dialect/sql"
)
// APIKey is the predicate function for apikey builders.
type
APIKey
func
(
*
sql
.
Selector
)
// Account is the predicate function for account builders.
type
Account
func
(
*
sql
.
Selector
)
// AccountGroup is the predicate function for accountgroup builders.
type
AccountGroup
func
(
*
sql
.
Selector
)
// ApiKey is the predicate function for apikey builders.
type
ApiKey
func
(
*
sql
.
Selector
)
// Group is the predicate function for group builders.
type
Group
func
(
*
sql
.
Selector
)
...
...
backend/ent/runtime/runtime.go
View file @
c86d445c
...
...
@@ -25,6 +25,67 @@ import (
// (default values, validators, hooks and policies) and stitches it
// to their package variables.
func
init
()
{
apikeyMixin
:=
schema
.
APIKey
{}
.
Mixin
()
apikeyMixinHooks1
:=
apikeyMixin
[
1
]
.
Hooks
()
apikey
.
Hooks
[
0
]
=
apikeyMixinHooks1
[
0
]
apikeyMixinInters1
:=
apikeyMixin
[
1
]
.
Interceptors
()
apikey
.
Interceptors
[
0
]
=
apikeyMixinInters1
[
0
]
apikeyMixinFields0
:=
apikeyMixin
[
0
]
.
Fields
()
_
=
apikeyMixinFields0
apikeyFields
:=
schema
.
APIKey
{}
.
Fields
()
_
=
apikeyFields
// apikeyDescCreatedAt is the schema descriptor for created_at field.
apikeyDescCreatedAt
:=
apikeyMixinFields0
[
0
]
.
Descriptor
()
// apikey.DefaultCreatedAt holds the default value on creation for the created_at field.
apikey
.
DefaultCreatedAt
=
apikeyDescCreatedAt
.
Default
.
(
func
()
time
.
Time
)
// apikeyDescUpdatedAt is the schema descriptor for updated_at field.
apikeyDescUpdatedAt
:=
apikeyMixinFields0
[
1
]
.
Descriptor
()
// apikey.DefaultUpdatedAt holds the default value on creation for the updated_at field.
apikey
.
DefaultUpdatedAt
=
apikeyDescUpdatedAt
.
Default
.
(
func
()
time
.
Time
)
// apikey.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
apikey
.
UpdateDefaultUpdatedAt
=
apikeyDescUpdatedAt
.
UpdateDefault
.
(
func
()
time
.
Time
)
// apikeyDescKey is the schema descriptor for key field.
apikeyDescKey
:=
apikeyFields
[
1
]
.
Descriptor
()
// apikey.KeyValidator is a validator for the "key" field. It is called by the builders before save.
apikey
.
KeyValidator
=
func
()
func
(
string
)
error
{
validators
:=
apikeyDescKey
.
Validators
fns
:=
[
...
]
func
(
string
)
error
{
validators
[
0
]
.
(
func
(
string
)
error
),
validators
[
1
]
.
(
func
(
string
)
error
),
}
return
func
(
key
string
)
error
{
for
_
,
fn
:=
range
fns
{
if
err
:=
fn
(
key
);
err
!=
nil
{
return
err
}
}
return
nil
}
}()
// apikeyDescName is the schema descriptor for name field.
apikeyDescName
:=
apikeyFields
[
2
]
.
Descriptor
()
// apikey.NameValidator is a validator for the "name" field. It is called by the builders before save.
apikey
.
NameValidator
=
func
()
func
(
string
)
error
{
validators
:=
apikeyDescName
.
Validators
fns
:=
[
...
]
func
(
string
)
error
{
validators
[
0
]
.
(
func
(
string
)
error
),
validators
[
1
]
.
(
func
(
string
)
error
),
}
return
func
(
name
string
)
error
{
for
_
,
fn
:=
range
fns
{
if
err
:=
fn
(
name
);
err
!=
nil
{
return
err
}
}
return
nil
}
}()
// apikeyDescStatus is the schema descriptor for status field.
apikeyDescStatus
:=
apikeyFields
[
4
]
.
Descriptor
()
// apikey.DefaultStatus holds the default value on creation for the status field.
apikey
.
DefaultStatus
=
apikeyDescStatus
.
Default
.
(
string
)
// apikey.StatusValidator is a validator for the "status" field. It is called by the builders before save.
apikey
.
StatusValidator
=
apikeyDescStatus
.
Validators
[
0
]
.
(
func
(
string
)
error
)
accountMixin
:=
schema
.
Account
{}
.
Mixin
()
accountMixinHooks1
:=
accountMixin
[
1
]
.
Hooks
()
account
.
Hooks
[
0
]
=
accountMixinHooks1
[
0
]
...
...
@@ -138,67 +199,6 @@ func init() {
accountgroupDescCreatedAt
:=
accountgroupFields
[
3
]
.
Descriptor
()
// accountgroup.DefaultCreatedAt holds the default value on creation for the created_at field.
accountgroup
.
DefaultCreatedAt
=
accountgroupDescCreatedAt
.
Default
.
(
func
()
time
.
Time
)
apikeyMixin
:=
schema
.
ApiKey
{}
.
Mixin
()
apikeyMixinHooks1
:=
apikeyMixin
[
1
]
.
Hooks
()
apikey
.
Hooks
[
0
]
=
apikeyMixinHooks1
[
0
]
apikeyMixinInters1
:=
apikeyMixin
[
1
]
.
Interceptors
()
apikey
.
Interceptors
[
0
]
=
apikeyMixinInters1
[
0
]
apikeyMixinFields0
:=
apikeyMixin
[
0
]
.
Fields
()
_
=
apikeyMixinFields0
apikeyFields
:=
schema
.
ApiKey
{}
.
Fields
()
_
=
apikeyFields
// apikeyDescCreatedAt is the schema descriptor for created_at field.
apikeyDescCreatedAt
:=
apikeyMixinFields0
[
0
]
.
Descriptor
()
// apikey.DefaultCreatedAt holds the default value on creation for the created_at field.
apikey
.
DefaultCreatedAt
=
apikeyDescCreatedAt
.
Default
.
(
func
()
time
.
Time
)
// apikeyDescUpdatedAt is the schema descriptor for updated_at field.
apikeyDescUpdatedAt
:=
apikeyMixinFields0
[
1
]
.
Descriptor
()
// apikey.DefaultUpdatedAt holds the default value on creation for the updated_at field.
apikey
.
DefaultUpdatedAt
=
apikeyDescUpdatedAt
.
Default
.
(
func
()
time
.
Time
)
// apikey.UpdateDefaultUpdatedAt holds the default value on update for the updated_at field.
apikey
.
UpdateDefaultUpdatedAt
=
apikeyDescUpdatedAt
.
UpdateDefault
.
(
func
()
time
.
Time
)
// apikeyDescKey is the schema descriptor for key field.
apikeyDescKey
:=
apikeyFields
[
1
]
.
Descriptor
()
// apikey.KeyValidator is a validator for the "key" field. It is called by the builders before save.
apikey
.
KeyValidator
=
func
()
func
(
string
)
error
{
validators
:=
apikeyDescKey
.
Validators
fns
:=
[
...
]
func
(
string
)
error
{
validators
[
0
]
.
(
func
(
string
)
error
),
validators
[
1
]
.
(
func
(
string
)
error
),
}
return
func
(
key
string
)
error
{
for
_
,
fn
:=
range
fns
{
if
err
:=
fn
(
key
);
err
!=
nil
{
return
err
}
}
return
nil
}
}()
// apikeyDescName is the schema descriptor for name field.
apikeyDescName
:=
apikeyFields
[
2
]
.
Descriptor
()
// apikey.NameValidator is a validator for the "name" field. It is called by the builders before save.
apikey
.
NameValidator
=
func
()
func
(
string
)
error
{
validators
:=
apikeyDescName
.
Validators
fns
:=
[
...
]
func
(
string
)
error
{
validators
[
0
]
.
(
func
(
string
)
error
),
validators
[
1
]
.
(
func
(
string
)
error
),
}
return
func
(
name
string
)
error
{
for
_
,
fn
:=
range
fns
{
if
err
:=
fn
(
name
);
err
!=
nil
{
return
err
}
}
return
nil
}
}()
// apikeyDescStatus is the schema descriptor for status field.
apikeyDescStatus
:=
apikeyFields
[
4
]
.
Descriptor
()
// apikey.DefaultStatus holds the default value on creation for the status field.
apikey
.
DefaultStatus
=
apikeyDescStatus
.
Default
.
(
string
)
// apikey.StatusValidator is a validator for the "status" field. It is called by the builders before save.
apikey
.
StatusValidator
=
apikeyDescStatus
.
Validators
[
0
]
.
(
func
(
string
)
error
)
groupMixin
:=
schema
.
Group
{}
.
Mixin
()
groupMixinHooks1
:=
groupMixin
[
1
]
.
Hooks
()
group
.
Hooks
[
0
]
=
groupMixinHooks1
[
0
]
...
...
backend/ent/schema/api_key.go
View file @
c86d445c
...
...
@@ -12,25 +12,25 @@ import (
"entgo.io/ent/schema/index"
)
// A
pi
Key holds the schema definition for the A
pi
Key entity.
type
A
pi
Key
struct
{
// A
PI
Key holds the schema definition for the A
PI
Key entity.
type
A
PI
Key
struct
{
ent
.
Schema
}
func
(
A
pi
Key
)
Annotations
()
[]
schema
.
Annotation
{
func
(
A
PI
Key
)
Annotations
()
[]
schema
.
Annotation
{
return
[]
schema
.
Annotation
{
entsql
.
Annotation
{
Table
:
"api_keys"
},
}
}
func
(
A
pi
Key
)
Mixin
()
[]
ent
.
Mixin
{
func
(
A
PI
Key
)
Mixin
()
[]
ent
.
Mixin
{
return
[]
ent
.
Mixin
{
mixins
.
TimeMixin
{},
mixins
.
SoftDeleteMixin
{},
}
}
func
(
A
pi
Key
)
Fields
()
[]
ent
.
Field
{
func
(
A
PI
Key
)
Fields
()
[]
ent
.
Field
{
return
[]
ent
.
Field
{
field
.
Int64
(
"user_id"
),
field
.
String
(
"key"
)
.
...
...
@@ -49,7 +49,7 @@ func (ApiKey) Fields() []ent.Field {
}
}
func
(
A
pi
Key
)
Edges
()
[]
ent
.
Edge
{
func
(
A
PI
Key
)
Edges
()
[]
ent
.
Edge
{
return
[]
ent
.
Edge
{
edge
.
From
(
"user"
,
User
.
Type
)
.
Ref
(
"api_keys"
)
.
...
...
@@ -64,7 +64,7 @@ func (ApiKey) Edges() []ent.Edge {
}
}
func
(
A
pi
Key
)
Indexes
()
[]
ent
.
Index
{
func
(
A
PI
Key
)
Indexes
()
[]
ent
.
Index
{
return
[]
ent
.
Index
{
// key 字段已在 Fields() 中声明 Unique(),无需重复索引
index
.
Fields
(
"user_id"
),
...
...
backend/ent/schema/group.go
View file @
c86d445c
...
...
@@ -77,7 +77,7 @@ func (Group) Fields() []ent.Field {
func
(
Group
)
Edges
()
[]
ent
.
Edge
{
return
[]
ent
.
Edge
{
edge
.
To
(
"api_keys"
,
A
pi
Key
.
Type
),
edge
.
To
(
"api_keys"
,
A
PI
Key
.
Type
),
edge
.
To
(
"redeem_codes"
,
RedeemCode
.
Type
),
edge
.
To
(
"subscriptions"
,
UserSubscription
.
Type
),
edge
.
To
(
"usage_logs"
,
UsageLog
.
Type
),
...
...
backend/ent/schema/usage_log.go
View file @
c86d445c
...
...
@@ -113,7 +113,7 @@ func (UsageLog) Edges() []ent.Edge {
Field
(
"user_id"
)
.
Required
()
.
Unique
(),
edge
.
From
(
"api_key"
,
A
pi
Key
.
Type
)
.
edge
.
From
(
"api_key"
,
A
PI
Key
.
Type
)
.
Ref
(
"usage_logs"
)
.
Field
(
"api_key_id"
)
.
Required
()
.
...
...
backend/ent/schema/user.go
View file @
c86d445c
...
...
@@ -66,7 +66,7 @@ func (User) Fields() []ent.Field {
func
(
User
)
Edges
()
[]
ent
.
Edge
{
return
[]
ent
.
Edge
{
edge
.
To
(
"api_keys"
,
A
pi
Key
.
Type
),
edge
.
To
(
"api_keys"
,
A
PI
Key
.
Type
),
edge
.
To
(
"redeem_codes"
,
RedeemCode
.
Type
),
edge
.
To
(
"subscriptions"
,
UserSubscription
.
Type
),
edge
.
To
(
"assigned_subscriptions"
,
UserSubscription
.
Type
),
...
...
backend/ent/tx.go
View file @
c86d445c
...
...
@@ -14,12 +14,12 @@ import (
// Tx is a transactional client that is created by calling Client.Tx().
type
Tx
struct
{
config
// APIKey is the client for interacting with the APIKey builders.
APIKey
*
APIKeyClient
// Account is the client for interacting with the Account builders.
Account
*
AccountClient
// AccountGroup is the client for interacting with the AccountGroup builders.
AccountGroup
*
AccountGroupClient
// ApiKey is the client for interacting with the ApiKey builders.
ApiKey
*
ApiKeyClient
// Group is the client for interacting with the Group builders.
Group
*
GroupClient
// Proxy is the client for interacting with the Proxy builders.
...
...
@@ -171,9 +171,9 @@ func (tx *Tx) Client() *Client {
}
func
(
tx
*
Tx
)
init
()
{
tx
.
APIKey
=
NewAPIKeyClient
(
tx
.
config
)
tx
.
Account
=
NewAccountClient
(
tx
.
config
)
tx
.
AccountGroup
=
NewAccountGroupClient
(
tx
.
config
)
tx
.
ApiKey
=
NewApiKeyClient
(
tx
.
config
)
tx
.
Group
=
NewGroupClient
(
tx
.
config
)
tx
.
Proxy
=
NewProxyClient
(
tx
.
config
)
tx
.
RedeemCode
=
NewRedeemCodeClient
(
tx
.
config
)
...
...
@@ -193,7 +193,7 @@ func (tx *Tx) init() {
// of them in order to commit or rollback the transaction.
//
// If a closed transaction is embedded in one of the generated entities, and the entity
// applies a query, for example: A
ccount
.QueryXXX(), the query will be executed
// applies a query, for example: A
PIKey
.QueryXXX(), the query will be executed
// through the driver which created this transaction.
//
// Note that txDriver is not goroutine safe.
...
...
backend/ent/usagelog.go
View file @
c86d445c
...
...
@@ -83,7 +83,7 @@ type UsageLogEdges struct {
// User holds the value of the user edge.
User
*
User
`json:"user,omitempty"`
// APIKey holds the value of the api_key edge.
APIKey
*
A
pi
Key
`json:"api_key,omitempty"`
APIKey
*
A
PI
Key
`json:"api_key,omitempty"`
// Account holds the value of the account edge.
Account
*
Account
`json:"account,omitempty"`
// Group holds the value of the group edge.
...
...
@@ -108,7 +108,7 @@ func (e UsageLogEdges) UserOrErr() (*User, error) {
// APIKeyOrErr returns the APIKey value or an error if the edge
// was not loaded in eager-loading, or loaded but was not found.
func
(
e
UsageLogEdges
)
APIKeyOrErr
()
(
*
A
pi
Key
,
error
)
{
func
(
e
UsageLogEdges
)
APIKeyOrErr
()
(
*
A
PI
Key
,
error
)
{
if
e
.
APIKey
!=
nil
{
return
e
.
APIKey
,
nil
}
else
if
e
.
loadedTypes
[
1
]
{
...
...
@@ -359,7 +359,7 @@ func (_m *UsageLog) QueryUser() *UserQuery {
}
// QueryAPIKey queries the "api_key" edge of the UsageLog entity.
func
(
_m
*
UsageLog
)
QueryAPIKey
()
*
A
pi
KeyQuery
{
func
(
_m
*
UsageLog
)
QueryAPIKey
()
*
A
PI
KeyQuery
{
return
NewUsageLogClient
(
_m
.
config
)
.
QueryAPIKey
(
_m
)
}
...
...
backend/ent/usagelog/usagelog.go
View file @
c86d445c
...
...
@@ -85,7 +85,7 @@ const (
UserColumn
=
"user_id"
// APIKeyTable is the table that holds the api_key relation/edge.
APIKeyTable
=
"usage_logs"
// APIKeyInverseTable is the table name for the A
pi
Key entity.
// APIKeyInverseTable is the table name for the A
PI
Key entity.
// It exists in this package in order to avoid circular dependency with the "apikey" package.
APIKeyInverseTable
=
"api_keys"
// APIKeyColumn is the table column denoting the api_key relation/edge.
...
...
backend/ent/usagelog/where.go
View file @
c86d445c
...
...
@@ -1175,7 +1175,7 @@ func HasAPIKey() predicate.UsageLog {
}
// HasAPIKeyWith applies the HasEdge predicate on the "api_key" edge with a given conditions (other predicates).
func
HasAPIKeyWith
(
preds
...
predicate
.
A
pi
Key
)
predicate
.
UsageLog
{
func
HasAPIKeyWith
(
preds
...
predicate
.
A
PI
Key
)
predicate
.
UsageLog
{
return
predicate
.
UsageLog
(
func
(
s
*
sql
.
Selector
)
{
step
:=
newAPIKeyStep
()
sqlgraph
.
HasNeighborsWith
(
s
,
step
,
func
(
s
*
sql
.
Selector
)
{
...
...
backend/ent/usagelog_create.go
View file @
c86d445c
...
...
@@ -342,8 +342,8 @@ func (_c *UsageLogCreate) SetUser(v *User) *UsageLogCreate {
return
_c
.
SetUserID
(
v
.
ID
)
}
// SetAPIKey sets the "api_key" edge to the A
pi
Key entity.
func
(
_c
*
UsageLogCreate
)
SetAPIKey
(
v
*
A
pi
Key
)
*
UsageLogCreate
{
// SetAPIKey sets the "api_key" edge to the A
PI
Key entity.
func
(
_c
*
UsageLogCreate
)
SetAPIKey
(
v
*
A
PI
Key
)
*
UsageLogCreate
{
return
_c
.
SetAPIKeyID
(
v
.
ID
)
}
...
...
backend/ent/usagelog_query.go
View file @
c86d445c
...
...
@@ -28,7 +28,7 @@ type UsageLogQuery struct {
inters
[]
Interceptor
predicates
[]
predicate
.
UsageLog
withUser
*
UserQuery
withAPIKey
*
A
pi
KeyQuery
withAPIKey
*
A
PI
KeyQuery
withAccount
*
AccountQuery
withGroup
*
GroupQuery
withSubscription
*
UserSubscriptionQuery
...
...
@@ -91,8 +91,8 @@ func (_q *UsageLogQuery) QueryUser() *UserQuery {
}
// QueryAPIKey chains the current query on the "api_key" edge.
func
(
_q
*
UsageLogQuery
)
QueryAPIKey
()
*
A
pi
KeyQuery
{
query
:=
(
&
A
pi
KeyClient
{
config
:
_q
.
config
})
.
Query
()
func
(
_q
*
UsageLogQuery
)
QueryAPIKey
()
*
A
PI
KeyQuery
{
query
:=
(
&
A
PI
KeyClient
{
config
:
_q
.
config
})
.
Query
()
query
.
path
=
func
(
ctx
context
.
Context
)
(
fromU
*
sql
.
Selector
,
err
error
)
{
if
err
:=
_q
.
prepareQuery
(
ctx
);
err
!=
nil
{
return
nil
,
err
...
...
@@ -394,8 +394,8 @@ func (_q *UsageLogQuery) WithUser(opts ...func(*UserQuery)) *UsageLogQuery {
// WithAPIKey tells the query-builder to eager-load the nodes that are connected to
// the "api_key" edge. The optional arguments are used to configure the query builder of the edge.
func
(
_q
*
UsageLogQuery
)
WithAPIKey
(
opts
...
func
(
*
A
pi
KeyQuery
))
*
UsageLogQuery
{
query
:=
(
&
A
pi
KeyClient
{
config
:
_q
.
config
})
.
Query
()
func
(
_q
*
UsageLogQuery
)
WithAPIKey
(
opts
...
func
(
*
A
PI
KeyQuery
))
*
UsageLogQuery
{
query
:=
(
&
A
PI
KeyClient
{
config
:
_q
.
config
})
.
Query
()
for
_
,
opt
:=
range
opts
{
opt
(
query
)
}
...
...
@@ -548,7 +548,7 @@ func (_q *UsageLogQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Usa
}
if
query
:=
_q
.
withAPIKey
;
query
!=
nil
{
if
err
:=
_q
.
loadAPIKey
(
ctx
,
query
,
nodes
,
nil
,
func
(
n
*
UsageLog
,
e
*
A
pi
Key
)
{
n
.
Edges
.
APIKey
=
e
});
err
!=
nil
{
func
(
n
*
UsageLog
,
e
*
A
PI
Key
)
{
n
.
Edges
.
APIKey
=
e
});
err
!=
nil
{
return
nil
,
err
}
}
...
...
@@ -602,7 +602,7 @@ func (_q *UsageLogQuery) loadUser(ctx context.Context, query *UserQuery, nodes [
}
return
nil
}
func
(
_q
*
UsageLogQuery
)
loadAPIKey
(
ctx
context
.
Context
,
query
*
A
pi
KeyQuery
,
nodes
[]
*
UsageLog
,
init
func
(
*
UsageLog
),
assign
func
(
*
UsageLog
,
*
A
pi
Key
))
error
{
func
(
_q
*
UsageLogQuery
)
loadAPIKey
(
ctx
context
.
Context
,
query
*
A
PI
KeyQuery
,
nodes
[]
*
UsageLog
,
init
func
(
*
UsageLog
),
assign
func
(
*
UsageLog
,
*
A
PI
Key
))
error
{
ids
:=
make
([]
int64
,
0
,
len
(
nodes
))
nodeids
:=
make
(
map
[
int64
][]
*
UsageLog
)
for
i
:=
range
nodes
{
...
...
backend/ent/usagelog_update.go
View file @
c86d445c
...
...
@@ -509,8 +509,8 @@ func (_u *UsageLogUpdate) SetUser(v *User) *UsageLogUpdate {
return
_u
.
SetUserID
(
v
.
ID
)
}
// SetAPIKey sets the "api_key" edge to the A
pi
Key entity.
func
(
_u
*
UsageLogUpdate
)
SetAPIKey
(
v
*
A
pi
Key
)
*
UsageLogUpdate
{
// SetAPIKey sets the "api_key" edge to the A
PI
Key entity.
func
(
_u
*
UsageLogUpdate
)
SetAPIKey
(
v
*
A
PI
Key
)
*
UsageLogUpdate
{
return
_u
.
SetAPIKeyID
(
v
.
ID
)
}
...
...
@@ -540,7 +540,7 @@ func (_u *UsageLogUpdate) ClearUser() *UsageLogUpdate {
return
_u
}
// ClearAPIKey clears the "api_key" edge to the A
pi
Key entity.
// ClearAPIKey clears the "api_key" edge to the A
PI
Key entity.
func
(
_u
*
UsageLogUpdate
)
ClearAPIKey
()
*
UsageLogUpdate
{
_u
.
mutation
.
ClearAPIKey
()
return
_u
...
...
@@ -1380,8 +1380,8 @@ func (_u *UsageLogUpdateOne) SetUser(v *User) *UsageLogUpdateOne {
return
_u
.
SetUserID
(
v
.
ID
)
}
// SetAPIKey sets the "api_key" edge to the A
pi
Key entity.
func
(
_u
*
UsageLogUpdateOne
)
SetAPIKey
(
v
*
A
pi
Key
)
*
UsageLogUpdateOne
{
// SetAPIKey sets the "api_key" edge to the A
PI
Key entity.
func
(
_u
*
UsageLogUpdateOne
)
SetAPIKey
(
v
*
A
PI
Key
)
*
UsageLogUpdateOne
{
return
_u
.
SetAPIKeyID
(
v
.
ID
)
}
...
...
@@ -1411,7 +1411,7 @@ func (_u *UsageLogUpdateOne) ClearUser() *UsageLogUpdateOne {
return
_u
}
// ClearAPIKey clears the "api_key" edge to the A
pi
Key entity.
// ClearAPIKey clears the "api_key" edge to the A
PI
Key entity.
func
(
_u
*
UsageLogUpdateOne
)
ClearAPIKey
()
*
UsageLogUpdateOne
{
_u
.
mutation
.
ClearAPIKey
()
return
_u
...
...
backend/ent/user.go
View file @
c86d445c
...
...
@@ -48,7 +48,7 @@ type User struct {
// UserEdges holds the relations/edges for other nodes in the graph.
type
UserEdges
struct
{
// APIKeys holds the value of the api_keys edge.
APIKeys
[]
*
A
pi
Key
`json:"api_keys,omitempty"`
APIKeys
[]
*
A
PI
Key
`json:"api_keys,omitempty"`
// RedeemCodes holds the value of the redeem_codes edge.
RedeemCodes
[]
*
RedeemCode
`json:"redeem_codes,omitempty"`
// Subscriptions holds the value of the subscriptions edge.
...
...
@@ -70,7 +70,7 @@ type UserEdges struct {
// APIKeysOrErr returns the APIKeys value or an error if the edge
// was not loaded in eager-loading.
func
(
e
UserEdges
)
APIKeysOrErr
()
([]
*
A
pi
Key
,
error
)
{
func
(
e
UserEdges
)
APIKeysOrErr
()
([]
*
A
PI
Key
,
error
)
{
if
e
.
loadedTypes
[
0
]
{
return
e
.
APIKeys
,
nil
}
...
...
@@ -255,7 +255,7 @@ func (_m *User) Value(name string) (ent.Value, error) {
}
// QueryAPIKeys queries the "api_keys" edge of the User entity.
func
(
_m
*
User
)
QueryAPIKeys
()
*
A
pi
KeyQuery
{
func
(
_m
*
User
)
QueryAPIKeys
()
*
A
PI
KeyQuery
{
return
NewUserClient
(
_m
.
config
)
.
QueryAPIKeys
(
_m
)
}
...
...
backend/ent/user/user.go
View file @
c86d445c
...
...
@@ -57,7 +57,7 @@ const (
Table
=
"users"
// APIKeysTable is the table that holds the api_keys relation/edge.
APIKeysTable
=
"api_keys"
// APIKeysInverseTable is the table name for the A
pi
Key entity.
// APIKeysInverseTable is the table name for the A
PI
Key entity.
// It exists in this package in order to avoid circular dependency with the "apikey" package.
APIKeysInverseTable
=
"api_keys"
// APIKeysColumn is the table column denoting the api_keys relation/edge.
...
...
backend/ent/user/where.go
View file @
c86d445c
...
...
@@ -722,7 +722,7 @@ func HasAPIKeys() predicate.User {
}
// HasAPIKeysWith applies the HasEdge predicate on the "api_keys" edge with a given conditions (other predicates).
func
HasAPIKeysWith
(
preds
...
predicate
.
A
pi
Key
)
predicate
.
User
{
func
HasAPIKeysWith
(
preds
...
predicate
.
A
PI
Key
)
predicate
.
User
{
return
predicate
.
User
(
func
(
s
*
sql
.
Selector
)
{
step
:=
newAPIKeysStep
()
sqlgraph
.
HasNeighborsWith
(
s
,
step
,
func
(
s
*
sql
.
Selector
)
{
...
...
Prev
1
2
3
4
5
6
…
10
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