Documentation
¶
Index ¶
- Constants
- Variables
- func AllDocuments() iter.Seq2[DocId, Document]
- func AllDocumentsOf[T Document]() iter.Seq2[DocId, T]
- func Clear()
- func Delete(id DocId) error
- func DeleteAllOf[T Document]() int
- func DeleteHandler[T Document]() http.HandlerFunc
- func GetAs[T Document](id DocId) (*T, error)
- func GetHandler[T Document]() http.HandlerFunc
- func ListHandler[T Document]() http.HandlerFunc
- func Put(id DocId, doc Document) error
- func PutHandler[T Document]() http.HandlerFunc
- func ReadAll(r io.Reader) error
- func ReadAllFromFile(filename string) (err error)
- func RegisterHandlers[T Document](prefix string, mux *http.ServeMux)
- func RegisterType[T Document]()
- func WriteAll(w io.Writer) error
- func WriteAllToFile(filename string) (err error)
- type DocId
- type Document
Constants ¶
const EmptyDocId = DocId("")
EmptyDocId is an empty document identifier.
Variables ¶
var ( // ErrDocumentNotFound is returned when a document is not found. ErrDocumentNotFound = errors.New("document not found") // ErrEmptyDocumentId is returned when a valid document id is required. ErrEmptyDocumentId = errors.New("empty document id") // ErrDocumentTypeMismatch is returned when a document type does not match the expected type ErrDocumentTypeMismatch = errors.New("document type mismatch") )
Functions ¶
func AllDocuments ¶ added in v1.2.4
AllDocuments returns a iterator that goes over all stored documents
func AllDocumentsOf ¶ added in v1.2.4
AllDocumentsOf returns a iterator that goes over all stored documents of a given type
func DeleteAllOf ¶ added in v1.2.5
DeleteAllOf removes all documents of the given type returns the number of documents deleted
func DeleteHandler ¶ added in v1.2.1
func DeleteHandler[T Document]() http.HandlerFunc
DeleteHandler returns an http.HandlerFunc for deleting a document. It expects the document ID to be in the URL path (e.g., /docs/my-doc-id).
func GetHandler ¶ added in v1.2.1
func GetHandler[T Document]() http.HandlerFunc
GetHandler returns an http.HandlerFunc for retrieving a document. It expects the document ID to be in the URL path (e.g., /docs/my-doc-id).
func ListHandler ¶ added in v1.2.4
func ListHandler[T Document]() http.HandlerFunc
ListHandler returns an http.HandlerFunc for retrieving all documents of the given type
func PutHandler ¶ added in v1.2.1
func PutHandler[T Document]() http.HandlerFunc
PutHandler returns an http.HandlerFunc for adding or updating a document. It expects a POST request with a JSON body representing the full document. On success, it returns status 204
func ReadAllFromFile ¶ added in v1.2.0
ReadAllFromFile reads the entire docstore from a single file, replacing any contents that were in the docstore.
func RegisterHandlers ¶ added in v1.2.1
RegisterHandlers registers the store handlers on a ServeMux. This uses the path-based routing available in Go 1.22+. For example, if you provide "/api/docs", it will register: - POST /api/docs/{id} - GET /api/docs/{id} - DELETE /api/docs/{id}
func RegisterType ¶ added in v1.2.0
func RegisterType[T Document]()
RegisterType registers the given document type with the gob package. This is necessary so that the gob package knows how to encode and decode the document type.
func WriteAllToFile ¶ added in v1.2.0
WriteAllToFile writes the entire docstore to a single file.