github.com/kotovmak/go-admin@v1.1.1/plugins/admin/modules/table/config.go (about)

     1  package table
     2  
     3  import (
     4  	"github.com/kotovmak/go-admin/modules/db"
     5  )
     6  
     7  type Config struct {
     8  	Driver         string
     9  	DriverMode     string
    10  	Connection     string
    11  	CanAdd         bool
    12  	Editable       bool
    13  	Deletable      bool
    14  	Exportable     bool
    15  	PrimaryKey     PrimaryKey
    16  	SourceURL      string
    17  	GetDataFun     GetDataFun
    18  	OnlyInfo       bool
    19  	OnlyNewForm    bool
    20  	OnlyUpdateForm bool
    21  	OnlyDetail     bool
    22  }
    23  
    24  func DefaultConfig() Config {
    25  	return Config{
    26  		Driver:     db.DriverMysql,
    27  		CanAdd:     true,
    28  		Editable:   true,
    29  		Deletable:  true,
    30  		Exportable: true,
    31  		Connection: DefaultConnectionName,
    32  		PrimaryKey: PrimaryKey{
    33  			Type: db.Int,
    34  			Name: DefaultPrimaryKeyName,
    35  		},
    36  	}
    37  }
    38  
    39  func (config Config) SetPrimaryKey(name string, typ db.DatabaseType) Config {
    40  	config.PrimaryKey.Name = name
    41  	config.PrimaryKey.Type = typ
    42  	return config
    43  }
    44  
    45  func (config Config) SetDriverMode(mode string) Config {
    46  	config.DriverMode = mode
    47  	return config
    48  }
    49  
    50  func (config Config) SetPrimaryKeyType(typ string) Config {
    51  	config.PrimaryKey.Type = db.GetDTAndCheck(typ)
    52  	return config
    53  }
    54  
    55  func (config Config) SetCanAdd(canAdd bool) Config {
    56  	config.CanAdd = canAdd
    57  	return config
    58  }
    59  
    60  func (config Config) SetSourceURL(url string) Config {
    61  	config.SourceURL = url
    62  	return config
    63  }
    64  
    65  func (config Config) SetGetDataFun(fun GetDataFun) Config {
    66  	config.GetDataFun = fun
    67  	return config
    68  }
    69  
    70  func (config Config) SetEditable(editable bool) Config {
    71  	config.Editable = editable
    72  	return config
    73  }
    74  
    75  func (config Config) SetDeletable(deletable bool) Config {
    76  	config.Deletable = deletable
    77  	return config
    78  }
    79  
    80  func (config Config) SetOnlyInfo() Config {
    81  	config.OnlyInfo = true
    82  	return config
    83  }
    84  
    85  func (config Config) SetOnlyUpdateForm() Config {
    86  	config.OnlyUpdateForm = true
    87  	return config
    88  }
    89  
    90  func (config Config) SetOnlyNewForm() Config {
    91  	config.OnlyNewForm = true
    92  	return config
    93  }
    94  
    95  func (config Config) SetOnlyDetail() Config {
    96  	config.OnlyDetail = true
    97  	return config
    98  }
    99  
   100  func (config Config) SetExportable(exportable bool) Config {
   101  	config.Exportable = exportable
   102  	return config
   103  }
   104  
   105  func (config Config) SetConnection(connection string) Config {
   106  	config.Connection = connection
   107  	return config
   108  }
   109  
   110  func DefaultConfigWithDriver(driver string) Config {
   111  	return Config{
   112  		Driver:     driver,
   113  		Connection: DefaultConnectionName,
   114  		CanAdd:     true,
   115  		Editable:   true,
   116  		Deletable:  true,
   117  		Exportable: true,
   118  		PrimaryKey: PrimaryKey{
   119  			Type: db.Int,
   120  			Name: DefaultPrimaryKeyName,
   121  		},
   122  	}
   123  }
   124  
   125  func DefaultConfigWithDriverAndConnection(driver, conn string) Config {
   126  	return Config{
   127  		Driver:     driver,
   128  		Connection: conn,
   129  		CanAdd:     true,
   130  		Editable:   true,
   131  		Deletable:  true,
   132  		Exportable: true,
   133  		PrimaryKey: PrimaryKey{
   134  			Type: db.Int,
   135  			Name: DefaultPrimaryKeyName,
   136  		},
   137  	}
   138  }