api

package
v0.0.0-...-f0f63f4 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: MIT Imports: 2 Imported by: 0

README

gomithrilapp

Sample notepad application in Mithril and Go.

Build Setup

# Install dependencies.
go get github.com/FiloSottile/gvt
gvt restore

# Serve at localhost:8081.
go run cmd/api/main.go

# Build for production and launch server.
go build cmd/api/main.go
./main

# Run tests (must set up database first).
docker run -d --name=mysql57 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=password mysql:5.7
go test ./...
docker rm -f mysql57

# Run coverage tests.
go test ./... -coverprofile cover.out && go tool cover -html=cover.out \
-o cover.html && open cover.html && sleep 5 && rm cover.html && rm cover.out

Documentation

Overview

Package api gomithrilapp API

This is the API for the sample notepad application in Mithril and Go.

Swagger 2.0 Spec - generated by [go-swagger](https://github.com/go-swagger/go-swagger)

Schemes: http Host: localhost:8080 BasePath: / Version: 1.0

Consumes: - application/json

Produces: - application/json

SecurityDefinitions: token:

type: apiKey
name: Authorization
in: header
description: "In the 'Value' textbox below, please enter in the word 'Bearer', a space, and then paste in your token."

swagger:meta

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type IBind

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

IBind provides bind and validation for requests.

type IContext

type IContext interface {
	SetUserID(r *http.Request, val string)
	UserID(r *http.Request) (string, bool)
}

IContext provides handlers for type request context.

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
	QueryRowScan(dest interface{}, query string, args ...interface{}) error
	Name() string
	RecordExists(err error) (bool, error)
	AffectedRows(result sql.Result) int
	RecordExistsString(err error, s string) (bool, string, error)
	SuppressNoRowsError(err error) error
}

IDatabase provides data query capabilities.

type IPassword

type IPassword interface {
	Hash(password string) (string, error)
	Match(hash, password string) bool
}

IPassword provides password hashing.

type IQuery

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

IQuery provides default queries.

type IRecord

type IRecord interface {
	Table() string
	PrimaryKey() string
}

IRecord provides table information.

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 IToken

type IToken interface {
	Generate(userID string) (string, error)
	Verify(s string) (string, error)
}

IToken provides outputs for the JWT.

Directories

Path Synopsis
cmd
api
internal
jwt
ui
pkg
env
Package env will fill a struct from environment variables.
Package env will fill a struct from environment variables.
logger
Package logger standardizes the logging functions available to your team.
Package logger standardizes the logging functions available to your team.
mock
Package mock allows you to return specific values for functions.
Package mock allows you to return specific values for functions.
passhash
Package passhash provides password hashing functionality using bcrypt.
Package passhash provides password hashing functionality using bcrypt.

Jump to

Keyboard shortcuts

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