datastore

package
v0.1.4-beta.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 14, 2023 License: BSD-3-Clause Imports: 3 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var Logger *zap.Logger

Logger is a package-level variable to access the zap logger throughout the datastore package.

Functions

func CloseClient

func CloseClient(client *datastore.Client)

CloseClient closes the Datastore client. It should be called to clean up resources and connections when the client is no longer needed. Logs an error if the client could not be closed, but does not return an error.

func CreateContext

func CreateContext() context.Context

CreateContext creates a new context that can be used for Datastore operations. It returns a non-nil, empty context.

func CreateDatastoreClient

func CreateDatastoreClient(ctx context.Context, projectID string) (*datastore.Client, error)

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.

func SaveURL

func SaveURL(ctx context.Context, client *datastore.Client, url *URL) error

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 URL

type URL struct {
	Original string `datastore:"original"` // The original URL.
	ID       string `datastore:"id"`       // The unique identifier for the shortened URL.
}

URL represents a shortened URL with its original URL and a unique identifier.

func GetURL

func GetURL(ctx context.Context, client *datastore.Client, id string) (*URL, error)

GetURL retrieves a URL entity by its ID from Datastore. It requires a context, a Datastore client, and the ID of the URL entity. Returns the URL entity or an error if the entity could not be retrieved.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL