feat: add goreleaser

This commit is contained in:
Simon Ding
2024-09-29 14:27:01 +08:00
parent ce25c090f5
commit 5d726dbcf1
25 changed files with 2192 additions and 48 deletions

View File

@@ -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