Files
kannn 2cd3052da1
golangci-lint / lint (push) Failing after 1m5s
rebrand: frp -> kanhole (kanhole server, kanholec client)
2026-05-29 09:05:34 +00:00

613 lines
17 KiB
Go

// Code generated by ent, DO NOT EDIT.
package ent
import (
"context"
"errors"
"fmt"
"time"
"entgo.io/ent/dialect/sql"
"entgo.io/ent/dialect/sql/sqlgraph"
"entgo.io/ent/schema/field"
"kanhole/pkg/db/ent/predicate"
"kanhole/pkg/db/ent/proxy"
)
// ProxyUpdate is the builder for updating Proxy entities.
type ProxyUpdate struct {
config
hooks []Hook
mutation *ProxyMutation
}
// Where appends a list predicates to the ProxyUpdate builder.
func (_u *ProxyUpdate) Where(ps ...predicate.Proxy) *ProxyUpdate {
_u.mutation.Where(ps...)
return _u
}
// SetName sets the "name" field.
func (_u *ProxyUpdate) SetName(v string) *ProxyUpdate {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableName(v *string) *ProxyUpdate {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetProxyType sets the "proxy_type" field.
func (_u *ProxyUpdate) SetProxyType(v string) *ProxyUpdate {
_u.mutation.SetProxyType(v)
return _u
}
// SetNillableProxyType sets the "proxy_type" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableProxyType(v *string) *ProxyUpdate {
if v != nil {
_u.SetProxyType(*v)
}
return _u
}
// SetLocalIP sets the "local_ip" field.
func (_u *ProxyUpdate) SetLocalIP(v string) *ProxyUpdate {
_u.mutation.SetLocalIP(v)
return _u
}
// SetNillableLocalIP sets the "local_ip" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableLocalIP(v *string) *ProxyUpdate {
if v != nil {
_u.SetLocalIP(*v)
}
return _u
}
// SetLocalPort sets the "local_port" field.
func (_u *ProxyUpdate) SetLocalPort(v int) *ProxyUpdate {
_u.mutation.ResetLocalPort()
_u.mutation.SetLocalPort(v)
return _u
}
// SetNillableLocalPort sets the "local_port" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableLocalPort(v *int) *ProxyUpdate {
if v != nil {
_u.SetLocalPort(*v)
}
return _u
}
// AddLocalPort adds value to the "local_port" field.
func (_u *ProxyUpdate) AddLocalPort(v int) *ProxyUpdate {
_u.mutation.AddLocalPort(v)
return _u
}
// SetRemotePort sets the "remote_port" field.
func (_u *ProxyUpdate) SetRemotePort(v int) *ProxyUpdate {
_u.mutation.ResetRemotePort()
_u.mutation.SetRemotePort(v)
return _u
}
// SetNillableRemotePort sets the "remote_port" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableRemotePort(v *int) *ProxyUpdate {
if v != nil {
_u.SetRemotePort(*v)
}
return _u
}
// AddRemotePort adds value to the "remote_port" field.
func (_u *ProxyUpdate) AddRemotePort(v int) *ProxyUpdate {
_u.mutation.AddRemotePort(v)
return _u
}
// SetStatus sets the "status" field.
func (_u *ProxyUpdate) SetStatus(v string) *ProxyUpdate {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableStatus(v *string) *ProxyUpdate {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetCustomDomains sets the "custom_domains" field.
func (_u *ProxyUpdate) SetCustomDomains(v string) *ProxyUpdate {
_u.mutation.SetCustomDomains(v)
return _u
}
// SetNillableCustomDomains sets the "custom_domains" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableCustomDomains(v *string) *ProxyUpdate {
if v != nil {
_u.SetCustomDomains(*v)
}
return _u
}
// SetMetadata sets the "metadata" field.
func (_u *ProxyUpdate) SetMetadata(v string) *ProxyUpdate {
_u.mutation.SetMetadata(v)
return _u
}
// SetNillableMetadata sets the "metadata" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableMetadata(v *string) *ProxyUpdate {
if v != nil {
_u.SetMetadata(*v)
}
return _u
}
// SetClientID sets the "client_id" field.
func (_u *ProxyUpdate) SetClientID(v int) *ProxyUpdate {
_u.mutation.ResetClientID()
_u.mutation.SetClientID(v)
return _u
}
// SetNillableClientID sets the "client_id" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableClientID(v *int) *ProxyUpdate {
if v != nil {
_u.SetClientID(*v)
}
return _u
}
// AddClientID adds value to the "client_id" field.
func (_u *ProxyUpdate) AddClientID(v int) *ProxyUpdate {
_u.mutation.AddClientID(v)
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *ProxyUpdate) SetCreatedAt(v time.Time) *ProxyUpdate {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *ProxyUpdate) SetNillableCreatedAt(v *time.Time) *ProxyUpdate {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *ProxyUpdate) SetUpdatedAt(v time.Time) *ProxyUpdate {
_u.mutation.SetUpdatedAt(v)
return _u
}
// Mutation returns the ProxyMutation object of the builder.
func (_u *ProxyUpdate) Mutation() *ProxyMutation {
return _u.mutation
}
// Save executes the query and returns the number of nodes affected by the update operation.
func (_u *ProxyUpdate) Save(ctx context.Context) (int, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ProxyUpdate) SaveX(ctx context.Context) int {
affected, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return affected
}
// Exec executes the query.
func (_u *ProxyUpdate) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ProxyUpdate) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *ProxyUpdate) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := proxy.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
func (_u *ProxyUpdate) sqlSave(ctx context.Context) (_node int, err error) {
_spec := sqlgraph.NewUpdateSpec(proxy.Table, proxy.Columns, sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt))
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(proxy.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.ProxyType(); ok {
_spec.SetField(proxy.FieldProxyType, field.TypeString, value)
}
if value, ok := _u.mutation.LocalIP(); ok {
_spec.SetField(proxy.FieldLocalIP, field.TypeString, value)
}
if value, ok := _u.mutation.LocalPort(); ok {
_spec.SetField(proxy.FieldLocalPort, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedLocalPort(); ok {
_spec.AddField(proxy.FieldLocalPort, field.TypeInt, value)
}
if value, ok := _u.mutation.RemotePort(); ok {
_spec.SetField(proxy.FieldRemotePort, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedRemotePort(); ok {
_spec.AddField(proxy.FieldRemotePort, field.TypeInt, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(proxy.FieldStatus, field.TypeString, value)
}
if value, ok := _u.mutation.CustomDomains(); ok {
_spec.SetField(proxy.FieldCustomDomains, field.TypeString, value)
}
if value, ok := _u.mutation.Metadata(); ok {
_spec.SetField(proxy.FieldMetadata, field.TypeString, value)
}
if value, ok := _u.mutation.ClientID(); ok {
_spec.SetField(proxy.FieldClientID, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedClientID(); ok {
_spec.AddField(proxy.FieldClientID, field.TypeInt, value)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(proxy.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(proxy.FieldUpdatedAt, field.TypeTime, value)
}
if _node, err = sqlgraph.UpdateNodes(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{proxy.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return 0, err
}
_u.mutation.done = true
return _node, nil
}
// ProxyUpdateOne is the builder for updating a single Proxy entity.
type ProxyUpdateOne struct {
config
fields []string
hooks []Hook
mutation *ProxyMutation
}
// SetName sets the "name" field.
func (_u *ProxyUpdateOne) SetName(v string) *ProxyUpdateOne {
_u.mutation.SetName(v)
return _u
}
// SetNillableName sets the "name" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableName(v *string) *ProxyUpdateOne {
if v != nil {
_u.SetName(*v)
}
return _u
}
// SetProxyType sets the "proxy_type" field.
func (_u *ProxyUpdateOne) SetProxyType(v string) *ProxyUpdateOne {
_u.mutation.SetProxyType(v)
return _u
}
// SetNillableProxyType sets the "proxy_type" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableProxyType(v *string) *ProxyUpdateOne {
if v != nil {
_u.SetProxyType(*v)
}
return _u
}
// SetLocalIP sets the "local_ip" field.
func (_u *ProxyUpdateOne) SetLocalIP(v string) *ProxyUpdateOne {
_u.mutation.SetLocalIP(v)
return _u
}
// SetNillableLocalIP sets the "local_ip" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableLocalIP(v *string) *ProxyUpdateOne {
if v != nil {
_u.SetLocalIP(*v)
}
return _u
}
// SetLocalPort sets the "local_port" field.
func (_u *ProxyUpdateOne) SetLocalPort(v int) *ProxyUpdateOne {
_u.mutation.ResetLocalPort()
_u.mutation.SetLocalPort(v)
return _u
}
// SetNillableLocalPort sets the "local_port" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableLocalPort(v *int) *ProxyUpdateOne {
if v != nil {
_u.SetLocalPort(*v)
}
return _u
}
// AddLocalPort adds value to the "local_port" field.
func (_u *ProxyUpdateOne) AddLocalPort(v int) *ProxyUpdateOne {
_u.mutation.AddLocalPort(v)
return _u
}
// SetRemotePort sets the "remote_port" field.
func (_u *ProxyUpdateOne) SetRemotePort(v int) *ProxyUpdateOne {
_u.mutation.ResetRemotePort()
_u.mutation.SetRemotePort(v)
return _u
}
// SetNillableRemotePort sets the "remote_port" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableRemotePort(v *int) *ProxyUpdateOne {
if v != nil {
_u.SetRemotePort(*v)
}
return _u
}
// AddRemotePort adds value to the "remote_port" field.
func (_u *ProxyUpdateOne) AddRemotePort(v int) *ProxyUpdateOne {
_u.mutation.AddRemotePort(v)
return _u
}
// SetStatus sets the "status" field.
func (_u *ProxyUpdateOne) SetStatus(v string) *ProxyUpdateOne {
_u.mutation.SetStatus(v)
return _u
}
// SetNillableStatus sets the "status" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableStatus(v *string) *ProxyUpdateOne {
if v != nil {
_u.SetStatus(*v)
}
return _u
}
// SetCustomDomains sets the "custom_domains" field.
func (_u *ProxyUpdateOne) SetCustomDomains(v string) *ProxyUpdateOne {
_u.mutation.SetCustomDomains(v)
return _u
}
// SetNillableCustomDomains sets the "custom_domains" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableCustomDomains(v *string) *ProxyUpdateOne {
if v != nil {
_u.SetCustomDomains(*v)
}
return _u
}
// SetMetadata sets the "metadata" field.
func (_u *ProxyUpdateOne) SetMetadata(v string) *ProxyUpdateOne {
_u.mutation.SetMetadata(v)
return _u
}
// SetNillableMetadata sets the "metadata" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableMetadata(v *string) *ProxyUpdateOne {
if v != nil {
_u.SetMetadata(*v)
}
return _u
}
// SetClientID sets the "client_id" field.
func (_u *ProxyUpdateOne) SetClientID(v int) *ProxyUpdateOne {
_u.mutation.ResetClientID()
_u.mutation.SetClientID(v)
return _u
}
// SetNillableClientID sets the "client_id" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableClientID(v *int) *ProxyUpdateOne {
if v != nil {
_u.SetClientID(*v)
}
return _u
}
// AddClientID adds value to the "client_id" field.
func (_u *ProxyUpdateOne) AddClientID(v int) *ProxyUpdateOne {
_u.mutation.AddClientID(v)
return _u
}
// SetCreatedAt sets the "created_at" field.
func (_u *ProxyUpdateOne) SetCreatedAt(v time.Time) *ProxyUpdateOne {
_u.mutation.SetCreatedAt(v)
return _u
}
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
func (_u *ProxyUpdateOne) SetNillableCreatedAt(v *time.Time) *ProxyUpdateOne {
if v != nil {
_u.SetCreatedAt(*v)
}
return _u
}
// SetUpdatedAt sets the "updated_at" field.
func (_u *ProxyUpdateOne) SetUpdatedAt(v time.Time) *ProxyUpdateOne {
_u.mutation.SetUpdatedAt(v)
return _u
}
// Mutation returns the ProxyMutation object of the builder.
func (_u *ProxyUpdateOne) Mutation() *ProxyMutation {
return _u.mutation
}
// Where appends a list predicates to the ProxyUpdate builder.
func (_u *ProxyUpdateOne) Where(ps ...predicate.Proxy) *ProxyUpdateOne {
_u.mutation.Where(ps...)
return _u
}
// Select allows selecting one or more fields (columns) of the returned entity.
// The default is selecting all fields defined in the entity schema.
func (_u *ProxyUpdateOne) Select(field string, fields ...string) *ProxyUpdateOne {
_u.fields = append([]string{field}, fields...)
return _u
}
// Save executes the query and returns the updated Proxy entity.
func (_u *ProxyUpdateOne) Save(ctx context.Context) (*Proxy, error) {
_u.defaults()
return withHooks(ctx, _u.sqlSave, _u.mutation, _u.hooks)
}
// SaveX is like Save, but panics if an error occurs.
func (_u *ProxyUpdateOne) SaveX(ctx context.Context) *Proxy {
node, err := _u.Save(ctx)
if err != nil {
panic(err)
}
return node
}
// Exec executes the query on the entity.
func (_u *ProxyUpdateOne) Exec(ctx context.Context) error {
_, err := _u.Save(ctx)
return err
}
// ExecX is like Exec, but panics if an error occurs.
func (_u *ProxyUpdateOne) ExecX(ctx context.Context) {
if err := _u.Exec(ctx); err != nil {
panic(err)
}
}
// defaults sets the default values of the builder before save.
func (_u *ProxyUpdateOne) defaults() {
if _, ok := _u.mutation.UpdatedAt(); !ok {
v := proxy.UpdateDefaultUpdatedAt()
_u.mutation.SetUpdatedAt(v)
}
}
func (_u *ProxyUpdateOne) sqlSave(ctx context.Context) (_node *Proxy, err error) {
_spec := sqlgraph.NewUpdateSpec(proxy.Table, proxy.Columns, sqlgraph.NewFieldSpec(proxy.FieldID, field.TypeInt))
id, ok := _u.mutation.ID()
if !ok {
return nil, &ValidationError{Name: "id", err: errors.New(`ent: missing "Proxy.id" for update`)}
}
_spec.Node.ID.Value = id
if fields := _u.fields; len(fields) > 0 {
_spec.Node.Columns = make([]string, 0, len(fields))
_spec.Node.Columns = append(_spec.Node.Columns, proxy.FieldID)
for _, f := range fields {
if !proxy.ValidColumn(f) {
return nil, &ValidationError{Name: f, err: fmt.Errorf("ent: invalid field %q for query", f)}
}
if f != proxy.FieldID {
_spec.Node.Columns = append(_spec.Node.Columns, f)
}
}
}
if ps := _u.mutation.predicates; len(ps) > 0 {
_spec.Predicate = func(selector *sql.Selector) {
for i := range ps {
ps[i](selector)
}
}
}
if value, ok := _u.mutation.Name(); ok {
_spec.SetField(proxy.FieldName, field.TypeString, value)
}
if value, ok := _u.mutation.ProxyType(); ok {
_spec.SetField(proxy.FieldProxyType, field.TypeString, value)
}
if value, ok := _u.mutation.LocalIP(); ok {
_spec.SetField(proxy.FieldLocalIP, field.TypeString, value)
}
if value, ok := _u.mutation.LocalPort(); ok {
_spec.SetField(proxy.FieldLocalPort, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedLocalPort(); ok {
_spec.AddField(proxy.FieldLocalPort, field.TypeInt, value)
}
if value, ok := _u.mutation.RemotePort(); ok {
_spec.SetField(proxy.FieldRemotePort, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedRemotePort(); ok {
_spec.AddField(proxy.FieldRemotePort, field.TypeInt, value)
}
if value, ok := _u.mutation.Status(); ok {
_spec.SetField(proxy.FieldStatus, field.TypeString, value)
}
if value, ok := _u.mutation.CustomDomains(); ok {
_spec.SetField(proxy.FieldCustomDomains, field.TypeString, value)
}
if value, ok := _u.mutation.Metadata(); ok {
_spec.SetField(proxy.FieldMetadata, field.TypeString, value)
}
if value, ok := _u.mutation.ClientID(); ok {
_spec.SetField(proxy.FieldClientID, field.TypeInt, value)
}
if value, ok := _u.mutation.AddedClientID(); ok {
_spec.AddField(proxy.FieldClientID, field.TypeInt, value)
}
if value, ok := _u.mutation.CreatedAt(); ok {
_spec.SetField(proxy.FieldCreatedAt, field.TypeTime, value)
}
if value, ok := _u.mutation.UpdatedAt(); ok {
_spec.SetField(proxy.FieldUpdatedAt, field.TypeTime, value)
}
_node = &Proxy{config: _u.config}
_spec.Assign = _node.assignValues
_spec.ScanValues = _node.scanValues
if err = sqlgraph.UpdateNode(ctx, _u.driver, _spec); err != nil {
if _, ok := err.(*sqlgraph.NotFoundError); ok {
err = &NotFoundError{proxy.Label}
} else if sqlgraph.IsConstraintError(err) {
err = &ConstraintError{msg: err.Error(), wrap: err}
}
return nil, err
}
_u.mutation.done = true
return _node, nil
}