dna

package
v0.0.0-...-a012da0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2018 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrSubsequenceNotFound is returned by Check on a failure.
	ErrSubsequenceNotFound = errors.New("subsequence doesn't appear in the DNA sequence")

	// ErrBadAuth is returned if a user validation check fails.
	ErrBadAuth = errors.New("bad auth")

	// ErrInvalidSequence is returned if an invalid sequence is added.
	ErrInvalidSequence = errors.New("invalid DNA sequence")
)
View Source
var ErrInvalidUser = errors.New("invalid user")

ErrInvalidUser is returned when an invalid user is passed to Select.

Functions

This section is empty.

Types

type DefaultService

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

DefaultService provides our DNA sequence business logic.

func NewDefaultService

func NewDefaultService(r Repository, v Validator) *DefaultService

NewDefaultService returns a usable service, wrapping a repository.

func (*DefaultService) Add

func (s *DefaultService) Add(ctx context.Context, user, token, sequence string) (err error)

Add a user and their DNA sequence to the database.

func (*DefaultService) Check

func (s *DefaultService) Check(ctx context.Context, user, token, subsequence string) (err error)

Check returns true if the given subsequence is present in the user's DNA.

type HTTPServer

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

HTTPServer wraps a Service and implements http.Handler.

func NewHTTPServer

func NewHTTPServer(service Service) *HTTPServer

NewHTTPServer returns an HTTPServer wrapping the Service.

func (*HTTPServer) ServeHTTP

func (s *HTTPServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

type Repository

type Repository interface {
	Insert(ctx context.Context, user, sequence string) error
	Select(ctx context.Context, user string) (sequence string, err error)
}

Repository is a client-side interface, which models the concrete e.g. SQLiteRepository.

type SQLiteRepository

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

SQLiteRepository for persistence of the DNA sequences.

func NewSQLiteRepository

func NewSQLiteRepository(urn string) (*SQLiteRepository, error)

NewSQLiteRepository connects to the DB represented by URN.

func (*SQLiteRepository) Insert

func (r *SQLiteRepository) Insert(ctx context.Context, user, sequence string) error

Insert a user's DNA sequence to the repository.

func (*SQLiteRepository) Select

func (r *SQLiteRepository) Select(ctx context.Context, user string) (sequence string, err error)

Select a user's DNA sequence from the repository.

type Service

type Service interface {
	Add(ctx context.Context, user, token, sequence string) error
	Check(ctx context.Context, user, token, subsequence string) error
}

Service describes the expected behavior of the DNA sequence service. Users can add their DNA, and check if subsequences exist.

type Validator

type Validator interface {
	Validate(ctx context.Context, user, token string) error
}

Validator is a client-side interface, which models the parts of the auth service that we use.

Jump to

Keyboard shortcuts

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