Documentation ¶
Index ¶
- type Admin
- type BaseContextData
- type Column
- type DB
- func (d *DB) CreateEntity(ctx context.Context, tableName, primaryKey string, columns []Column) error
- func (d *DB) DeleteEntityByID(ctx context.Context, tableName, primaryKey string, id any) error
- func (d *DB) GetEntityByID(ctx context.Context, tableName, primaryKey string, editColumns []string, ...) (*Row, error)
- func (d *DB) GetTableColumenRows(ctx context.Context, tableName, primaryKey string, selectColumns []string) ([]Row, []string, error)
- func (d *DB) GetTableFieldTypes(ctx context.Context, tableName string) (map[string]string, error)
- func (d *DB) GetTableRow(ctx context.Context, tableName, primaryKey string, editColumns []string) (*Row, error)
- func (d *DB) Open(ctx context.Context) (*sql.Conn, error)
- func (d *DB) UpdateEntity(ctx context.Context, tableName, primaryKey string, primaryKeyValue string, ...) error
- type EditData
- type Entity
- type Formatter
- type ListData
- type Menu
- type Option
- func WithBaseURL(baseURL string) Option
- func WithDatabaseURI(uri string) Option
- func WithDefaultFormatter(column string, formatter Formatter) Option
- func WithDefaultFormatters(formatters map[string]Formatter) Option
- func WithEntities(entities []Entity) Option
- func WithEntity(entity Entity) Option
- func WithPermissionChecker(fn func(r *http.Request, userID, entityName, action string) bool) Option
- func WithSearchHandler(fn func(r *http.Request, q string) ([]SearchResult, error)) Option
- func WithTemplate(name, text string) Option
- func WithTemplateFunc(name string, fn interface{}) Option
- func WithTemplateFuncs(funcs template.FuncMap) Option
- func WithUserIdentifier(fn func(r *http.Request) string) Option
- type Row
- type SearchData
- type SearchResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Admin ¶
type Admin struct { // DatabaseURI represents the database uri. default is "postgres://postgres:postgres@localhost:5432/postgres?sslmode=disable". DatabaseURI string // Entities represents the entities of the admin module. Entities map[string]Entity // BaseURL represents the base url for the admin module. default is "/admin". BaseURL string // DefaultFormatters represents the default formatters for each column. if provided, the formatter will be used to format the column value. // if a column has a formatter, the formatter will be used instead of the default formatter. DefaultFormatters map[string]Formatter // TemplateFuncs represents the template funcs for the admin module. TemplateFuncs template.FuncMap // Templates represents the templates for the admin module. will override the default templates. Templates map[string]*template.Template // PermissionChecker represents the permission checker for the admin module. PermissionChecker func(r *http.Request, userID, entityName, action string) bool // UserIdentifier represents the function that returns the user identifier from the request. UserIdentifier func(r *http.Request) string // SearchHandler represents the search handler for the admin module. SearchHandler func(r *http.Request, query string) ([]SearchResult, error) // contains filtered or unexported fields }
Admin represents the admin module.
type BaseContextData ¶
BaseContextData represents the data needed to render the base template.
type DB ¶
DB represents a database.
func (*DB) CreateEntity ¶
func (d *DB) CreateEntity(ctx context.Context, tableName, primaryKey string, columns []Column) error
CreateEntity creates a row of a table.
func (*DB) DeleteEntityByID ¶
DeleteEntityByID deletes a row of a table by its primary key.
func (*DB) GetEntityByID ¶
func (d *DB) GetEntityByID(ctx context.Context, tableName, primaryKey string, editColumns []string, id any) (*Row, error)
GetEntityByID returns a row of a table by its primary key.
func (*DB) GetTableColumenRows ¶
func (d *DB) GetTableColumenRows(ctx context.Context, tableName, primaryKey string, selectColumns []string) ([]Row, []string, error)
GetTableColumenRows returns the rows of a table.
func (*DB) GetTableFieldTypes ¶
GetTableFieldTypes returns the field types of a table.
func (*DB) GetTableRow ¶
func (d *DB) GetTableRow(ctx context.Context, tableName, primaryKey string, editColumns []string) (*Row, error)
GetTableRow returns the columns of a table.
type EditData ¶
type EditData struct { Title string Description string Row Row EntityName string EntityID string IsEdit bool BaseContextData }
EditData represents the data needed to render the edit template.
type Entity ¶
type Entity struct { // Entity table name. TableName string // Primary key column name. default is "id". PrimaryKey string // Entity title plural. default is the entity table name. TitlePlural string // Entity title singular. default is the entity table name. TitleSingular string // FavIcon represents the entity fav icon. default is empty. FavIcon string // Menu order. default is 0. Order int // Entity description. default is empty. Description string // SelectColumns columns. if nil, all columns will be selected. SelectColumns []string // EditColumns columns. if nil, all columns will be selected. EditColumns []string // NewColumns columns. if nil, edit columns or all columns will be selected. NewColumns []string // ColumnNameFormatter represents the column name formatter. if provided, the formatter will be used to format the column name. ColumnNameFormatter map[string]Formatter // ValueFormatters for each column. if provided, the formatter will be used to format the column value. ValueFormatters map[string]Formatter }
Entity represents a database entity.
type ListData ¶
type ListData struct { Title string Description string EntityName string Columns []string Rows []Row BaseContextData }
ListData represents the data needed to render the list template.
type Option ¶
Option represents an admin option.
func WithBaseURL ¶
WithBaseURL returns an admin option that sets the admin base url.
func WithDatabaseURI ¶
WithDatabaseURI returns an admin option that sets the database uri.
func WithDefaultFormatter ¶
WithDefaultFormatter returns an admin option that sets a default formatter.
func WithDefaultFormatters ¶
WithDefaultFormatters returns an admin option that sets the default formatters.
func WithEntities ¶
WithEntities returns an admin option that adds entities.
func WithEntity ¶
WithEntity returns an admin option that adds an entity.
func WithPermissionChecker ¶
WithPermissionChecker returns an admin option that sets the permission checker.
func WithSearchHandler ¶
WithSearchHandler returns an admin option that sets the search handler.
func WithTemplate ¶
WithTemplate returns an admin option that adds a template.
func WithTemplateFunc ¶
WithTemplateFunc returns an admin option that adds a template func.
func WithTemplateFuncs ¶
WithTemplateFuncs returns an admin option that adds template funcs.
type SearchData ¶
type SearchData struct { Query string ResultCount int BaseContextData Results []SearchResult }
SearchData represents the data needed to render the search template.
type SearchResult ¶
SearchResult represents the search results.