misc

package module
v0.0.0-...-193a3fc Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2016 License: MIT Imports: 10 Imported by: 7

README

misc

Miscellaneous GoLang utility methods I've written and collected from various public sources on the web.

/*
 * Returns true if user answered something that starts with "y".
 * Returns false if user answers something that starts with "n".
 * Returns yesIsDefault if no answer given.
 */
func PromptYesNo(msg string, yesIsDefault bool) bool
/*
 * Prompts user for input and returns their response
 */
func Prompt(msg string) string 
/*
 * Prompts user for a password that is never echoed back to the screen.
 */
func PromptPassword(prompt string) string
/*
 * Returns the first non-empty, non-blank string value
 * Returns an empty string if none qualify
 */
func CoalesceStrings(strs ...string) string

Documentation

Overview

hashpassword.go wraps the bcrypt password hashing library with base64 encoding so we can deal in strings

bcrypt is based on this paper: https://www.usenix.org/legacy/event/usenix99/provos/provos.pdf

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChooseOne

func ChooseOne(prompt string, values ...string) string

ChooseOne prompts the user to enter one of n values Example: answer := misc.PromptOne("Continue, Quit, or Redo? [cqr]: ", ["c", "q", "r"])

func CoalesceStrings

func CoalesceStrings(strs ...string) string

ColesceStrings returns the first non-empty string value or, if none qualify, it returns an empty string

func ComparePassword

func ComparePassword(hashBase64, testPassword string) bool

ComparePassword hashes the test password and then compares the two hashes.

func CompareStrings

func CompareStrings(s1, s2 string) int

CompareStrings returns negative when first string is less, positive if more, zero otherwise

func ContainsString

func ContainsString(slice []string, value string) bool

ContainsString returns true if the given slice contains the given string

func HashCost

func HashCost(hashBase64 string) (int, error)

HashCost returns how much it cost (1-31) to hash this password

func HashPassword

func HashPassword(password string, cost int) (string, error)

HashPassword hashes the clear-text password and encodes it as base64,

func HashPasswordDefaultCost

func HashPasswordDefaultCost(password string) (string, error)

HashPasswordDefaultCost hashes the clear-text password and encodes it as base64,

func InStrings

func InStrings(str string, strs ...string) bool

InStrings returns true if the first argument is in the list of following arguments or it returns false if none match. InStrings is similar to ConstainsString which takes a slice of strings instead of a variable number of string arguments.

func Prompt

func Prompt(prompt string) string

Prompt prompts user for input and returns their response

func PromptPassword

func PromptPassword(prompt string) string

PromptPassword prompts user for a password that is never echoed back to the screen. This needs to be improved because it leaves terminal in unusable state when user presses Ctrl-C

func PromptYesNo

func PromptYesNo(prompt string, yesIsDefault bool) bool

PromptYesNo returns true if user answered something that starts with "y". PromptYesNo returns false if user answers something that starts with "n". PromptYesNo returns yesIsDefault if no answer given.

Types

This section is empty.

Jump to

Keyboard shortcuts

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