app

package
v0.0.0-...-3e81905 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Db *sql.DB
View Source
var TempSecret = "123"

Functions

func Close

func Close()

func ExtractToken

func ExtractToken(r *http.Request) string

func GetSimpleValue

func GetSimpleValue(r *http.Request, paramName string) (value string, exists bool)

func GetSimpleValueAsInt

func GetSimpleValueAsInt(r *http.Request, paramName string) (value int64, exists bool, err error)

func Hash

func Hash(password string) ([]byte, error)

func InitDb

func InitDb(host, dbname, dbuser, dbpass string)

func Install

func Install(loadTestData bool)

func ReadToken

func ReadToken(secretKey string, tokenString string) (*jwt.Token, error)

func ResponseERROR

func ResponseERROR(w http.ResponseWriter, statusCode int, err error)

func ResponseJSON

func ResponseJSON(w http.ResponseWriter, statusCode int, data interface{})

func SetMiddlewareAuth

func SetMiddlewareAuth(next http.HandlerFunc) http.HandlerFunc

Проверяем токен

func SetMiddlewareJSON

func SetMiddlewareJSON(next http.HandlerFunc) http.HandlerFunc

Добавляем Content-Type всем обработчикам

func TokenValid

func TokenValid(r *http.Request) error

Проверяем токен

func ValidPassword

func ValidPassword(hashedPassword, password string) (bool, error)

Types

type Route

type Route struct {
	Name          string
	Method        string
	Pattern       string
	SetHeaderJSON bool
	ValidateToken bool
	HandlerFunc   http.HandlerFunc
}

type Routes

type Routes []Route

type TokenPair

type TokenPair struct {
	AccessToken  string `json:"access_token"`
	TokenType    string `json:"token_type"`
	ExpiresIn    int64  `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
}

func CreateTokenPair

func CreateTokenPair(userId int64, secretKey string, tokenExpiresSec int64) (*TokenPair, error)

Создаем и подписываем пару токенов

Jump to

Keyboard shortcuts

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