90 lines
2.2 KiB
Markdown
90 lines
2.2 KiB
Markdown
# Notion Mapper
|
|
|
|
Libreria Go per mappare pagine e proprietà di Notion a struct Go in modo type-safe e configurabile.
|
|
|
|
## Caratteristiche
|
|
|
|
- **Type-safe**: Mappa le proprietà di Notion a struct Go con generics
|
|
- **Configurabile**: Definisci mapping personalizzati per ogni proprietà
|
|
- **Helper functions**: Funzioni di utilità per estrarre valori comuni da proprietà Notion
|
|
- **Supporto completo**: Supporta proprietà di pagina e proprietà individuali
|
|
|
|
## Installazione
|
|
|
|
```bash
|
|
go get ceccgit.duckdns.org/simone/notion-mapper
|
|
```
|
|
|
|
## Utilizzo
|
|
|
|
```go
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/jomei/notionapi"
|
|
"ceccgit.duckdns.org/simone/notion-mapper"
|
|
)
|
|
|
|
type Task struct {
|
|
ID string
|
|
Title string
|
|
Priority string
|
|
DueDate string
|
|
}
|
|
|
|
func main() {
|
|
// Crea un nuovo mapper per la struct Task
|
|
mapper := notionmapper.NewMapper[Task]()
|
|
|
|
// Configura i mapping
|
|
mapper.
|
|
ForMember("Title", func(prop notionapi.Property, dest *Task) {
|
|
dest.Title = notionmapper.ExtractTitle(prop)
|
|
}).
|
|
ForMember("Priority", func(prop notionapi.Property, dest *Task) {
|
|
dest.Priority = notionmapper.ExtractSelect(prop)
|
|
}).
|
|
ForMember("Due Date", func(prop notionapi.Property, dest *Task) {
|
|
dest.DueDate = notionmapper.ExtractRichText(prop)
|
|
}).
|
|
ForPage(func(page notionapi.Page, dest *Task) {
|
|
dest.ID = page.ID.String()
|
|
})
|
|
|
|
// Esempio di mapping da una pagina Notion
|
|
// page := notionapi.Page{...} // la tua pagina Notion
|
|
// task := mapper.MapFrom(page)
|
|
|
|
fmt.Println("Mapper configurato!")
|
|
}
|
|
```
|
|
|
|
## API
|
|
|
|
### `NewMapper[TDest]()`
|
|
Crea un nuovo mapper per il tipo di destinazione specificato.
|
|
|
|
### `ForMember(propertyName, setter)`
|
|
Configura come mappare una property specifica di Notion.
|
|
|
|
### `ForPage(setter)`
|
|
Configura un mapping che ha accesso all'intera pagina (utile per ID, timestamps, etc.).
|
|
|
|
### `MapFrom(page)`
|
|
Esegue il mapping da una pagina Notion alla struct di destinazione.
|
|
|
|
## Helper Functions
|
|
|
|
- `ExtractTitle(prop)` - Estrae testo da TitleProperty
|
|
- `ExtractRichText(prop)` - Estrae testo da RichTextProperty
|
|
- `ExtractNumber(prop)` - Estrae numero da NumberProperty
|
|
- `ExtractSelect(prop)` - Estrae valore da SelectProperty
|
|
|
|
## Dipendenze
|
|
|
|
- `github.com/jomei/notionapi` v1.13.3
|
|
|
|
## Licenza
|
|
|
|
MIT |