mirror of
https://github.com/simon-ding/polaris.git
synced 2026-02-06 15:10:49 +08:00
feat: add goreleaser
This commit is contained in:
37
.github/workflows/goreleaser.yml
vendored
Normal file
37
.github/workflows/goreleaser.yml
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
name: goreleaser
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
|
||||
jobs:
|
||||
goreleaser:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
-
|
||||
name: Set up Go
|
||||
uses: actions/setup-go@v5
|
||||
-
|
||||
name: Run GoReleaser
|
||||
uses: goreleaser/goreleaser-action@v6
|
||||
with:
|
||||
# either 'goreleaser' (default) or 'goreleaser-pro'
|
||||
distribution: goreleaser
|
||||
# 'latest', 'nightly', or a semver
|
||||
version: '~> v2'
|
||||
args: release --clean
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
# Your GoReleaser Pro key, if you are using the 'goreleaser-pro' distribution
|
||||
# GORELEASER_KEY: ${{ secrets.GORELEASER_KEY }}
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -30,3 +30,5 @@ ui/dist/
|
||||
# Go workspace file
|
||||
go.work
|
||||
go.work.sum
|
||||
|
||||
dist/
|
||||
|
||||
51
.goreleaser.yaml
Normal file
51
.goreleaser.yaml
Normal file
@@ -0,0 +1,51 @@
|
||||
# This is an example .goreleaser.yml file with some sensible defaults.
|
||||
# Make sure to check the documentation at https://goreleaser.com
|
||||
|
||||
# The lines below are called `modelines`. See `:help modeline`
|
||||
# Feel free to remove those if you don't want/need to use them.
|
||||
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
|
||||
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
|
||||
|
||||
version: 2
|
||||
|
||||
before:
|
||||
hooks:
|
||||
# You may remove this if you don't use go modules.
|
||||
- go mod tidy
|
||||
# you may remove this if you don't need go generate
|
||||
#- go generate ./...
|
||||
|
||||
builds:
|
||||
- env:
|
||||
- CGO_ENABLED=0
|
||||
goos:
|
||||
- linux
|
||||
- windows
|
||||
- darwin
|
||||
- freebsd
|
||||
main: ./cmd
|
||||
goarch:
|
||||
- amd64
|
||||
- arm64
|
||||
|
||||
archives:
|
||||
- format: tar.gz
|
||||
# this name template makes the OS and Arch compatible with the results of `uname`.
|
||||
name_template: >-
|
||||
{{ .ProjectName }}_
|
||||
{{- title .Os }}_
|
||||
{{- if eq .Arch "amd64" }}x86_64
|
||||
{{- else if eq .Arch "386" }}i386
|
||||
{{- else }}{{ .Arch }}{{ end }}
|
||||
{{- if .Arm }}v{{ .Arm }}{{ end }}
|
||||
# use zip for windows archives
|
||||
format_overrides:
|
||||
- goos: windows
|
||||
format: zip
|
||||
|
||||
changelog:
|
||||
sort: asc
|
||||
filters:
|
||||
exclude:
|
||||
- "^docs:"
|
||||
- "^test:"
|
||||
@@ -5,14 +5,13 @@ import (
|
||||
"polaris/log"
|
||||
"polaris/pkg/utils"
|
||||
"polaris/server"
|
||||
"syscall"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
log.Infof("------------------- Starting Polaris ---------------------")
|
||||
|
||||
syscall.Umask(0) //max permission 0777
|
||||
utils.MaxPermission()
|
||||
|
||||
dbClient, err := db.Open()
|
||||
if err != nil {
|
||||
|
||||
5
db/db.go
5
db/db.go
@@ -22,7 +22,8 @@ import (
|
||||
|
||||
"entgo.io/ent/dialect"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
_ "github.com/ncruces/go-sqlite3/driver"
|
||||
_ "github.com/ncruces/go-sqlite3/embed"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@@ -643,4 +644,4 @@ func (c *Client) GetMovingNamingFormat() string {
|
||||
return DefaultNamingFormat
|
||||
}
|
||||
return s
|
||||
}
|
||||
}
|
||||
|
||||
114
ent/blocklist.go
Normal file
114
ent/blocklist.go
Normal file
@@ -0,0 +1,114 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"polaris/ent/blocklist"
|
||||
"strings"
|
||||
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// Blocklist is the model entity for the Blocklist schema.
|
||||
type Blocklist struct {
|
||||
config `json:"-"`
|
||||
// ID of the ent.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Type holds the value of the "type" field.
|
||||
Type blocklist.Type `json:"type,omitempty"`
|
||||
// Value holds the value of the "value" field.
|
||||
Value string `json:"value,omitempty"`
|
||||
selectValues sql.SelectValues
|
||||
}
|
||||
|
||||
// scanValues returns the types for scanning values from sql.Rows.
|
||||
func (*Blocklist) scanValues(columns []string) ([]any, error) {
|
||||
values := make([]any, len(columns))
|
||||
for i := range columns {
|
||||
switch columns[i] {
|
||||
case blocklist.FieldID:
|
||||
values[i] = new(sql.NullInt64)
|
||||
case blocklist.FieldType, blocklist.FieldValue:
|
||||
values[i] = new(sql.NullString)
|
||||
default:
|
||||
values[i] = new(sql.UnknownType)
|
||||
}
|
||||
}
|
||||
return values, nil
|
||||
}
|
||||
|
||||
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
||||
// to the Blocklist fields.
|
||||
func (b *Blocklist) 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 blocklist.FieldID:
|
||||
value, ok := values[i].(*sql.NullInt64)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field id", value)
|
||||
}
|
||||
b.ID = int(value.Int64)
|
||||
case blocklist.FieldType:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field type", values[i])
|
||||
} else if value.Valid {
|
||||
b.Type = blocklist.Type(value.String)
|
||||
}
|
||||
case blocklist.FieldValue:
|
||||
if value, ok := values[i].(*sql.NullString); !ok {
|
||||
return fmt.Errorf("unexpected type %T for field value", values[i])
|
||||
} else if value.Valid {
|
||||
b.Value = value.String
|
||||
}
|
||||
default:
|
||||
b.selectValues.Set(columns[i], values[i])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetValue returns the ent.Value that was dynamically selected and assigned to the Blocklist.
|
||||
// This includes values selected through modifiers, order, etc.
|
||||
func (b *Blocklist) GetValue(name string) (ent.Value, error) {
|
||||
return b.selectValues.Get(name)
|
||||
}
|
||||
|
||||
// Update returns a builder for updating this Blocklist.
|
||||
// Note that you need to call Blocklist.Unwrap() before calling this method if this Blocklist
|
||||
// was returned from a transaction, and the transaction was committed or rolled back.
|
||||
func (b *Blocklist) Update() *BlocklistUpdateOne {
|
||||
return NewBlocklistClient(b.config).UpdateOne(b)
|
||||
}
|
||||
|
||||
// Unwrap unwraps the Blocklist 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 (b *Blocklist) Unwrap() *Blocklist {
|
||||
_tx, ok := b.config.driver.(*txDriver)
|
||||
if !ok {
|
||||
panic("ent: Blocklist is not a transactional entity")
|
||||
}
|
||||
b.config.driver = _tx.drv
|
||||
return b
|
||||
}
|
||||
|
||||
// String implements the fmt.Stringer.
|
||||
func (b *Blocklist) String() string {
|
||||
var builder strings.Builder
|
||||
builder.WriteString("Blocklist(")
|
||||
builder.WriteString(fmt.Sprintf("id=%v, ", b.ID))
|
||||
builder.WriteString("type=")
|
||||
builder.WriteString(fmt.Sprintf("%v", b.Type))
|
||||
builder.WriteString(", ")
|
||||
builder.WriteString("value=")
|
||||
builder.WriteString(b.Value)
|
||||
builder.WriteByte(')')
|
||||
return builder.String()
|
||||
}
|
||||
|
||||
// Blocklists is a parsable slice of Blocklist.
|
||||
type Blocklists []*Blocklist
|
||||
80
ent/blocklist/blocklist.go
Normal file
80
ent/blocklist/blocklist.go
Normal file
@@ -0,0 +1,80 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package blocklist
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
const (
|
||||
// Label holds the string label denoting the blocklist type in the database.
|
||||
Label = "blocklist"
|
||||
// FieldID holds the string denoting the id field in the database.
|
||||
FieldID = "id"
|
||||
// FieldType holds the string denoting the type field in the database.
|
||||
FieldType = "type"
|
||||
// FieldValue holds the string denoting the value field in the database.
|
||||
FieldValue = "value"
|
||||
// Table holds the table name of the blocklist in the database.
|
||||
Table = "blocklists"
|
||||
)
|
||||
|
||||
// Columns holds all SQL columns for blocklist fields.
|
||||
var Columns = []string{
|
||||
FieldID,
|
||||
FieldType,
|
||||
FieldValue,
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
// Type defines the type for the "type" enum field.
|
||||
type Type string
|
||||
|
||||
// Type values.
|
||||
const (
|
||||
TypeMedia Type = "media"
|
||||
TypeTorrent Type = "torrent"
|
||||
)
|
||||
|
||||
func (_type Type) String() string {
|
||||
return string(_type)
|
||||
}
|
||||
|
||||
// TypeValidator is a validator for the "type" field enum values. It is called by the builders before save.
|
||||
func TypeValidator(_type Type) error {
|
||||
switch _type {
|
||||
case TypeMedia, TypeTorrent:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("blocklist: invalid enum value for type field: %q", _type)
|
||||
}
|
||||
}
|
||||
|
||||
// OrderOption defines the ordering options for the Blocklist 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()
|
||||
}
|
||||
|
||||
// ByType orders the results by the type field.
|
||||
func ByType(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldType, opts...).ToFunc()
|
||||
}
|
||||
|
||||
// ByValue orders the results by the value field.
|
||||
func ByValue(opts ...sql.OrderTermOption) OrderOption {
|
||||
return sql.OrderByField(FieldValue, opts...).ToFunc()
|
||||
}
|
||||
159
ent/blocklist/where.go
Normal file
159
ent/blocklist/where.go
Normal file
@@ -0,0 +1,159 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package blocklist
|
||||
|
||||
import (
|
||||
"polaris/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// ID filters vertices based on their ID field.
|
||||
func ID(id int) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDEQ applies the EQ predicate on the ID field.
|
||||
func IDEQ(id int) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDNEQ applies the NEQ predicate on the ID field.
|
||||
func IDNEQ(id int) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldNEQ(FieldID, id))
|
||||
}
|
||||
|
||||
// IDIn applies the In predicate on the ID field.
|
||||
func IDIn(ids ...int) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDNotIn applies the NotIn predicate on the ID field.
|
||||
func IDNotIn(ids ...int) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldNotIn(FieldID, ids...))
|
||||
}
|
||||
|
||||
// IDGT applies the GT predicate on the ID field.
|
||||
func IDGT(id int) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldGT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDGTE applies the GTE predicate on the ID field.
|
||||
func IDGTE(id int) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldGTE(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLT applies the LT predicate on the ID field.
|
||||
func IDLT(id int) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldLT(FieldID, id))
|
||||
}
|
||||
|
||||
// IDLTE applies the LTE predicate on the ID field.
|
||||
func IDLTE(id int) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldLTE(FieldID, id))
|
||||
}
|
||||
|
||||
// Value applies equality check predicate on the "value" field. It's identical to ValueEQ.
|
||||
func Value(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldEQ(FieldValue, v))
|
||||
}
|
||||
|
||||
// TypeEQ applies the EQ predicate on the "type" field.
|
||||
func TypeEQ(v Type) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeNEQ applies the NEQ predicate on the "type" field.
|
||||
func TypeNEQ(v Type) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldNEQ(FieldType, v))
|
||||
}
|
||||
|
||||
// TypeIn applies the In predicate on the "type" field.
|
||||
func TypeIn(vs ...Type) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// TypeNotIn applies the NotIn predicate on the "type" field.
|
||||
func TypeNotIn(vs ...Type) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldNotIn(FieldType, vs...))
|
||||
}
|
||||
|
||||
// ValueEQ applies the EQ predicate on the "value" field.
|
||||
func ValueEQ(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldEQ(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueNEQ applies the NEQ predicate on the "value" field.
|
||||
func ValueNEQ(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldNEQ(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueIn applies the In predicate on the "value" field.
|
||||
func ValueIn(vs ...string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldIn(FieldValue, vs...))
|
||||
}
|
||||
|
||||
// ValueNotIn applies the NotIn predicate on the "value" field.
|
||||
func ValueNotIn(vs ...string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldNotIn(FieldValue, vs...))
|
||||
}
|
||||
|
||||
// ValueGT applies the GT predicate on the "value" field.
|
||||
func ValueGT(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldGT(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueGTE applies the GTE predicate on the "value" field.
|
||||
func ValueGTE(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldGTE(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueLT applies the LT predicate on the "value" field.
|
||||
func ValueLT(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldLT(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueLTE applies the LTE predicate on the "value" field.
|
||||
func ValueLTE(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldLTE(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueContains applies the Contains predicate on the "value" field.
|
||||
func ValueContains(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldContains(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueHasPrefix applies the HasPrefix predicate on the "value" field.
|
||||
func ValueHasPrefix(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldHasPrefix(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueHasSuffix applies the HasSuffix predicate on the "value" field.
|
||||
func ValueHasSuffix(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldHasSuffix(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueEqualFold applies the EqualFold predicate on the "value" field.
|
||||
func ValueEqualFold(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldEqualFold(FieldValue, v))
|
||||
}
|
||||
|
||||
// ValueContainsFold applies the ContainsFold predicate on the "value" field.
|
||||
func ValueContainsFold(v string) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.FieldContainsFold(FieldValue, v))
|
||||
}
|
||||
|
||||
// And groups predicates with the AND operator between them.
|
||||
func And(predicates ...predicate.Blocklist) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.AndPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Or groups predicates with the OR operator between them.
|
||||
func Or(predicates ...predicate.Blocklist) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.OrPredicates(predicates...))
|
||||
}
|
||||
|
||||
// Not applies the not operator on the given predicate.
|
||||
func Not(p predicate.Blocklist) predicate.Blocklist {
|
||||
return predicate.Blocklist(sql.NotPredicates(p))
|
||||
}
|
||||
201
ent/blocklist_create.go
Normal file
201
ent/blocklist_create.go
Normal file
@@ -0,0 +1,201 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"polaris/ent/blocklist"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// BlocklistCreate is the builder for creating a Blocklist entity.
|
||||
type BlocklistCreate struct {
|
||||
config
|
||||
mutation *BlocklistMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (bc *BlocklistCreate) SetType(b blocklist.Type) *BlocklistCreate {
|
||||
bc.mutation.SetType(b)
|
||||
return bc
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (bc *BlocklistCreate) SetValue(s string) *BlocklistCreate {
|
||||
bc.mutation.SetValue(s)
|
||||
return bc
|
||||
}
|
||||
|
||||
// Mutation returns the BlocklistMutation object of the builder.
|
||||
func (bc *BlocklistCreate) Mutation() *BlocklistMutation {
|
||||
return bc.mutation
|
||||
}
|
||||
|
||||
// Save creates the Blocklist in the database.
|
||||
func (bc *BlocklistCreate) Save(ctx context.Context) (*Blocklist, error) {
|
||||
return withHooks(ctx, bc.sqlSave, bc.mutation, bc.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (bc *BlocklistCreate) SaveX(ctx context.Context) *Blocklist {
|
||||
v, err := bc.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (bc *BlocklistCreate) Exec(ctx context.Context) error {
|
||||
_, err := bc.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (bc *BlocklistCreate) ExecX(ctx context.Context) {
|
||||
if err := bc.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (bc *BlocklistCreate) check() error {
|
||||
if _, ok := bc.mutation.GetType(); !ok {
|
||||
return &ValidationError{Name: "type", err: errors.New(`ent: missing required field "Blocklist.type"`)}
|
||||
}
|
||||
if v, ok := bc.mutation.GetType(); ok {
|
||||
if err := blocklist.TypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Blocklist.type": %w`, err)}
|
||||
}
|
||||
}
|
||||
if _, ok := bc.mutation.Value(); !ok {
|
||||
return &ValidationError{Name: "value", err: errors.New(`ent: missing required field "Blocklist.value"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (bc *BlocklistCreate) sqlSave(ctx context.Context) (*Blocklist, error) {
|
||||
if err := bc.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := bc.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, bc.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 = int(id)
|
||||
bc.mutation.id = &_node.ID
|
||||
bc.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (bc *BlocklistCreate) createSpec() (*Blocklist, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &Blocklist{config: bc.config}
|
||||
_spec = sqlgraph.NewCreateSpec(blocklist.Table, sqlgraph.NewFieldSpec(blocklist.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := bc.mutation.GetType(); ok {
|
||||
_spec.SetField(blocklist.FieldType, field.TypeEnum, value)
|
||||
_node.Type = value
|
||||
}
|
||||
if value, ok := bc.mutation.Value(); ok {
|
||||
_spec.SetField(blocklist.FieldValue, field.TypeString, value)
|
||||
_node.Value = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// BlocklistCreateBulk is the builder for creating many Blocklist entities in bulk.
|
||||
type BlocklistCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*BlocklistCreate
|
||||
}
|
||||
|
||||
// Save creates the Blocklist entities in the database.
|
||||
func (bcb *BlocklistCreateBulk) Save(ctx context.Context) ([]*Blocklist, error) {
|
||||
if bcb.err != nil {
|
||||
return nil, bcb.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(bcb.builders))
|
||||
nodes := make([]*Blocklist, len(bcb.builders))
|
||||
mutators := make([]Mutator, len(bcb.builders))
|
||||
for i := range bcb.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := bcb.builders[i]
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*BlocklistMutation)
|
||||
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, bcb.builders[i+1].mutation)
|
||||
} else {
|
||||
spec := &sqlgraph.BatchCreateSpec{Nodes: specs}
|
||||
// Invoke the actual operation on the latest mutation in the chain.
|
||||
if err = sqlgraph.BatchCreate(ctx, bcb.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 = int(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, bcb.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (bcb *BlocklistCreateBulk) SaveX(ctx context.Context) []*Blocklist {
|
||||
v, err := bcb.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (bcb *BlocklistCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := bcb.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (bcb *BlocklistCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := bcb.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
88
ent/blocklist_delete.go
Normal file
88
ent/blocklist_delete.go
Normal file
@@ -0,0 +1,88 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"polaris/ent/blocklist"
|
||||
"polaris/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// BlocklistDelete is the builder for deleting a Blocklist entity.
|
||||
type BlocklistDelete struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *BlocklistMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the BlocklistDelete builder.
|
||||
func (bd *BlocklistDelete) Where(ps ...predicate.Blocklist) *BlocklistDelete {
|
||||
bd.mutation.Where(ps...)
|
||||
return bd
|
||||
}
|
||||
|
||||
// Exec executes the deletion query and returns how many vertices were deleted.
|
||||
func (bd *BlocklistDelete) Exec(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, bd.sqlExec, bd.mutation, bd.hooks)
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (bd *BlocklistDelete) ExecX(ctx context.Context) int {
|
||||
n, err := bd.Exec(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return n
|
||||
}
|
||||
|
||||
func (bd *BlocklistDelete) sqlExec(ctx context.Context) (int, error) {
|
||||
_spec := sqlgraph.NewDeleteSpec(blocklist.Table, sqlgraph.NewFieldSpec(blocklist.FieldID, field.TypeInt))
|
||||
if ps := bd.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
affected, err := sqlgraph.DeleteNodes(ctx, bd.driver, _spec)
|
||||
if err != nil && sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
bd.mutation.done = true
|
||||
return affected, err
|
||||
}
|
||||
|
||||
// BlocklistDeleteOne is the builder for deleting a single Blocklist entity.
|
||||
type BlocklistDeleteOne struct {
|
||||
bd *BlocklistDelete
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the BlocklistDelete builder.
|
||||
func (bdo *BlocklistDeleteOne) Where(ps ...predicate.Blocklist) *BlocklistDeleteOne {
|
||||
bdo.bd.mutation.Where(ps...)
|
||||
return bdo
|
||||
}
|
||||
|
||||
// Exec executes the deletion query.
|
||||
func (bdo *BlocklistDeleteOne) Exec(ctx context.Context) error {
|
||||
n, err := bdo.bd.Exec(ctx)
|
||||
switch {
|
||||
case err != nil:
|
||||
return err
|
||||
case n == 0:
|
||||
return &NotFoundError{blocklist.Label}
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (bdo *BlocklistDeleteOne) ExecX(ctx context.Context) {
|
||||
if err := bdo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
526
ent/blocklist_query.go
Normal file
526
ent/blocklist_query.go
Normal file
@@ -0,0 +1,526 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"polaris/ent/blocklist"
|
||||
"polaris/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// BlocklistQuery is the builder for querying Blocklist entities.
|
||||
type BlocklistQuery struct {
|
||||
config
|
||||
ctx *QueryContext
|
||||
order []blocklist.OrderOption
|
||||
inters []Interceptor
|
||||
predicates []predicate.Blocklist
|
||||
// intermediate query (i.e. traversal path).
|
||||
sql *sql.Selector
|
||||
path func(context.Context) (*sql.Selector, error)
|
||||
}
|
||||
|
||||
// Where adds a new predicate for the BlocklistQuery builder.
|
||||
func (bq *BlocklistQuery) Where(ps ...predicate.Blocklist) *BlocklistQuery {
|
||||
bq.predicates = append(bq.predicates, ps...)
|
||||
return bq
|
||||
}
|
||||
|
||||
// Limit the number of records to be returned by this query.
|
||||
func (bq *BlocklistQuery) Limit(limit int) *BlocklistQuery {
|
||||
bq.ctx.Limit = &limit
|
||||
return bq
|
||||
}
|
||||
|
||||
// Offset to start from.
|
||||
func (bq *BlocklistQuery) Offset(offset int) *BlocklistQuery {
|
||||
bq.ctx.Offset = &offset
|
||||
return bq
|
||||
}
|
||||
|
||||
// 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 (bq *BlocklistQuery) Unique(unique bool) *BlocklistQuery {
|
||||
bq.ctx.Unique = &unique
|
||||
return bq
|
||||
}
|
||||
|
||||
// Order specifies how the records should be ordered.
|
||||
func (bq *BlocklistQuery) Order(o ...blocklist.OrderOption) *BlocklistQuery {
|
||||
bq.order = append(bq.order, o...)
|
||||
return bq
|
||||
}
|
||||
|
||||
// First returns the first Blocklist entity from the query.
|
||||
// Returns a *NotFoundError when no Blocklist was found.
|
||||
func (bq *BlocklistQuery) First(ctx context.Context) (*Blocklist, error) {
|
||||
nodes, err := bq.Limit(1).All(setContextOp(ctx, bq.ctx, "First"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nil, &NotFoundError{blocklist.Label}
|
||||
}
|
||||
return nodes[0], nil
|
||||
}
|
||||
|
||||
// FirstX is like First, but panics if an error occurs.
|
||||
func (bq *BlocklistQuery) FirstX(ctx context.Context) *Blocklist {
|
||||
node, err := bq.First(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// FirstID returns the first Blocklist ID from the query.
|
||||
// Returns a *NotFoundError when no Blocklist ID was found.
|
||||
func (bq *BlocklistQuery) FirstID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = bq.Limit(1).IDs(setContextOp(ctx, bq.ctx, "FirstID")); err != nil {
|
||||
return
|
||||
}
|
||||
if len(ids) == 0 {
|
||||
err = &NotFoundError{blocklist.Label}
|
||||
return
|
||||
}
|
||||
return ids[0], nil
|
||||
}
|
||||
|
||||
// FirstIDX is like FirstID, but panics if an error occurs.
|
||||
func (bq *BlocklistQuery) FirstIDX(ctx context.Context) int {
|
||||
id, err := bq.FirstID(ctx)
|
||||
if err != nil && !IsNotFound(err) {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// Only returns a single Blocklist entity found by the query, ensuring it only returns one.
|
||||
// Returns a *NotSingularError when more than one Blocklist entity is found.
|
||||
// Returns a *NotFoundError when no Blocklist entities are found.
|
||||
func (bq *BlocklistQuery) Only(ctx context.Context) (*Blocklist, error) {
|
||||
nodes, err := bq.Limit(2).All(setContextOp(ctx, bq.ctx, "Only"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
switch len(nodes) {
|
||||
case 1:
|
||||
return nodes[0], nil
|
||||
case 0:
|
||||
return nil, &NotFoundError{blocklist.Label}
|
||||
default:
|
||||
return nil, &NotSingularError{blocklist.Label}
|
||||
}
|
||||
}
|
||||
|
||||
// OnlyX is like Only, but panics if an error occurs.
|
||||
func (bq *BlocklistQuery) OnlyX(ctx context.Context) *Blocklist {
|
||||
node, err := bq.Only(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// OnlyID is like Only, but returns the only Blocklist ID in the query.
|
||||
// Returns a *NotSingularError when more than one Blocklist ID is found.
|
||||
// Returns a *NotFoundError when no entities are found.
|
||||
func (bq *BlocklistQuery) OnlyID(ctx context.Context) (id int, err error) {
|
||||
var ids []int
|
||||
if ids, err = bq.Limit(2).IDs(setContextOp(ctx, bq.ctx, "OnlyID")); err != nil {
|
||||
return
|
||||
}
|
||||
switch len(ids) {
|
||||
case 1:
|
||||
id = ids[0]
|
||||
case 0:
|
||||
err = &NotFoundError{blocklist.Label}
|
||||
default:
|
||||
err = &NotSingularError{blocklist.Label}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// OnlyIDX is like OnlyID, but panics if an error occurs.
|
||||
func (bq *BlocklistQuery) OnlyIDX(ctx context.Context) int {
|
||||
id, err := bq.OnlyID(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return id
|
||||
}
|
||||
|
||||
// All executes the query and returns a list of Blocklists.
|
||||
func (bq *BlocklistQuery) All(ctx context.Context) ([]*Blocklist, error) {
|
||||
ctx = setContextOp(ctx, bq.ctx, "All")
|
||||
if err := bq.prepareQuery(ctx); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qr := querierAll[[]*Blocklist, *BlocklistQuery]()
|
||||
return withInterceptors[[]*Blocklist](ctx, bq, qr, bq.inters)
|
||||
}
|
||||
|
||||
// AllX is like All, but panics if an error occurs.
|
||||
func (bq *BlocklistQuery) AllX(ctx context.Context) []*Blocklist {
|
||||
nodes, err := bq.All(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodes
|
||||
}
|
||||
|
||||
// IDs executes the query and returns a list of Blocklist IDs.
|
||||
func (bq *BlocklistQuery) IDs(ctx context.Context) (ids []int, err error) {
|
||||
if bq.ctx.Unique == nil && bq.path != nil {
|
||||
bq.Unique(true)
|
||||
}
|
||||
ctx = setContextOp(ctx, bq.ctx, "IDs")
|
||||
if err = bq.Select(blocklist.FieldID).Scan(ctx, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// IDsX is like IDs, but panics if an error occurs.
|
||||
func (bq *BlocklistQuery) IDsX(ctx context.Context) []int {
|
||||
ids, err := bq.IDs(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return ids
|
||||
}
|
||||
|
||||
// Count returns the count of the given query.
|
||||
func (bq *BlocklistQuery) Count(ctx context.Context) (int, error) {
|
||||
ctx = setContextOp(ctx, bq.ctx, "Count")
|
||||
if err := bq.prepareQuery(ctx); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return withInterceptors[int](ctx, bq, querierCount[*BlocklistQuery](), bq.inters)
|
||||
}
|
||||
|
||||
// CountX is like Count, but panics if an error occurs.
|
||||
func (bq *BlocklistQuery) CountX(ctx context.Context) int {
|
||||
count, err := bq.Count(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// Exist returns true if the query has elements in the graph.
|
||||
func (bq *BlocklistQuery) Exist(ctx context.Context) (bool, error) {
|
||||
ctx = setContextOp(ctx, bq.ctx, "Exist")
|
||||
switch _, err := bq.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 (bq *BlocklistQuery) ExistX(ctx context.Context) bool {
|
||||
exist, err := bq.Exist(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return exist
|
||||
}
|
||||
|
||||
// Clone returns a duplicate of the BlocklistQuery builder, including all associated steps. It can be
|
||||
// used to prepare common query builders and use them differently after the clone is made.
|
||||
func (bq *BlocklistQuery) Clone() *BlocklistQuery {
|
||||
if bq == nil {
|
||||
return nil
|
||||
}
|
||||
return &BlocklistQuery{
|
||||
config: bq.config,
|
||||
ctx: bq.ctx.Clone(),
|
||||
order: append([]blocklist.OrderOption{}, bq.order...),
|
||||
inters: append([]Interceptor{}, bq.inters...),
|
||||
predicates: append([]predicate.Blocklist{}, bq.predicates...),
|
||||
// clone intermediate query.
|
||||
sql: bq.sql.Clone(),
|
||||
path: bq.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 {
|
||||
// Type blocklist.Type `json:"type,omitempty"`
|
||||
// Count int `json:"count,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Blocklist.Query().
|
||||
// GroupBy(blocklist.FieldType).
|
||||
// Aggregate(ent.Count()).
|
||||
// Scan(ctx, &v)
|
||||
func (bq *BlocklistQuery) GroupBy(field string, fields ...string) *BlocklistGroupBy {
|
||||
bq.ctx.Fields = append([]string{field}, fields...)
|
||||
grbuild := &BlocklistGroupBy{build: bq}
|
||||
grbuild.flds = &bq.ctx.Fields
|
||||
grbuild.label = blocklist.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 {
|
||||
// Type blocklist.Type `json:"type,omitempty"`
|
||||
// }
|
||||
//
|
||||
// client.Blocklist.Query().
|
||||
// Select(blocklist.FieldType).
|
||||
// Scan(ctx, &v)
|
||||
func (bq *BlocklistQuery) Select(fields ...string) *BlocklistSelect {
|
||||
bq.ctx.Fields = append(bq.ctx.Fields, fields...)
|
||||
sbuild := &BlocklistSelect{BlocklistQuery: bq}
|
||||
sbuild.label = blocklist.Label
|
||||
sbuild.flds, sbuild.scan = &bq.ctx.Fields, sbuild.Scan
|
||||
return sbuild
|
||||
}
|
||||
|
||||
// Aggregate returns a BlocklistSelect configured with the given aggregations.
|
||||
func (bq *BlocklistQuery) Aggregate(fns ...AggregateFunc) *BlocklistSelect {
|
||||
return bq.Select().Aggregate(fns...)
|
||||
}
|
||||
|
||||
func (bq *BlocklistQuery) prepareQuery(ctx context.Context) error {
|
||||
for _, inter := range bq.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, bq); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, f := range bq.ctx.Fields {
|
||||
if !blocklist.ValidColumn(f) {
|
||||
return &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
}
|
||||
if bq.path != nil {
|
||||
prev, err := bq.path(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
bq.sql = prev
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (bq *BlocklistQuery) sqlAll(ctx context.Context, hooks ...queryHook) ([]*Blocklist, error) {
|
||||
var (
|
||||
nodes = []*Blocklist{}
|
||||
_spec = bq.querySpec()
|
||||
)
|
||||
_spec.ScanValues = func(columns []string) ([]any, error) {
|
||||
return (*Blocklist).scanValues(nil, columns)
|
||||
}
|
||||
_spec.Assign = func(columns []string, values []any) error {
|
||||
node := &Blocklist{config: bq.config}
|
||||
nodes = append(nodes, node)
|
||||
return node.assignValues(columns, values)
|
||||
}
|
||||
for i := range hooks {
|
||||
hooks[i](ctx, _spec)
|
||||
}
|
||||
if err := sqlgraph.QueryNodes(ctx, bq.driver, _spec); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(nodes) == 0 {
|
||||
return nodes, nil
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
func (bq *BlocklistQuery) sqlCount(ctx context.Context) (int, error) {
|
||||
_spec := bq.querySpec()
|
||||
_spec.Node.Columns = bq.ctx.Fields
|
||||
if len(bq.ctx.Fields) > 0 {
|
||||
_spec.Unique = bq.ctx.Unique != nil && *bq.ctx.Unique
|
||||
}
|
||||
return sqlgraph.CountNodes(ctx, bq.driver, _spec)
|
||||
}
|
||||
|
||||
func (bq *BlocklistQuery) querySpec() *sqlgraph.QuerySpec {
|
||||
_spec := sqlgraph.NewQuerySpec(blocklist.Table, blocklist.Columns, sqlgraph.NewFieldSpec(blocklist.FieldID, field.TypeInt))
|
||||
_spec.From = bq.sql
|
||||
if unique := bq.ctx.Unique; unique != nil {
|
||||
_spec.Unique = *unique
|
||||
} else if bq.path != nil {
|
||||
_spec.Unique = true
|
||||
}
|
||||
if fields := bq.ctx.Fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, blocklist.FieldID)
|
||||
for i := range fields {
|
||||
if fields[i] != blocklist.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, fields[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := bq.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if limit := bq.ctx.Limit; limit != nil {
|
||||
_spec.Limit = *limit
|
||||
}
|
||||
if offset := bq.ctx.Offset; offset != nil {
|
||||
_spec.Offset = *offset
|
||||
}
|
||||
if ps := bq.order; len(ps) > 0 {
|
||||
_spec.Order = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
return _spec
|
||||
}
|
||||
|
||||
func (bq *BlocklistQuery) sqlQuery(ctx context.Context) *sql.Selector {
|
||||
builder := sql.Dialect(bq.driver.Dialect())
|
||||
t1 := builder.Table(blocklist.Table)
|
||||
columns := bq.ctx.Fields
|
||||
if len(columns) == 0 {
|
||||
columns = blocklist.Columns
|
||||
}
|
||||
selector := builder.Select(t1.Columns(columns...)...).From(t1)
|
||||
if bq.sql != nil {
|
||||
selector = bq.sql
|
||||
selector.Select(selector.Columns(columns...)...)
|
||||
}
|
||||
if bq.ctx.Unique != nil && *bq.ctx.Unique {
|
||||
selector.Distinct()
|
||||
}
|
||||
for _, p := range bq.predicates {
|
||||
p(selector)
|
||||
}
|
||||
for _, p := range bq.order {
|
||||
p(selector)
|
||||
}
|
||||
if offset := bq.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 := bq.ctx.Limit; limit != nil {
|
||||
selector.Limit(*limit)
|
||||
}
|
||||
return selector
|
||||
}
|
||||
|
||||
// BlocklistGroupBy is the group-by builder for Blocklist entities.
|
||||
type BlocklistGroupBy struct {
|
||||
selector
|
||||
build *BlocklistQuery
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the group-by query.
|
||||
func (bgb *BlocklistGroupBy) Aggregate(fns ...AggregateFunc) *BlocklistGroupBy {
|
||||
bgb.fns = append(bgb.fns, fns...)
|
||||
return bgb
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (bgb *BlocklistGroupBy) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, bgb.build.ctx, "GroupBy")
|
||||
if err := bgb.build.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*BlocklistQuery, *BlocklistGroupBy](ctx, bgb.build, bgb, bgb.build.inters, v)
|
||||
}
|
||||
|
||||
func (bgb *BlocklistGroupBy) sqlScan(ctx context.Context, root *BlocklistQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx).Select()
|
||||
aggregation := make([]string, 0, len(bgb.fns))
|
||||
for _, fn := range bgb.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
if len(selector.SelectedColumns()) == 0 {
|
||||
columns := make([]string, 0, len(*bgb.flds)+len(bgb.fns))
|
||||
for _, f := range *bgb.flds {
|
||||
columns = append(columns, selector.C(f))
|
||||
}
|
||||
columns = append(columns, aggregation...)
|
||||
selector.Select(columns...)
|
||||
}
|
||||
selector.GroupBy(selector.Columns(*bgb.flds...)...)
|
||||
if err := selector.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
rows := &sql.Rows{}
|
||||
query, args := selector.Query()
|
||||
if err := bgb.build.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
|
||||
// BlocklistSelect is the builder for selecting fields of Blocklist entities.
|
||||
type BlocklistSelect struct {
|
||||
*BlocklistQuery
|
||||
selector
|
||||
}
|
||||
|
||||
// Aggregate adds the given aggregation functions to the selector query.
|
||||
func (bs *BlocklistSelect) Aggregate(fns ...AggregateFunc) *BlocklistSelect {
|
||||
bs.fns = append(bs.fns, fns...)
|
||||
return bs
|
||||
}
|
||||
|
||||
// Scan applies the selector query and scans the result into the given value.
|
||||
func (bs *BlocklistSelect) Scan(ctx context.Context, v any) error {
|
||||
ctx = setContextOp(ctx, bs.ctx, "Select")
|
||||
if err := bs.prepareQuery(ctx); err != nil {
|
||||
return err
|
||||
}
|
||||
return scanWithInterceptors[*BlocklistQuery, *BlocklistSelect](ctx, bs.BlocklistQuery, bs, bs.inters, v)
|
||||
}
|
||||
|
||||
func (bs *BlocklistSelect) sqlScan(ctx context.Context, root *BlocklistQuery, v any) error {
|
||||
selector := root.sqlQuery(ctx)
|
||||
aggregation := make([]string, 0, len(bs.fns))
|
||||
for _, fn := range bs.fns {
|
||||
aggregation = append(aggregation, fn(selector))
|
||||
}
|
||||
switch n := len(*bs.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 := bs.driver.Query(ctx, query, args, rows); err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
return sql.ScanSlice(rows, v)
|
||||
}
|
||||
269
ent/blocklist_update.go
Normal file
269
ent/blocklist_update.go
Normal file
@@ -0,0 +1,269 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"polaris/ent/blocklist"
|
||||
"polaris/ent/predicate"
|
||||
|
||||
"entgo.io/ent/dialect/sql"
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// BlocklistUpdate is the builder for updating Blocklist entities.
|
||||
type BlocklistUpdate struct {
|
||||
config
|
||||
hooks []Hook
|
||||
mutation *BlocklistMutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the BlocklistUpdate builder.
|
||||
func (bu *BlocklistUpdate) Where(ps ...predicate.Blocklist) *BlocklistUpdate {
|
||||
bu.mutation.Where(ps...)
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (bu *BlocklistUpdate) SetType(b blocklist.Type) *BlocklistUpdate {
|
||||
bu.mutation.SetType(b)
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetNillableType sets the "type" field if the given value is not nil.
|
||||
func (bu *BlocklistUpdate) SetNillableType(b *blocklist.Type) *BlocklistUpdate {
|
||||
if b != nil {
|
||||
bu.SetType(*b)
|
||||
}
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (bu *BlocklistUpdate) SetValue(s string) *BlocklistUpdate {
|
||||
bu.mutation.SetValue(s)
|
||||
return bu
|
||||
}
|
||||
|
||||
// SetNillableValue sets the "value" field if the given value is not nil.
|
||||
func (bu *BlocklistUpdate) SetNillableValue(s *string) *BlocklistUpdate {
|
||||
if s != nil {
|
||||
bu.SetValue(*s)
|
||||
}
|
||||
return bu
|
||||
}
|
||||
|
||||
// Mutation returns the BlocklistMutation object of the builder.
|
||||
func (bu *BlocklistUpdate) Mutation() *BlocklistMutation {
|
||||
return bu.mutation
|
||||
}
|
||||
|
||||
// Save executes the query and returns the number of nodes affected by the update operation.
|
||||
func (bu *BlocklistUpdate) Save(ctx context.Context) (int, error) {
|
||||
return withHooks(ctx, bu.sqlSave, bu.mutation, bu.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (bu *BlocklistUpdate) SaveX(ctx context.Context) int {
|
||||
affected, err := bu.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return affected
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (bu *BlocklistUpdate) Exec(ctx context.Context) error {
|
||||
_, err := bu.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (bu *BlocklistUpdate) ExecX(ctx context.Context) {
|
||||
if err := bu.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (bu *BlocklistUpdate) check() error {
|
||||
if v, ok := bu.mutation.GetType(); ok {
|
||||
if err := blocklist.TypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Blocklist.type": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (bu *BlocklistUpdate) sqlSave(ctx context.Context) (n int, err error) {
|
||||
if err := bu.check(); err != nil {
|
||||
return n, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(blocklist.Table, blocklist.Columns, sqlgraph.NewFieldSpec(blocklist.FieldID, field.TypeInt))
|
||||
if ps := bu.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := bu.mutation.GetType(); ok {
|
||||
_spec.SetField(blocklist.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := bu.mutation.Value(); ok {
|
||||
_spec.SetField(blocklist.FieldValue, field.TypeString, value)
|
||||
}
|
||||
if n, err = sqlgraph.UpdateNodes(ctx, bu.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{blocklist.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return 0, err
|
||||
}
|
||||
bu.mutation.done = true
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// BlocklistUpdateOne is the builder for updating a single Blocklist entity.
|
||||
type BlocklistUpdateOne struct {
|
||||
config
|
||||
fields []string
|
||||
hooks []Hook
|
||||
mutation *BlocklistMutation
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (buo *BlocklistUpdateOne) SetType(b blocklist.Type) *BlocklistUpdateOne {
|
||||
buo.mutation.SetType(b)
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetNillableType sets the "type" field if the given value is not nil.
|
||||
func (buo *BlocklistUpdateOne) SetNillableType(b *blocklist.Type) *BlocklistUpdateOne {
|
||||
if b != nil {
|
||||
buo.SetType(*b)
|
||||
}
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (buo *BlocklistUpdateOne) SetValue(s string) *BlocklistUpdateOne {
|
||||
buo.mutation.SetValue(s)
|
||||
return buo
|
||||
}
|
||||
|
||||
// SetNillableValue sets the "value" field if the given value is not nil.
|
||||
func (buo *BlocklistUpdateOne) SetNillableValue(s *string) *BlocklistUpdateOne {
|
||||
if s != nil {
|
||||
buo.SetValue(*s)
|
||||
}
|
||||
return buo
|
||||
}
|
||||
|
||||
// Mutation returns the BlocklistMutation object of the builder.
|
||||
func (buo *BlocklistUpdateOne) Mutation() *BlocklistMutation {
|
||||
return buo.mutation
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the BlocklistUpdate builder.
|
||||
func (buo *BlocklistUpdateOne) Where(ps ...predicate.Blocklist) *BlocklistUpdateOne {
|
||||
buo.mutation.Where(ps...)
|
||||
return buo
|
||||
}
|
||||
|
||||
// Select allows selecting one or more fields (columns) of the returned entity.
|
||||
// The default is selecting all fields defined in the entity schema.
|
||||
func (buo *BlocklistUpdateOne) Select(field string, fields ...string) *BlocklistUpdateOne {
|
||||
buo.fields = append([]string{field}, fields...)
|
||||
return buo
|
||||
}
|
||||
|
||||
// Save executes the query and returns the updated Blocklist entity.
|
||||
func (buo *BlocklistUpdateOne) Save(ctx context.Context) (*Blocklist, error) {
|
||||
return withHooks(ctx, buo.sqlSave, buo.mutation, buo.hooks)
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (buo *BlocklistUpdateOne) SaveX(ctx context.Context) *Blocklist {
|
||||
node, err := buo.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return node
|
||||
}
|
||||
|
||||
// Exec executes the query on the entity.
|
||||
func (buo *BlocklistUpdateOne) Exec(ctx context.Context) error {
|
||||
_, err := buo.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (buo *BlocklistUpdateOne) ExecX(ctx context.Context) {
|
||||
if err := buo.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (buo *BlocklistUpdateOne) check() error {
|
||||
if v, ok := buo.mutation.GetType(); ok {
|
||||
if err := blocklist.TypeValidator(v); err != nil {
|
||||
return &ValidationError{Name: "type", err: fmt.Errorf(`ent: validator failed for field "Blocklist.type": %w`, err)}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (buo *BlocklistUpdateOne) sqlSave(ctx context.Context) (_node *Blocklist, err error) {
|
||||
if err := buo.check(); err != nil {
|
||||
return _node, err
|
||||
}
|
||||
_spec := sqlgraph.NewUpdateSpec(blocklist.Table, blocklist.Columns, sqlgraph.NewFieldSpec(blocklist.FieldID, field.TypeInt))
|
||||
id, ok := buo.mutation.ID()
|
||||
if !ok {
|
||||
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Blocklist.id" for update`)}
|
||||
}
|
||||
_spec.Node.ID.Value = id
|
||||
if fields := buo.fields; len(fields) > 0 {
|
||||
_spec.Node.Columns = make([]string, 0, len(fields))
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, blocklist.FieldID)
|
||||
for _, f := range fields {
|
||||
if !blocklist.ValidColumn(f) {
|
||||
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
|
||||
}
|
||||
if f != blocklist.FieldID {
|
||||
_spec.Node.Columns = append(_spec.Node.Columns, f)
|
||||
}
|
||||
}
|
||||
}
|
||||
if ps := buo.mutation.predicates; len(ps) > 0 {
|
||||
_spec.Predicate = func(selector *sql.Selector) {
|
||||
for i := range ps {
|
||||
ps[i](selector)
|
||||
}
|
||||
}
|
||||
}
|
||||
if value, ok := buo.mutation.GetType(); ok {
|
||||
_spec.SetField(blocklist.FieldType, field.TypeEnum, value)
|
||||
}
|
||||
if value, ok := buo.mutation.Value(); ok {
|
||||
_spec.SetField(blocklist.FieldValue, field.TypeString, value)
|
||||
}
|
||||
_node = &Blocklist{config: buo.config}
|
||||
_spec.Assign = _node.assignValues
|
||||
_spec.ScanValues = _node.scanValues
|
||||
if err = sqlgraph.UpdateNode(ctx, buo.driver, _spec); err != nil {
|
||||
if _, ok := err.(*sqlgraph.NotFoundError); ok {
|
||||
err = &NotFoundError{blocklist.Label}
|
||||
} else if sqlgraph.IsConstraintError(err) {
|
||||
err = &ConstraintError{msg: err.Error(), wrap: err}
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
buo.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
155
ent/client.go
155
ent/client.go
@@ -11,6 +11,7 @@ import (
|
||||
|
||||
"polaris/ent/migrate"
|
||||
|
||||
"polaris/ent/blocklist"
|
||||
"polaris/ent/downloadclients"
|
||||
"polaris/ent/episode"
|
||||
"polaris/ent/history"
|
||||
@@ -32,6 +33,8 @@ type Client struct {
|
||||
config
|
||||
// Schema is the client for creating, migrating and dropping schema.
|
||||
Schema *migrate.Schema
|
||||
// Blocklist is the client for interacting with the Blocklist builders.
|
||||
Blocklist *BlocklistClient
|
||||
// DownloadClients is the client for interacting with the DownloadClients builders.
|
||||
DownloadClients *DownloadClientsClient
|
||||
// Episode is the client for interacting with the Episode builders.
|
||||
@@ -61,6 +64,7 @@ func NewClient(opts ...Option) *Client {
|
||||
|
||||
func (c *Client) init() {
|
||||
c.Schema = migrate.NewSchema(c.driver)
|
||||
c.Blocklist = NewBlocklistClient(c.config)
|
||||
c.DownloadClients = NewDownloadClientsClient(c.config)
|
||||
c.Episode = NewEpisodeClient(c.config)
|
||||
c.History = NewHistoryClient(c.config)
|
||||
@@ -162,6 +166,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Blocklist: NewBlocklistClient(cfg),
|
||||
DownloadClients: NewDownloadClientsClient(cfg),
|
||||
Episode: NewEpisodeClient(cfg),
|
||||
History: NewHistoryClient(cfg),
|
||||
@@ -190,6 +195,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||
return &Tx{
|
||||
ctx: ctx,
|
||||
config: cfg,
|
||||
Blocklist: NewBlocklistClient(cfg),
|
||||
DownloadClients: NewDownloadClientsClient(cfg),
|
||||
Episode: NewEpisodeClient(cfg),
|
||||
History: NewHistoryClient(cfg),
|
||||
@@ -205,7 +211,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
|
||||
// Debug returns a new debug-client. It's used to get verbose logging on specific operations.
|
||||
//
|
||||
// client.Debug().
|
||||
// DownloadClients.
|
||||
// Blocklist.
|
||||
// Query().
|
||||
// Count(ctx)
|
||||
func (c *Client) Debug() *Client {
|
||||
@@ -228,8 +234,8 @@ func (c *Client) Close() error {
|
||||
// In order to add hooks to a specific client, call: `client.Node.Use(...)`.
|
||||
func (c *Client) Use(hooks ...Hook) {
|
||||
for _, n := range []interface{ Use(...Hook) }{
|
||||
c.DownloadClients, c.Episode, c.History, c.ImportList, c.Indexers, c.Media,
|
||||
c.NotificationClient, c.Settings, c.Storage,
|
||||
c.Blocklist, c.DownloadClients, c.Episode, c.History, c.ImportList, c.Indexers,
|
||||
c.Media, c.NotificationClient, c.Settings, c.Storage,
|
||||
} {
|
||||
n.Use(hooks...)
|
||||
}
|
||||
@@ -239,8 +245,8 @@ func (c *Client) Use(hooks ...Hook) {
|
||||
// In order to add interceptors to a specific client, call: `client.Node.Intercept(...)`.
|
||||
func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||
for _, n := range []interface{ Intercept(...Interceptor) }{
|
||||
c.DownloadClients, c.Episode, c.History, c.ImportList, c.Indexers, c.Media,
|
||||
c.NotificationClient, c.Settings, c.Storage,
|
||||
c.Blocklist, c.DownloadClients, c.Episode, c.History, c.ImportList, c.Indexers,
|
||||
c.Media, c.NotificationClient, c.Settings, c.Storage,
|
||||
} {
|
||||
n.Intercept(interceptors...)
|
||||
}
|
||||
@@ -249,6 +255,8 @@ func (c *Client) Intercept(interceptors ...Interceptor) {
|
||||
// Mutate implements the ent.Mutator interface.
|
||||
func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
switch m := m.(type) {
|
||||
case *BlocklistMutation:
|
||||
return c.Blocklist.mutate(ctx, m)
|
||||
case *DownloadClientsMutation:
|
||||
return c.DownloadClients.mutate(ctx, m)
|
||||
case *EpisodeMutation:
|
||||
@@ -272,6 +280,139 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
|
||||
}
|
||||
}
|
||||
|
||||
// BlocklistClient is a client for the Blocklist schema.
|
||||
type BlocklistClient struct {
|
||||
config
|
||||
}
|
||||
|
||||
// NewBlocklistClient returns a client for the Blocklist from the given config.
|
||||
func NewBlocklistClient(c config) *BlocklistClient {
|
||||
return &BlocklistClient{config: c}
|
||||
}
|
||||
|
||||
// Use adds a list of mutation hooks to the hooks stack.
|
||||
// A call to `Use(f, g, h)` equals to `blocklist.Hooks(f(g(h())))`.
|
||||
func (c *BlocklistClient) Use(hooks ...Hook) {
|
||||
c.hooks.Blocklist = append(c.hooks.Blocklist, hooks...)
|
||||
}
|
||||
|
||||
// Intercept adds a list of query interceptors to the interceptors stack.
|
||||
// A call to `Intercept(f, g, h)` equals to `blocklist.Intercept(f(g(h())))`.
|
||||
func (c *BlocklistClient) Intercept(interceptors ...Interceptor) {
|
||||
c.inters.Blocklist = append(c.inters.Blocklist, interceptors...)
|
||||
}
|
||||
|
||||
// Create returns a builder for creating a Blocklist entity.
|
||||
func (c *BlocklistClient) Create() *BlocklistCreate {
|
||||
mutation := newBlocklistMutation(c.config, OpCreate)
|
||||
return &BlocklistCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// CreateBulk returns a builder for creating a bulk of Blocklist entities.
|
||||
func (c *BlocklistClient) CreateBulk(builders ...*BlocklistCreate) *BlocklistCreateBulk {
|
||||
return &BlocklistCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
|
||||
// a builder and applies setFunc on it.
|
||||
func (c *BlocklistClient) MapCreateBulk(slice any, setFunc func(*BlocklistCreate, int)) *BlocklistCreateBulk {
|
||||
rv := reflect.ValueOf(slice)
|
||||
if rv.Kind() != reflect.Slice {
|
||||
return &BlocklistCreateBulk{err: fmt.Errorf("calling to BlocklistClient.MapCreateBulk with wrong type %T, need slice", slice)}
|
||||
}
|
||||
builders := make([]*BlocklistCreate, rv.Len())
|
||||
for i := 0; i < rv.Len(); i++ {
|
||||
builders[i] = c.Create()
|
||||
setFunc(builders[i], i)
|
||||
}
|
||||
return &BlocklistCreateBulk{config: c.config, builders: builders}
|
||||
}
|
||||
|
||||
// Update returns an update builder for Blocklist.
|
||||
func (c *BlocklistClient) Update() *BlocklistUpdate {
|
||||
mutation := newBlocklistMutation(c.config, OpUpdate)
|
||||
return &BlocklistUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOne returns an update builder for the given entity.
|
||||
func (c *BlocklistClient) UpdateOne(b *Blocklist) *BlocklistUpdateOne {
|
||||
mutation := newBlocklistMutation(c.config, OpUpdateOne, withBlocklist(b))
|
||||
return &BlocklistUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// UpdateOneID returns an update builder for the given id.
|
||||
func (c *BlocklistClient) UpdateOneID(id int) *BlocklistUpdateOne {
|
||||
mutation := newBlocklistMutation(c.config, OpUpdateOne, withBlocklistID(id))
|
||||
return &BlocklistUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// Delete returns a delete builder for Blocklist.
|
||||
func (c *BlocklistClient) Delete() *BlocklistDelete {
|
||||
mutation := newBlocklistMutation(c.config, OpDelete)
|
||||
return &BlocklistDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
|
||||
}
|
||||
|
||||
// DeleteOne returns a builder for deleting the given entity.
|
||||
func (c *BlocklistClient) DeleteOne(b *Blocklist) *BlocklistDeleteOne {
|
||||
return c.DeleteOneID(b.ID)
|
||||
}
|
||||
|
||||
// DeleteOneID returns a builder for deleting the given entity by its id.
|
||||
func (c *BlocklistClient) DeleteOneID(id int) *BlocklistDeleteOne {
|
||||
builder := c.Delete().Where(blocklist.ID(id))
|
||||
builder.mutation.id = &id
|
||||
builder.mutation.op = OpDeleteOne
|
||||
return &BlocklistDeleteOne{builder}
|
||||
}
|
||||
|
||||
// Query returns a query builder for Blocklist.
|
||||
func (c *BlocklistClient) Query() *BlocklistQuery {
|
||||
return &BlocklistQuery{
|
||||
config: c.config,
|
||||
ctx: &QueryContext{Type: TypeBlocklist},
|
||||
inters: c.Interceptors(),
|
||||
}
|
||||
}
|
||||
|
||||
// Get returns a Blocklist entity by its id.
|
||||
func (c *BlocklistClient) Get(ctx context.Context, id int) (*Blocklist, error) {
|
||||
return c.Query().Where(blocklist.ID(id)).Only(ctx)
|
||||
}
|
||||
|
||||
// GetX is like Get, but panics if an error occurs.
|
||||
func (c *BlocklistClient) GetX(ctx context.Context, id int) *Blocklist {
|
||||
obj, err := c.Get(ctx, id)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return obj
|
||||
}
|
||||
|
||||
// Hooks returns the client hooks.
|
||||
func (c *BlocklistClient) Hooks() []Hook {
|
||||
return c.hooks.Blocklist
|
||||
}
|
||||
|
||||
// Interceptors returns the client interceptors.
|
||||
func (c *BlocklistClient) Interceptors() []Interceptor {
|
||||
return c.inters.Blocklist
|
||||
}
|
||||
|
||||
func (c *BlocklistClient) mutate(ctx context.Context, m *BlocklistMutation) (Value, error) {
|
||||
switch m.Op() {
|
||||
case OpCreate:
|
||||
return (&BlocklistCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdate:
|
||||
return (&BlocklistUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpUpdateOne:
|
||||
return (&BlocklistUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
|
||||
case OpDelete, OpDeleteOne:
|
||||
return (&BlocklistDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("ent: unknown Blocklist mutation op: %q", m.Op())
|
||||
}
|
||||
}
|
||||
|
||||
// DownloadClientsClient is a client for the DownloadClients schema.
|
||||
type DownloadClientsClient struct {
|
||||
config
|
||||
@@ -1504,11 +1645,11 @@ func (c *StorageClient) mutate(ctx context.Context, m *StorageMutation) (Value,
|
||||
// hooks and interceptors per client, for fast access.
|
||||
type (
|
||||
hooks struct {
|
||||
DownloadClients, Episode, History, ImportList, Indexers, Media,
|
||||
Blocklist, DownloadClients, Episode, History, ImportList, Indexers, Media,
|
||||
NotificationClient, Settings, Storage []ent.Hook
|
||||
}
|
||||
inters struct {
|
||||
DownloadClients, Episode, History, ImportList, Indexers, Media,
|
||||
Blocklist, DownloadClients, Episode, History, ImportList, Indexers, Media,
|
||||
NotificationClient, Settings, Storage []ent.Interceptor
|
||||
}
|
||||
)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"polaris/ent/blocklist"
|
||||
"polaris/ent/downloadclients"
|
||||
"polaris/ent/episode"
|
||||
"polaris/ent/history"
|
||||
@@ -81,6 +82,7 @@ var (
|
||||
func checkColumn(table, column string) error {
|
||||
initCheck.Do(func() {
|
||||
columnCheck = sql.NewColumnCheck(map[string]func(string) bool{
|
||||
blocklist.Table: blocklist.ValidColumn,
|
||||
downloadclients.Table: downloadclients.ValidColumn,
|
||||
episode.Table: episode.ValidColumn,
|
||||
history.Table: history.ValidColumn,
|
||||
|
||||
@@ -8,6 +8,18 @@ import (
|
||||
"polaris/ent"
|
||||
)
|
||||
|
||||
// The BlocklistFunc type is an adapter to allow the use of ordinary
|
||||
// function as Blocklist mutator.
|
||||
type BlocklistFunc func(context.Context, *ent.BlocklistMutation) (ent.Value, error)
|
||||
|
||||
// Mutate calls f(ctx, m).
|
||||
func (f BlocklistFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
|
||||
if mv, ok := m.(*ent.BlocklistMutation); ok {
|
||||
return f(ctx, mv)
|
||||
}
|
||||
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.BlocklistMutation", m)
|
||||
}
|
||||
|
||||
// The DownloadClientsFunc type is an adapter to allow the use of ordinary
|
||||
// function as DownloadClients mutator.
|
||||
type DownloadClientsFunc func(context.Context, *ent.DownloadClientsMutation) (ent.Value, error)
|
||||
|
||||
@@ -8,6 +8,18 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
// BlocklistsColumns holds the columns for the "blocklists" table.
|
||||
BlocklistsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
{Name: "type", Type: field.TypeEnum, Enums: []string{"media", "torrent"}},
|
||||
{Name: "value", Type: field.TypeString},
|
||||
}
|
||||
// BlocklistsTable holds the schema information for the "blocklists" table.
|
||||
BlocklistsTable = &schema.Table{
|
||||
Name: "blocklists",
|
||||
Columns: BlocklistsColumns,
|
||||
PrimaryKey: []*schema.Column{BlocklistsColumns[0]},
|
||||
}
|
||||
// DownloadClientsColumns holds the columns for the "download_clients" table.
|
||||
DownloadClientsColumns = []*schema.Column{
|
||||
{Name: "id", Type: field.TypeInt, Increment: true},
|
||||
@@ -179,6 +191,7 @@ var (
|
||||
}
|
||||
// Tables holds all the tables in the schema.
|
||||
Tables = []*schema.Table{
|
||||
BlocklistsTable,
|
||||
DownloadClientsTable,
|
||||
EpisodesTable,
|
||||
HistoriesTable,
|
||||
|
||||
382
ent/mutation.go
382
ent/mutation.go
@@ -6,6 +6,7 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"polaris/ent/blocklist"
|
||||
"polaris/ent/downloadclients"
|
||||
"polaris/ent/episode"
|
||||
"polaris/ent/history"
|
||||
@@ -33,6 +34,7 @@ const (
|
||||
OpUpdateOne = ent.OpUpdateOne
|
||||
|
||||
// Node types.
|
||||
TypeBlocklist = "Blocklist"
|
||||
TypeDownloadClients = "DownloadClients"
|
||||
TypeEpisode = "Episode"
|
||||
TypeHistory = "History"
|
||||
@@ -44,6 +46,386 @@ const (
|
||||
TypeStorage = "Storage"
|
||||
)
|
||||
|
||||
// BlocklistMutation represents an operation that mutates the Blocklist nodes in the graph.
|
||||
type BlocklistMutation struct {
|
||||
config
|
||||
op Op
|
||||
typ string
|
||||
id *int
|
||||
_type *blocklist.Type
|
||||
value *string
|
||||
clearedFields map[string]struct{}
|
||||
done bool
|
||||
oldValue func(context.Context) (*Blocklist, error)
|
||||
predicates []predicate.Blocklist
|
||||
}
|
||||
|
||||
var _ ent.Mutation = (*BlocklistMutation)(nil)
|
||||
|
||||
// blocklistOption allows management of the mutation configuration using functional options.
|
||||
type blocklistOption func(*BlocklistMutation)
|
||||
|
||||
// newBlocklistMutation creates new mutation for the Blocklist entity.
|
||||
func newBlocklistMutation(c config, op Op, opts ...blocklistOption) *BlocklistMutation {
|
||||
m := &BlocklistMutation{
|
||||
config: c,
|
||||
op: op,
|
||||
typ: TypeBlocklist,
|
||||
clearedFields: make(map[string]struct{}),
|
||||
}
|
||||
for _, opt := range opts {
|
||||
opt(m)
|
||||
}
|
||||
return m
|
||||
}
|
||||
|
||||
// withBlocklistID sets the ID field of the mutation.
|
||||
func withBlocklistID(id int) blocklistOption {
|
||||
return func(m *BlocklistMutation) {
|
||||
var (
|
||||
err error
|
||||
once sync.Once
|
||||
value *Blocklist
|
||||
)
|
||||
m.oldValue = func(ctx context.Context) (*Blocklist, error) {
|
||||
once.Do(func() {
|
||||
if m.done {
|
||||
err = errors.New("querying old values post mutation is not allowed")
|
||||
} else {
|
||||
value, err = m.Client().Blocklist.Get(ctx, id)
|
||||
}
|
||||
})
|
||||
return value, err
|
||||
}
|
||||
m.id = &id
|
||||
}
|
||||
}
|
||||
|
||||
// withBlocklist sets the old Blocklist of the mutation.
|
||||
func withBlocklist(node *Blocklist) blocklistOption {
|
||||
return func(m *BlocklistMutation) {
|
||||
m.oldValue = func(context.Context) (*Blocklist, error) {
|
||||
return node, nil
|
||||
}
|
||||
m.id = &node.ID
|
||||
}
|
||||
}
|
||||
|
||||
// Client returns a new `ent.Client` from the mutation. If the mutation was
|
||||
// executed in a transaction (ent.Tx), a transactional client is returned.
|
||||
func (m BlocklistMutation) Client() *Client {
|
||||
client := &Client{config: m.config}
|
||||
client.init()
|
||||
return client
|
||||
}
|
||||
|
||||
// Tx returns an `ent.Tx` for mutations that were executed in transactions;
|
||||
// it returns an error otherwise.
|
||||
func (m BlocklistMutation) Tx() (*Tx, error) {
|
||||
if _, ok := m.driver.(*txDriver); !ok {
|
||||
return nil, errors.New("ent: mutation is not running in a transaction")
|
||||
}
|
||||
tx := &Tx{config: m.config}
|
||||
tx.init()
|
||||
return tx, nil
|
||||
}
|
||||
|
||||
// ID returns the ID value in the mutation. Note that the ID is only available
|
||||
// if it was provided to the builder or after it was returned from the database.
|
||||
func (m *BlocklistMutation) ID() (id int, exists bool) {
|
||||
if m.id == nil {
|
||||
return
|
||||
}
|
||||
return *m.id, true
|
||||
}
|
||||
|
||||
// IDs queries the database and returns the entity ids that match the mutation's predicate.
|
||||
// That means, if the mutation is applied within a transaction with an isolation level such
|
||||
// as sql.LevelSerializable, the returned ids match the ids of the rows that will be updated
|
||||
// or updated by the mutation.
|
||||
func (m *BlocklistMutation) IDs(ctx context.Context) ([]int, error) {
|
||||
switch {
|
||||
case m.op.Is(OpUpdateOne | OpDeleteOne):
|
||||
id, exists := m.ID()
|
||||
if exists {
|
||||
return []int{id}, nil
|
||||
}
|
||||
fallthrough
|
||||
case m.op.Is(OpUpdate | OpDelete):
|
||||
return m.Client().Blocklist.Query().Where(m.predicates...).IDs(ctx)
|
||||
default:
|
||||
return nil, fmt.Errorf("IDs is not allowed on %s operations", m.op)
|
||||
}
|
||||
}
|
||||
|
||||
// SetType sets the "type" field.
|
||||
func (m *BlocklistMutation) SetType(b blocklist.Type) {
|
||||
m._type = &b
|
||||
}
|
||||
|
||||
// GetType returns the value of the "type" field in the mutation.
|
||||
func (m *BlocklistMutation) GetType() (r blocklist.Type, exists bool) {
|
||||
v := m._type
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldType returns the old "type" field's value of the Blocklist entity.
|
||||
// If the Blocklist object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *BlocklistMutation) OldType(ctx context.Context) (v blocklist.Type, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldType is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldType requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldType: %w", err)
|
||||
}
|
||||
return oldValue.Type, nil
|
||||
}
|
||||
|
||||
// ResetType resets all changes to the "type" field.
|
||||
func (m *BlocklistMutation) ResetType() {
|
||||
m._type = nil
|
||||
}
|
||||
|
||||
// SetValue sets the "value" field.
|
||||
func (m *BlocklistMutation) SetValue(s string) {
|
||||
m.value = &s
|
||||
}
|
||||
|
||||
// Value returns the value of the "value" field in the mutation.
|
||||
func (m *BlocklistMutation) Value() (r string, exists bool) {
|
||||
v := m.value
|
||||
if v == nil {
|
||||
return
|
||||
}
|
||||
return *v, true
|
||||
}
|
||||
|
||||
// OldValue returns the old "value" field's value of the Blocklist entity.
|
||||
// If the Blocklist object wasn't provided to the builder, the object is fetched from the database.
|
||||
// An error is returned if the mutation operation is not UpdateOne, or the database query fails.
|
||||
func (m *BlocklistMutation) OldValue(ctx context.Context) (v string, err error) {
|
||||
if !m.op.Is(OpUpdateOne) {
|
||||
return v, errors.New("OldValue is only allowed on UpdateOne operations")
|
||||
}
|
||||
if m.id == nil || m.oldValue == nil {
|
||||
return v, errors.New("OldValue requires an ID field in the mutation")
|
||||
}
|
||||
oldValue, err := m.oldValue(ctx)
|
||||
if err != nil {
|
||||
return v, fmt.Errorf("querying old value for OldValue: %w", err)
|
||||
}
|
||||
return oldValue.Value, nil
|
||||
}
|
||||
|
||||
// ResetValue resets all changes to the "value" field.
|
||||
func (m *BlocklistMutation) ResetValue() {
|
||||
m.value = nil
|
||||
}
|
||||
|
||||
// Where appends a list predicates to the BlocklistMutation builder.
|
||||
func (m *BlocklistMutation) Where(ps ...predicate.Blocklist) {
|
||||
m.predicates = append(m.predicates, ps...)
|
||||
}
|
||||
|
||||
// WhereP appends storage-level predicates to the BlocklistMutation builder. Using this method,
|
||||
// users can use type-assertion to append predicates that do not depend on any generated package.
|
||||
func (m *BlocklistMutation) WhereP(ps ...func(*sql.Selector)) {
|
||||
p := make([]predicate.Blocklist, len(ps))
|
||||
for i := range ps {
|
||||
p[i] = ps[i]
|
||||
}
|
||||
m.Where(p...)
|
||||
}
|
||||
|
||||
// Op returns the operation name.
|
||||
func (m *BlocklistMutation) Op() Op {
|
||||
return m.op
|
||||
}
|
||||
|
||||
// SetOp allows setting the mutation operation.
|
||||
func (m *BlocklistMutation) SetOp(op Op) {
|
||||
m.op = op
|
||||
}
|
||||
|
||||
// Type returns the node type of this mutation (Blocklist).
|
||||
func (m *BlocklistMutation) Type() string {
|
||||
return m.typ
|
||||
}
|
||||
|
||||
// Fields returns all fields that were changed during this mutation. Note that in
|
||||
// order to get all numeric fields that were incremented/decremented, call
|
||||
// AddedFields().
|
||||
func (m *BlocklistMutation) Fields() []string {
|
||||
fields := make([]string, 0, 2)
|
||||
if m._type != nil {
|
||||
fields = append(fields, blocklist.FieldType)
|
||||
}
|
||||
if m.value != nil {
|
||||
fields = append(fields, blocklist.FieldValue)
|
||||
}
|
||||
return fields
|
||||
}
|
||||
|
||||
// Field returns the value of a field with the given name. The second boolean
|
||||
// return value indicates that this field was not set, or was not defined in the
|
||||
// schema.
|
||||
func (m *BlocklistMutation) Field(name string) (ent.Value, bool) {
|
||||
switch name {
|
||||
case blocklist.FieldType:
|
||||
return m.GetType()
|
||||
case blocklist.FieldValue:
|
||||
return m.Value()
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// OldField returns the old value of the field from the database. An error is
|
||||
// returned if the mutation operation is not UpdateOne, or the query to the
|
||||
// database failed.
|
||||
func (m *BlocklistMutation) OldField(ctx context.Context, name string) (ent.Value, error) {
|
||||
switch name {
|
||||
case blocklist.FieldType:
|
||||
return m.OldType(ctx)
|
||||
case blocklist.FieldValue:
|
||||
return m.OldValue(ctx)
|
||||
}
|
||||
return nil, fmt.Errorf("unknown Blocklist field %s", name)
|
||||
}
|
||||
|
||||
// SetField sets the value of a field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *BlocklistMutation) SetField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
case blocklist.FieldType:
|
||||
v, ok := value.(blocklist.Type)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetType(v)
|
||||
return nil
|
||||
case blocklist.FieldValue:
|
||||
v, ok := value.(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("unexpected type %T for field %s", value, name)
|
||||
}
|
||||
m.SetValue(v)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Blocklist field %s", name)
|
||||
}
|
||||
|
||||
// AddedFields returns all numeric fields that were incremented/decremented during
|
||||
// this mutation.
|
||||
func (m *BlocklistMutation) AddedFields() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AddedField returns the numeric value that was incremented/decremented on a field
|
||||
// with the given name. The second boolean return value indicates that this field
|
||||
// was not set, or was not defined in the schema.
|
||||
func (m *BlocklistMutation) AddedField(name string) (ent.Value, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// AddField adds the value to the field with the given name. It returns an error if
|
||||
// the field is not defined in the schema, or if the type mismatched the field
|
||||
// type.
|
||||
func (m *BlocklistMutation) AddField(name string, value ent.Value) error {
|
||||
switch name {
|
||||
}
|
||||
return fmt.Errorf("unknown Blocklist numeric field %s", name)
|
||||
}
|
||||
|
||||
// ClearedFields returns all nullable fields that were cleared during this
|
||||
// mutation.
|
||||
func (m *BlocklistMutation) ClearedFields() []string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// FieldCleared returns a boolean indicating if a field with the given name was
|
||||
// cleared in this mutation.
|
||||
func (m *BlocklistMutation) FieldCleared(name string) bool {
|
||||
_, ok := m.clearedFields[name]
|
||||
return ok
|
||||
}
|
||||
|
||||
// ClearField clears the value of the field with the given name. It returns an
|
||||
// error if the field is not defined in the schema.
|
||||
func (m *BlocklistMutation) ClearField(name string) error {
|
||||
return fmt.Errorf("unknown Blocklist nullable field %s", name)
|
||||
}
|
||||
|
||||
// ResetField resets all changes in the mutation for the field with the given name.
|
||||
// It returns an error if the field is not defined in the schema.
|
||||
func (m *BlocklistMutation) ResetField(name string) error {
|
||||
switch name {
|
||||
case blocklist.FieldType:
|
||||
m.ResetType()
|
||||
return nil
|
||||
case blocklist.FieldValue:
|
||||
m.ResetValue()
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unknown Blocklist field %s", name)
|
||||
}
|
||||
|
||||
// AddedEdges returns all edge names that were set/added in this mutation.
|
||||
func (m *BlocklistMutation) AddedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// AddedIDs returns all IDs (to other nodes) that were added for the given edge
|
||||
// name in this mutation.
|
||||
func (m *BlocklistMutation) AddedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RemovedEdges returns all edge names that were removed in this mutation.
|
||||
func (m *BlocklistMutation) RemovedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// RemovedIDs returns all IDs (to other nodes) that were removed for the edge with
|
||||
// the given name in this mutation.
|
||||
func (m *BlocklistMutation) RemovedIDs(name string) []ent.Value {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ClearedEdges returns all edge names that were cleared in this mutation.
|
||||
func (m *BlocklistMutation) ClearedEdges() []string {
|
||||
edges := make([]string, 0, 0)
|
||||
return edges
|
||||
}
|
||||
|
||||
// EdgeCleared returns a boolean which indicates if the edge with the given name
|
||||
// was cleared in this mutation.
|
||||
func (m *BlocklistMutation) EdgeCleared(name string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// ClearEdge clears the value of the edge with the given name. It returns an error
|
||||
// if that edge is not defined in the schema.
|
||||
func (m *BlocklistMutation) ClearEdge(name string) error {
|
||||
return fmt.Errorf("unknown Blocklist unique edge %s", name)
|
||||
}
|
||||
|
||||
// ResetEdge resets all changes to the edge with the given name in this mutation.
|
||||
// It returns an error if the edge is not defined in the schema.
|
||||
func (m *BlocklistMutation) ResetEdge(name string) error {
|
||||
return fmt.Errorf("unknown Blocklist edge %s", name)
|
||||
}
|
||||
|
||||
// DownloadClientsMutation represents an operation that mutates the DownloadClients nodes in the graph.
|
||||
type DownloadClientsMutation struct {
|
||||
config
|
||||
|
||||
@@ -6,6 +6,9 @@ import (
|
||||
"entgo.io/ent/dialect/sql"
|
||||
)
|
||||
|
||||
// Blocklist is the predicate function for blocklist builders.
|
||||
type Blocklist func(*sql.Selector)
|
||||
|
||||
// DownloadClients is the predicate function for downloadclients builders.
|
||||
type DownloadClients func(*sql.Selector)
|
||||
|
||||
|
||||
24
ent/schema/blocklist.go
Normal file
24
ent/schema/blocklist.go
Normal file
@@ -0,0 +1,24 @@
|
||||
package schema
|
||||
|
||||
import (
|
||||
"entgo.io/ent"
|
||||
"entgo.io/ent/schema/field"
|
||||
)
|
||||
|
||||
// Blocklist holds the schema definition for the Blocklist entity.
|
||||
type Blocklist struct {
|
||||
ent.Schema
|
||||
}
|
||||
|
||||
// Fields of the Blocklist.
|
||||
func (Blocklist) Fields() []ent.Field {
|
||||
return []ent.Field{
|
||||
field.Enum("type").Values("media", "torrent"),
|
||||
field.String("value"),
|
||||
}
|
||||
}
|
||||
|
||||
// Edges of the Blocklist.
|
||||
func (Blocklist) Edges() []ent.Edge {
|
||||
return nil
|
||||
}
|
||||
@@ -12,6 +12,8 @@ import (
|
||||
// Tx is a transactional client that is created by calling Client.Tx().
|
||||
type Tx struct {
|
||||
config
|
||||
// Blocklist is the client for interacting with the Blocklist builders.
|
||||
Blocklist *BlocklistClient
|
||||
// DownloadClients is the client for interacting with the DownloadClients builders.
|
||||
DownloadClients *DownloadClientsClient
|
||||
// Episode is the client for interacting with the Episode builders.
|
||||
@@ -161,6 +163,7 @@ func (tx *Tx) Client() *Client {
|
||||
}
|
||||
|
||||
func (tx *Tx) init() {
|
||||
tx.Blocklist = NewBlocklistClient(tx.config)
|
||||
tx.DownloadClients = NewDownloadClientsClient(tx.config)
|
||||
tx.Episode = NewEpisodeClient(tx.config)
|
||||
tx.History = NewHistoryClient(tx.config)
|
||||
@@ -179,7 +182,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: DownloadClients.QueryXXX(), the query will be executed
|
||||
// applies a query, for example: Blocklist.QueryXXX(), the query will be executed
|
||||
// through the driver which created this transaction.
|
||||
//
|
||||
// Note that txDriver is not goroutine safe.
|
||||
|
||||
17
go.mod
17
go.mod
@@ -5,30 +5,35 @@ go 1.22.4
|
||||
require (
|
||||
entgo.io/ent v0.13.1
|
||||
github.com/golang-jwt/jwt/v5 v5.2.1
|
||||
github.com/mattn/go-sqlite3 v1.14.16
|
||||
github.com/mattn/go-sqlite3 v1.14.22 // indirect
|
||||
github.com/robfig/cron v1.2.0
|
||||
go.uber.org/zap v1.27.0
|
||||
golang.org/x/net v0.27.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/PuerkitoBio/goquery v1.9.2
|
||||
github.com/gin-contrib/zap v1.1.3
|
||||
github.com/ncruces/go-sqlite3 v0.18.4
|
||||
github.com/nikoksr/notify v1.0.0
|
||||
github.com/stretchr/testify v1.9.0
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/BurntSushi/toml v1.4.0 // indirect
|
||||
github.com/PuerkitoBio/goquery v1.9.2 // indirect
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.2 // indirect
|
||||
github.com/andybalholm/cascadia v1.3.2 // indirect
|
||||
github.com/blinkbean/dingtalk v1.1.3 // indirect
|
||||
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible // indirect
|
||||
github.com/go-test/deep v1.0.4 // indirect
|
||||
github.com/gregdel/pushover v1.3.1 // indirect
|
||||
github.com/ncruces/julianday v1.0.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||
github.com/stretchr/objx v0.5.2 // indirect
|
||||
github.com/technoweenie/multipartstreamer v1.0.1 // indirect
|
||||
golang.org/x/sync v0.7.0 // indirect
|
||||
github.com/tetratelabs/wazero v1.8.0 // indirect
|
||||
golang.org/x/sync v0.8.0 // indirect
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
)
|
||||
@@ -75,11 +80,11 @@ require (
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
github.com/zclconf/go-cty v1.8.0 // indirect
|
||||
golang.org/x/arch v0.8.0 // indirect
|
||||
golang.org/x/crypto v0.25.0
|
||||
golang.org/x/crypto v0.27.0
|
||||
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
|
||||
golang.org/x/mod v0.19.0 // indirect
|
||||
golang.org/x/sys v0.22.0
|
||||
golang.org/x/text v0.16.0 // indirect
|
||||
golang.org/x/sys v0.25.0
|
||||
golang.org/x/text v0.18.0 // indirect
|
||||
google.golang.org/protobuf v1.34.2 // indirect
|
||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
|
||||
43
go.sum
43
go.sum
@@ -4,8 +4,8 @@ entgo.io/ent v0.13.1 h1:uD8QwN1h6SNphdCCzmkMN3feSUzNnVvV/WIkHKMbzOE=
|
||||
entgo.io/ent v0.13.1/go.mod h1:qCEmo+biw3ccBn9OyL4ZK5dfpwg++l1Gxwac5B1206A=
|
||||
github.com/BurntSushi/toml v1.4.0 h1:kuoIxZQy2WRRk1pttg9asf+WVv6tWQuBNVmK8+nqPr0=
|
||||
github.com/BurntSushi/toml v1.4.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.2 h1:OcvFkGmslmlZibjAjaHm3L//6LiuBgolP7OputlJIzU=
|
||||
github.com/DATA-DOG/go-sqlmock v1.5.2/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
|
||||
github.com/PuerkitoBio/goquery v1.9.2 h1:4/wZksC3KgkQw7SQgkKotmKljk0M6V8TUvA8Wb4yPeE=
|
||||
github.com/PuerkitoBio/goquery v1.9.2/go.mod h1:GHPCaP0ODyyxqcNoFGYlAprUFH81NuRPd0GX3Zu2Mvk=
|
||||
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
|
||||
@@ -56,8 +56,8 @@ github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBEx
|
||||
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
||||
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible h1:2cauKuaELYAEARXRkq2LrJ0yDDv1rW7+wrTEdVL3uaU=
|
||||
github.com/go-telegram-bot-api/telegram-bot-api v4.6.4+incompatible/go.mod h1:qf9acutJ8cwBUhm1bqgz6Bei9/C/c93FPDljKWwsOgM=
|
||||
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
|
||||
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
|
||||
github.com/go-test/deep v1.0.4 h1:u2CU3YKy9I2pmu9pX0eq50wCgjfGIt539SqR7FbHiho=
|
||||
github.com/go-test/deep v1.0.4/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
|
||||
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
||||
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk=
|
||||
@@ -86,6 +86,7 @@ github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible
|
||||
github.com/jordan-wright/email v4.0.1-0.20210109023952-943e75fe5223+incompatible/go.mod h1:1c7szIrayyPPB/987hsnvNzLushdWf4o/79s3P08L8A=
|
||||
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/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM=
|
||||
github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws=
|
||||
@@ -105,10 +106,8 @@ github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0V
|
||||
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
|
||||
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
|
||||
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
|
||||
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
||||
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
|
||||
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo=
|
||||
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
|
||||
@@ -120,10 +119,12 @@ 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/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM=
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk=
|
||||
github.com/ncruces/go-sqlite3 v0.18.4 h1:Je8o3y33MDwPYY/Cacas8yCsuoUzpNY/AgoSlN2ekyE=
|
||||
github.com/ncruces/go-sqlite3 v0.18.4/go.mod h1:4HLag13gq1k10s4dfGBhMfRVsssJRT9/5hYqVM9RUYo=
|
||||
github.com/ncruces/julianday v1.0.0 h1:fH0OKwa7NWvniGQtxdJRxAgkBMolni2BjDHaWTxqt7M=
|
||||
github.com/ncruces/julianday v1.0.0/go.mod h1:Dusn2KvZrrovOMJuOt0TNXL6tB7U2E8kvza5fFc9G7g=
|
||||
github.com/nikoksr/notify v1.0.0 h1:qe9/6FRsWdxBgQgWcpvQ0sv8LRGJZDpRB4TkL2uNdO8=
|
||||
github.com/nikoksr/notify v1.0.0/go.mod h1:hPaaDt30d6LAA7/5nb0e48Bp/MctDfycCSs8VEgN29I=
|
||||
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/pelletier/go-toml/v2 v2.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM=
|
||||
github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
@@ -147,8 +148,6 @@ github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
|
||||
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
|
||||
github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
|
||||
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
|
||||
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/spf13/viper v1.19.0 h1:RWq5SEjt8o25SROyN3z2OrDB9l7RPd3lwTWU8EcEdcI=
|
||||
@@ -170,6 +169,8 @@ github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8
|
||||
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
|
||||
github.com/technoweenie/multipartstreamer v1.0.1 h1:XRztA5MXiR1TIRHxH2uNxXxaIkKQDeX7m2XsSOlQEnM=
|
||||
github.com/technoweenie/multipartstreamer v1.0.1/go.mod h1:jNVxdtShOxzAsukZwTSw6MDx5eUJoiEBsSvzDU9uzog=
|
||||
github.com/tetratelabs/wazero v1.8.0 h1:iEKu0d4c2Pd+QSRieYbnQC9yiFlMS9D+Jr0LsRmcF4g=
|
||||
github.com/tetratelabs/wazero v1.8.0/go.mod h1:yAI0XTsMBhREkM/YDAK/zNou3GoiAce1P6+rp/wQhjs=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI=
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
|
||||
@@ -190,8 +191,8 @@ golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
|
||||
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
|
||||
golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
|
||||
golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A=
|
||||
golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70=
|
||||
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
|
||||
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
@@ -210,8 +211,8 @@ golang.org/x/net v0.27.0/go.mod h1:dDi0PyhWNoiUOrAS8uXv/vnScO4wnHQO4mj9fn/RytE=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
|
||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
|
||||
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
@@ -220,8 +221,8 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
|
||||
golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
|
||||
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
@@ -233,14 +234,12 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
||||
golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4=
|
||||
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
|
||||
golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224=
|
||||
golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/tools v0.23.0 h1:SGsXPZ+2l4JsgaCKkx+FQ9YZ5XEtA1GZYuoDjenLjvg=
|
||||
golang.org/x/tools v0.23.0/go.mod h1:pnu6ufv6vQkll6szChhK3C3L/ruaIv5eBeztNG8wtsI=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/appengine v1.6.5/go.mod h1:8WjMMxjGQR8xUklV/ARdw2HLXBOI7O7uCIDZVag1xfc=
|
||||
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
|
||||
|
||||
25
pkg/utils/linux.go
Normal file
25
pkg/utils/linux.go
Normal file
@@ -0,0 +1,25 @@
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"golang.org/x/sys/unix"
|
||||
"math"
|
||||
"runtime"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func AvailableSpace(dir string) uint64 {
|
||||
if runtime.GOOS != "linux" {
|
||||
return math.MaxUint64
|
||||
}
|
||||
var stat unix.Statfs_t
|
||||
|
||||
unix.Statfs(dir, &stat)
|
||||
return stat.Bavail * uint64(stat.Bsize)
|
||||
}
|
||||
|
||||
func MaxPermission() {
|
||||
syscall.Umask(0) //max permission 0777
|
||||
}
|
||||
16
pkg/utils/other.go
Normal file
16
pkg/utils/other.go
Normal file
@@ -0,0 +1,16 @@
|
||||
//go:build !linux
|
||||
// +build !linux
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"math"
|
||||
)
|
||||
|
||||
func AvailableSpace(dir string) uint64 {
|
||||
return math.MaxUint64
|
||||
}
|
||||
|
||||
func MaxPermission() {
|
||||
return
|
||||
}
|
||||
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"golang.org/x/exp/rand"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func IsASCII(s string) bool {
|
||||
@@ -131,13 +130,6 @@ func SeasonId(seasonName string) (int, error) {
|
||||
return num, nil
|
||||
}
|
||||
|
||||
func AvailableSpace(dir string) uint64 {
|
||||
var stat unix.Statfs_t
|
||||
|
||||
unix.Statfs(dir, &stat)
|
||||
return stat.Bavail * uint64(stat.Bsize)
|
||||
}
|
||||
|
||||
func ChangeFileHash(name string) error {
|
||||
f, err := os.OpenFile(name, os.O_APPEND|os.O_WRONLY, 0655)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user