Documentation
¶
Overview ¶
Package datastore provides a set of functions to interact with Google Cloud Datastore.
It allows for operations such as creating a new client, saving a URL entity, retrieving a URL entity by its ID, and closing the client connection.
This version has been updated to use the zap logger for consistent and structured logging.
Copyright (c) 2023 H0llyW00dzZ
Index ¶
- Variables
- func CloseClient(client *Client) error
- func CreateContext() context.Context
- func DeleteURL(ctx context.Context, client *Client, id string) error
- func SaveURL(ctx context.Context, client *Client, url *URL) error
- func SetLogger(logger *zap.Logger)
- func UpdateURL(ctx context.Context, client *Client, id string, newURL string) error
- type Client
- type URL
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("datastore: no such entity")
ErrNotFound is the error returned when a requested entity is not found in the datastore.
var Logger *zap.Logger
Logger is a package-level variable to access the zap logger throughout the datastore package. It is intended to be used by other functions within the package for logging purposes.
Functions ¶
func CloseClient ¶
CloseClient closes the Datastore client. It should be called to clean up resources and connections when the client is no longer needed. Returns an error if the client could not be closed.
func CreateContext ¶
CreateContext creates a new context that can be used for Datastore operations. It returns a non-nil, empty context.
func DeleteURL ¶ added in v0.1.10
DeleteURL deletes a URL entity by its ID from Datastore. It requires a context, a Datastore client, and the ID of the URL entity. Returns an error if the entity could not be deleted.
func SaveURL ¶
SaveURL saves a new URL entity to Datastore under the Kind 'urlz'. It takes a context, a Datastore client, and a URL struct. If the Kind 'urlz' does not exist, Datastore will create it automatically. Returns an error if the URL entity could not be saved.
Types ¶
type Client ¶ added in v0.1.5
type Client struct {
*cloudDatastore.Client
}
Client wraps the cloudDatastore.Client to abstract away the underlying implementation.
func CreateDatastoreClient ¶
CreateDatastoreClient creates a new client connected to Google Cloud Datastore. It requires a context and a projectID to initialize the connection. Returns a new Datastore client or an error if the connection could not be established.