diff --git a/auth_utility.go b/auth_utility.go index 1ffab64..827eb80 100644 --- a/auth_utility.go +++ b/auth_utility.go @@ -1,16 +1,13 @@ package restutility import ( -// "fmt" "errors" -// "os" "time" "crypto/sha256" "crypto/rand" "encoding/hex" "strings" "github.com/dgrijalva/jwt-go" -// "github.com/SermoDigital/jose/jwt" ) const OneDay = time.Hour*24 @@ -34,7 +31,7 @@ type CredentialsStruct struct { Password string `json:"password"` } -func generateSalt() (string, error) { +func GenerateSalt() (string, error) { salt := "" rawsalt := make([]byte, saltSize) @@ -46,13 +43,13 @@ func generateSalt() (string, error) { return salt, nil } -func hashMessage(message string, presalt string) (string, string, error) { +func HashMessage(message string, presalt string) (string, string, error) { hash, salt := "", "" var err error // chech if message is presalted if presalt == "" { - salt, err = generateSalt() + salt, err = GenerateSalt() if err != nil { return "", "", err } @@ -78,7 +75,7 @@ func hashMessage(message string, presalt string) (string, string, error) { return hash, salt, nil } -func issueAPIToken(username, role string) (Token, error) { +func IssueAPIToken(username, role string) (Token, error) { var apiToken Token var err error @@ -103,7 +100,7 @@ func issueAPIToken(username, role string) (Token, error) { return apiToken, nil } -func refreshAPIToken(tokenString string) (Token, error) { +func RefreshAPIToken(tokenString string) (Token, error) { var newToken Token tokenString = strings.TrimPrefix(tokenString, "Bearer ") token, err := parseTokenFunc(tokenString) @@ -128,7 +125,7 @@ func refreshAPIToken(tokenString string) (Token, error) { return newToken, nil } -func parseAPIToken(tokenString string) (*TokenClaims, error) { +func ParseAPIToken(tokenString string) (*TokenClaims, error) { if ok := strings.HasPrefix(tokenString, "Bearer"); ok { tokenString = strings.TrimPrefix(tokenString, "Bearer ") } else { @@ -157,8 +154,3 @@ func parseTokenFunc(tokenString string) (*jwt.Token, error) { ) return token, err } - -func authMinRegReq(uname, pword string) (bool, error) { - return true, nil -} - diff --git a/format_utility.go b/format_utility.go index 0ae8d9d..9dc625c 100644 --- a/format_utility.go +++ b/format_utility.go @@ -1,9 +1,7 @@ package restutility import ( - "strings" "time" - "strconv" ) func UnixToDate(input int64) time.Time { diff --git a/http_utility.go b/http_utility.go index 04b319d..2368972 100644 --- a/http_utility.go +++ b/http_utility.go @@ -9,7 +9,7 @@ var _apiVersion = "/api/v1" func SetApiVersion(ver string) string { _apiVersion = ver - return _apiVeresion + return _apiVersion } ////