handler

package
v0.0.0-...-0fb5c5d Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2019 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSecretOutdated secret in not valid anymore
	ErrSecretOutdated = errors.New("secret isn't valid anymore")
)

Functions

func RedirectTo

func RedirectTo(url string) gin.HandlerFunc

RedirectTo redirects to provided url

Types

type Database

type Database interface {
	GetSecret(hash string) (*models.Secret, error)
	CreateSecret(hash string, s models.Secret) error
	DeleteSecret(hash string) error
	UpdateSecret(hash string, s models.Secret) error
}

Database is a database layer interface

type SecretHandler

type SecretHandler struct {
	// contains filtered or unexported fields
}

SecretHandler is a REST API handler for secret service

func NewSecretHandler

func NewSecretHandler(db Database) *SecretHandler

NewSecretHandler creates a new API handler

func (*SecretHandler) GetSecret

func (h *SecretHandler) GetSecret(c *gin.Context)

GetSecret returns a secret if possible.

It tries to get a secret by hash, if found, checks view counter and TTL. If any of checks fails, the method will delete this secret as expired. Otherwise, it will decrement view counter and return the secret.

func (*SecretHandler) PostSecret

func (h *SecretHandler) PostSecret(c *gin.Context)

PostSecret creates a new secret.

The method verifies incoming data and creates a new encrypted secret in the database.

Jump to

Keyboard shortcuts

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