feat: ent ORM, admin UI, client auth, Fyne GUI, Windows/MSI packaging
This commit is contained in:
@@ -0,0 +1,387 @@
|
||||
// Code generated by ent, DO NOT EDIT.
|
||||
|
||||
package ent
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"entgo.io/ent/dialect/sql/sqlgraph"
|
||||
"entgo.io/ent/schema/field"
|
||||
"github.com/fatedier/frp/pkg/db/ent/frpcclient"
|
||||
)
|
||||
|
||||
// FrpcClientCreate is the builder for creating a FrpcClient entity.
|
||||
type FrpcClientCreate struct {
|
||||
config
|
||||
mutation *FrpcClientMutation
|
||||
hooks []Hook
|
||||
}
|
||||
|
||||
// SetName sets the "name" field.
|
||||
func (_c *FrpcClientCreate) SetName(v string) *FrpcClientCreate {
|
||||
_c.mutation.SetName(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetKey sets the "key" field.
|
||||
func (_c *FrpcClientCreate) SetKey(v string) *FrpcClientCreate {
|
||||
_c.mutation.SetKey(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableKey sets the "key" field if the given value is not nil.
|
||||
func (_c *FrpcClientCreate) SetNillableKey(v *string) *FrpcClientCreate {
|
||||
if v != nil {
|
||||
_c.SetKey(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetAddr sets the "addr" field.
|
||||
func (_c *FrpcClientCreate) SetAddr(v string) *FrpcClientCreate {
|
||||
_c.mutation.SetAddr(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableAddr sets the "addr" field if the given value is not nil.
|
||||
func (_c *FrpcClientCreate) SetNillableAddr(v *string) *FrpcClientCreate {
|
||||
if v != nil {
|
||||
_c.SetAddr(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetPort sets the "port" field.
|
||||
func (_c *FrpcClientCreate) SetPort(v int) *FrpcClientCreate {
|
||||
_c.mutation.SetPort(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillablePort sets the "port" field if the given value is not nil.
|
||||
func (_c *FrpcClientCreate) SetNillablePort(v *int) *FrpcClientCreate {
|
||||
if v != nil {
|
||||
_c.SetPort(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetStatus sets the "status" field.
|
||||
func (_c *FrpcClientCreate) SetStatus(v string) *FrpcClientCreate {
|
||||
_c.mutation.SetStatus(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableStatus sets the "status" field if the given value is not nil.
|
||||
func (_c *FrpcClientCreate) SetNillableStatus(v *string) *FrpcClientCreate {
|
||||
if v != nil {
|
||||
_c.SetStatus(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetMetadata sets the "metadata" field.
|
||||
func (_c *FrpcClientCreate) SetMetadata(v string) *FrpcClientCreate {
|
||||
_c.mutation.SetMetadata(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableMetadata sets the "metadata" field if the given value is not nil.
|
||||
func (_c *FrpcClientCreate) SetNillableMetadata(v *string) *FrpcClientCreate {
|
||||
if v != nil {
|
||||
_c.SetMetadata(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetCreatedAt sets the "created_at" field.
|
||||
func (_c *FrpcClientCreate) SetCreatedAt(v time.Time) *FrpcClientCreate {
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableCreatedAt sets the "created_at" field if the given value is not nil.
|
||||
func (_c *FrpcClientCreate) SetNillableCreatedAt(v *time.Time) *FrpcClientCreate {
|
||||
if v != nil {
|
||||
_c.SetCreatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetUpdatedAt sets the "updated_at" field.
|
||||
func (_c *FrpcClientCreate) SetUpdatedAt(v time.Time) *FrpcClientCreate {
|
||||
_c.mutation.SetUpdatedAt(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableUpdatedAt sets the "updated_at" field if the given value is not nil.
|
||||
func (_c *FrpcClientCreate) SetNillableUpdatedAt(v *time.Time) *FrpcClientCreate {
|
||||
if v != nil {
|
||||
_c.SetUpdatedAt(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetLastSeen sets the "last_seen" field.
|
||||
func (_c *FrpcClientCreate) SetLastSeen(v time.Time) *FrpcClientCreate {
|
||||
_c.mutation.SetLastSeen(v)
|
||||
return _c
|
||||
}
|
||||
|
||||
// SetNillableLastSeen sets the "last_seen" field if the given value is not nil.
|
||||
func (_c *FrpcClientCreate) SetNillableLastSeen(v *time.Time) *FrpcClientCreate {
|
||||
if v != nil {
|
||||
_c.SetLastSeen(*v)
|
||||
}
|
||||
return _c
|
||||
}
|
||||
|
||||
// Mutation returns the FrpcClientMutation object of the builder.
|
||||
func (_c *FrpcClientCreate) Mutation() *FrpcClientMutation {
|
||||
return _c.mutation
|
||||
}
|
||||
|
||||
// Save creates the FrpcClient in the database.
|
||||
func (_c *FrpcClientCreate) Save(ctx context.Context) (*FrpcClient, error) {
|
||||
_c.defaults()
|
||||
return withHooks(ctx, _c.sqlSave, _c.mutation, _c.hooks)
|
||||
}
|
||||
|
||||
// SaveX calls Save and panics if Save returns an error.
|
||||
func (_c *FrpcClientCreate) SaveX(ctx context.Context) *FrpcClient {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *FrpcClientCreate) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *FrpcClientCreate) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// defaults sets the default values of the builder before save.
|
||||
func (_c *FrpcClientCreate) defaults() {
|
||||
if _, ok := _c.mutation.Key(); !ok {
|
||||
v := frpcclient.DefaultKey
|
||||
_c.mutation.SetKey(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Addr(); !ok {
|
||||
v := frpcclient.DefaultAddr
|
||||
_c.mutation.SetAddr(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Port(); !ok {
|
||||
v := frpcclient.DefaultPort
|
||||
_c.mutation.SetPort(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Status(); !ok {
|
||||
v := frpcclient.DefaultStatus
|
||||
_c.mutation.SetStatus(v)
|
||||
}
|
||||
if _, ok := _c.mutation.Metadata(); !ok {
|
||||
v := frpcclient.DefaultMetadata
|
||||
_c.mutation.SetMetadata(v)
|
||||
}
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
v := frpcclient.DefaultCreatedAt()
|
||||
_c.mutation.SetCreatedAt(v)
|
||||
}
|
||||
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||
v := frpcclient.DefaultUpdatedAt()
|
||||
_c.mutation.SetUpdatedAt(v)
|
||||
}
|
||||
if _, ok := _c.mutation.LastSeen(); !ok {
|
||||
v := frpcclient.DefaultLastSeen()
|
||||
_c.mutation.SetLastSeen(v)
|
||||
}
|
||||
}
|
||||
|
||||
// check runs all checks and user-defined validators on the builder.
|
||||
func (_c *FrpcClientCreate) check() error {
|
||||
if _, ok := _c.mutation.Name(); !ok {
|
||||
return &ValidationError{Name: "name", err: errors.New(`ent: missing required field "FrpcClient.name"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Key(); !ok {
|
||||
return &ValidationError{Name: "key", err: errors.New(`ent: missing required field "FrpcClient.key"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Addr(); !ok {
|
||||
return &ValidationError{Name: "addr", err: errors.New(`ent: missing required field "FrpcClient.addr"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Port(); !ok {
|
||||
return &ValidationError{Name: "port", err: errors.New(`ent: missing required field "FrpcClient.port"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Status(); !ok {
|
||||
return &ValidationError{Name: "status", err: errors.New(`ent: missing required field "FrpcClient.status"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.Metadata(); !ok {
|
||||
return &ValidationError{Name: "metadata", err: errors.New(`ent: missing required field "FrpcClient.metadata"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.CreatedAt(); !ok {
|
||||
return &ValidationError{Name: "created_at", err: errors.New(`ent: missing required field "FrpcClient.created_at"`)}
|
||||
}
|
||||
if _, ok := _c.mutation.UpdatedAt(); !ok {
|
||||
return &ValidationError{Name: "updated_at", err: errors.New(`ent: missing required field "FrpcClient.updated_at"`)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (_c *FrpcClientCreate) sqlSave(ctx context.Context) (*FrpcClient, error) {
|
||||
if err := _c.check(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_node, _spec := _c.createSpec()
|
||||
if err := sqlgraph.CreateNode(ctx, _c.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)
|
||||
_c.mutation.id = &_node.ID
|
||||
_c.mutation.done = true
|
||||
return _node, nil
|
||||
}
|
||||
|
||||
func (_c *FrpcClientCreate) createSpec() (*FrpcClient, *sqlgraph.CreateSpec) {
|
||||
var (
|
||||
_node = &FrpcClient{config: _c.config}
|
||||
_spec = sqlgraph.NewCreateSpec(frpcclient.Table, sqlgraph.NewFieldSpec(frpcclient.FieldID, field.TypeInt))
|
||||
)
|
||||
if value, ok := _c.mutation.Name(); ok {
|
||||
_spec.SetField(frpcclient.FieldName, field.TypeString, value)
|
||||
_node.Name = value
|
||||
}
|
||||
if value, ok := _c.mutation.Key(); ok {
|
||||
_spec.SetField(frpcclient.FieldKey, field.TypeString, value)
|
||||
_node.Key = value
|
||||
}
|
||||
if value, ok := _c.mutation.Addr(); ok {
|
||||
_spec.SetField(frpcclient.FieldAddr, field.TypeString, value)
|
||||
_node.Addr = value
|
||||
}
|
||||
if value, ok := _c.mutation.Port(); ok {
|
||||
_spec.SetField(frpcclient.FieldPort, field.TypeInt, value)
|
||||
_node.Port = value
|
||||
}
|
||||
if value, ok := _c.mutation.Status(); ok {
|
||||
_spec.SetField(frpcclient.FieldStatus, field.TypeString, value)
|
||||
_node.Status = value
|
||||
}
|
||||
if value, ok := _c.mutation.Metadata(); ok {
|
||||
_spec.SetField(frpcclient.FieldMetadata, field.TypeString, value)
|
||||
_node.Metadata = value
|
||||
}
|
||||
if value, ok := _c.mutation.CreatedAt(); ok {
|
||||
_spec.SetField(frpcclient.FieldCreatedAt, field.TypeTime, value)
|
||||
_node.CreatedAt = value
|
||||
}
|
||||
if value, ok := _c.mutation.UpdatedAt(); ok {
|
||||
_spec.SetField(frpcclient.FieldUpdatedAt, field.TypeTime, value)
|
||||
_node.UpdatedAt = value
|
||||
}
|
||||
if value, ok := _c.mutation.LastSeen(); ok {
|
||||
_spec.SetField(frpcclient.FieldLastSeen, field.TypeTime, value)
|
||||
_node.LastSeen = value
|
||||
}
|
||||
return _node, _spec
|
||||
}
|
||||
|
||||
// FrpcClientCreateBulk is the builder for creating many FrpcClient entities in bulk.
|
||||
type FrpcClientCreateBulk struct {
|
||||
config
|
||||
err error
|
||||
builders []*FrpcClientCreate
|
||||
}
|
||||
|
||||
// Save creates the FrpcClient entities in the database.
|
||||
func (_c *FrpcClientCreateBulk) Save(ctx context.Context) ([]*FrpcClient, error) {
|
||||
if _c.err != nil {
|
||||
return nil, _c.err
|
||||
}
|
||||
specs := make([]*sqlgraph.CreateSpec, len(_c.builders))
|
||||
nodes := make([]*FrpcClient, len(_c.builders))
|
||||
mutators := make([]Mutator, len(_c.builders))
|
||||
for i := range _c.builders {
|
||||
func(i int, root context.Context) {
|
||||
builder := _c.builders[i]
|
||||
builder.defaults()
|
||||
var mut Mutator = MutateFunc(func(ctx context.Context, m Mutation) (Value, error) {
|
||||
mutation, ok := m.(*FrpcClientMutation)
|
||||
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, _c.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, _c.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, _c.builders[0].mutation); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return nodes, nil
|
||||
}
|
||||
|
||||
// SaveX is like Save, but panics if an error occurs.
|
||||
func (_c *FrpcClientCreateBulk) SaveX(ctx context.Context) []*FrpcClient {
|
||||
v, err := _c.Save(ctx)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
// Exec executes the query.
|
||||
func (_c *FrpcClientCreateBulk) Exec(ctx context.Context) error {
|
||||
_, err := _c.Save(ctx)
|
||||
return err
|
||||
}
|
||||
|
||||
// ExecX is like Exec, but panics if an error occurs.
|
||||
func (_c *FrpcClientCreateBulk) ExecX(ctx context.Context) {
|
||||
if err := _c.Exec(ctx); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user