utils

package
v0.0.0-...-da5f288 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultTokenSecret = "D8AB934ECD92D0008477DFFE679D06A89779DE4BDB0D436A0B1D16E4F5BEFA2B"

DefaultTokenSecret is the default key used when there is no env vars

Variables

View Source
var DBHost = GetVar("DB_HOST", "localhost")

DBHost for the production/development database

View Source
var DBName = GetVar("DB_NAME", "pricewatch")

DBName for the production/development database

View Source
var DBPassword = GetVar("DB_PASSWORD", "postgres")

DBPassword for the production/development database

View Source
var DBPort = GetVar("DB_PORT", "5432")

DBPort for the production/development database

View Source
var DBUrl = GetVar("DATABASE_URL", "")

DBUrl is the database url string

View Source
var DBUser = GetVar("DB_USER", "postgres")

DBUser for the production/development database

View Source
var GPTokenSecret = []byte(GetVar("GP_TOKEN_SECRET", DefaultTokenSecret))

GPTokenSecret is the secret token for authorization through JWT

View Source
var ServerPort = GetVar("PORT", "8080")

ServerPort is the port the server listens on

View Source
var Sugar = logger.Sugar()

Sugar is an API for logging from Logger.

Functions

func CheckError

func CheckError(err error)

CheckError panics on an error, ending the program. It takes in the error to panic on if at all.

func ExtractClaims

func ExtractClaims(tokenString string) map[string]interface{}

ExtractClaims will take the claim out of an authorization header. It takes in the JWT tokenString to read the claims from. It returns a map of string to interface for the claims.

func GenerateJWT

func GenerateJWT(id uuid.UUID) string

GenerateJWT creates a JSON Web Token based on an id, with an expiration time of 1 day It returns the token string

func GetVar

func GetVar(name string, _default string) string

GetVar gets an environment variable with name name, and returns its value if its set If not, the function returns the default value

func HashPassword

func HashPassword(pass string) (hash []byte, err error)

HashPassword hashes a password string

Types

This section is empty.

Jump to

Keyboard shortcuts

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