slug

package
v0.0.0-...-b405234 Latest Latest
Warning

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

Go to latest
Published: Oct 4, 2016 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

package slug provides support for "slug" keys, which are string IDs for Datastore keys that need to be usable as URL components.

Let's say you want to key the Profile entity on a URL-friendly form of a person's name. You setttle on something like:

/profiles/john-smith

Suppose, as can happen, you have two different John Smiths in your system. Keying on name might be a problem unless you can autoincrement the slug thus:

/profiles/john-smith-2

Which is precisely the behavior permitted by slug.Next. You can write code for this that looks like:

nextSlug, err := slug.Next(ctx, "Profile", slugify(newProfile.name))
datastore.Put(ctx, datastore.NewKey(ctx, "Profile", nextSlug, 0, nil), &newProfile)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Next

func Next(ctx context.Context, kind, slug string) (nextSlug string, err error)

Next returns the next available slug for a given entity type. If none exist as yet, the unmodified value of slug is returned.

func Reset

func Reset(ctx context.Context, kind, slug string) error

Reset resets the slug counter for a given entity type and slug.

func ResetAll

func ResetAll(ctx context.Context, kind string) error

ResetAll resets all slug counters for a given entity type.

Types

This section is empty.

Jump to

Keyboard shortcuts

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