This is used for my personal portfolio website. It is essentially used, to create dynamic content for the website. This includes dynamic schema, dynamic content and dynamic endpoint creation.
This is implemented using Go and MongoDB. For authentication, Redis might be used aswell.
- create a new schema
- add dynamic fields to the schema
- save the schema
type Schema struct {
Name string `json:"name"`
Fields []Field `json:"fields"`
}
type Field struct {
Name string `json:"name"`
DataType string `json:"data_type"`
Data interface{} `json:"data"`
}
These can also handle nested data, but the json would look like this:
{
"name": "test_schema",
"fields": [
{
"name": "description",
"data_type": "text",
"data": "Some description"
}
]
}
- select created schema
- add data to the schema
- get schema
- create menu entry based on schema name and fill page with fields
- get data based on schema name
- fill list with data
This approach works for simple data types, but the following can't be handled:
- nested data
- relations
- files
Since files (images or videos) might be required for projects (or else), the Rust structs might be reworked to handle files. The files can be saved on a Docker Volume
and the path can be saved in the database. But since all fields share the same types, a rework like this might be required:
pub struct Field {
pub name: String,
pub data_type: DataType,
}
pub enum DataType {
String,
Number,
Boolean,
Date,
FileUrl,
}
The endpoints would then change from web::json
to Multipart
. If a schema contains the FileUrl data type, the endpoint needs to handle the file upload (and writing to the volume) first, then the data can be saved to the database (with FileUrl updated with the path).
The implementation is not started, but might be implemented using NextJS or SvelteKit.