component

package
v0.0.0-...-44af80e Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewCoreMock

func NewCoreMock(db *database.DBW) (Core, *CoreMock)

NewCoreMock returns all mocked dependencies.

Types

type Core

type Core struct {
	Log      ILogger
	DB       IDatabase
	Q        IQuery
	Bind     IBind
	Response IResponse
	Token    IToken
	Password IPassword
}

Core contains all the dependencies for the components.

func NewCore

func NewCore(l ILogger, d IDatabase, q IQuery, b IBind, resp IResponse, t IToken, p IPassword) Core

NewCore returns the standard component dependencies.

type CoreMock

type CoreMock struct {
	Log      *testutil.MockLogger
	DB       IDatabase
	Q        IQuery
	Bind     IBind
	Response IResponse
	Token    *testutil.MockToken
	Password IPassword
}

CoreMock contains all the mocked dependencies.

type IBind

type IBind interface {
	FormUnmarshal(i interface{}, r *http.Request) (err error)
	Validate(s interface{}) error
}

IBind provides bind and validation for requests.

type IDatabase

type IDatabase interface {
	Exec(query string, args ...interface{}) (sql.Result, error)
	Get(dest interface{}, query string, args ...interface{}) error
	Select(dest interface{}, query string, args ...interface{}) error
}

IDatabase provides data query capabilities.

type ILogger

type ILogger interface {
	Fatalf(format string, v ...interface{})
	Printf(format string, v ...interface{})
}

ILogger provides logging capabilities.

type IPassword

type IPassword interface {
	HashString(password string) (string, error)
	MatchString(hash, password string) bool
}

IPassword provides password hashing.

type IQuery

type IQuery interface {
	FindOneByID(dest query.IRecord, ID string) (found bool, err error)
	FindAll(dest query.IRecord) (total int, err error)
	ExistsByID(db query.IRecord, s string) (found bool, err error)
	ExistsByField(db query.IRecord, field string, value string) (found bool, ID string, err error)
	DeleteOneByID(dest query.IRecord, ID string) (affected int, err error)
	DeleteAll(dest query.IRecord) (affected int, err error)
}

IQuery provides default queries.

type IResponse

type IResponse interface {
	JSON(w http.ResponseWriter, body interface{}) (int, error)
	Created(w http.ResponseWriter, recordID string) (int, error)
	OK(w http.ResponseWriter, message string) (int, error)
}

IResponse provides outputs for data.

type IRouter

type IRouter interface {
	Delete(path string, fn router.Handler)
	Get(path string, fn router.Handler)
	Head(path string, fn router.Handler)
	Options(path string, fn router.Handler)
	Patch(path string, fn router.Handler)
	Post(path string, fn router.Handler)
	Put(path string, fn router.Handler)
}

IRouter provides routing capabilities.

type IToken

type IToken interface {
	Generate(userID string, duration time.Duration) (string, error)
}

IToken provides outputs for the JWT.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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