utils

package
v0.0.0-...-6d8a328 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2022 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

Function checks the plaintext string and hash string and returns either true or false depending.

func ConnectDB

func ConnectDB(databaseHost, databasePort, databaseUser, databasePassword, databaseName, databaseSchemaName string) (*sql.DB, error)

func ConvertNullStringToNullTime

func ConvertNullStringToNullTime(s null.String, timezone string, nowWhenIsZero bool) (null.Time, error)

func ConvertNullStringToTime

func ConvertNullStringToTime(s null.String, timezone string, nowWhenIsZero bool) (time.Time, error)

func ConvertPGAdminTimeStringToTime

func ConvertPGAdminTimeStringToTime(dateTimeString string) (time.Time, error)

Function will convert the timestamp string that `PgAdmin` exports (when you export as CSV format) into a Golang `time` data-format. TODO: Implement matching of timezones!

func DownloadS3ObjToTmpDir

func DownloadS3ObjToTmpDir(s3Client *s3.S3, bucketName string, s3key string, uuid string) (string, error)

Function will download the s3 file to the `/tmp` folder on the system and return the local filepath address of the downloaded file.

func FindMatchingObjectKeyInS3Bucket

func FindMatchingObjectKeyInS3Bucket(s3Objects *s3.ListObjectsOutput, partialKey string) string

Function will iterate over all the s3 objects to match the partial key with the actual key found in the S3 bucket.

func GenerateJWTTokenPair

func GenerateJWTTokenPair(hmacSecret []byte, uuid string, d time.Duration) (string, string, error)

GenerateJWTTokenPair Generate the `access token` and `refresh token` for the secret key.

func GetBinFromBase64String

func GetBinFromBase64String(b64s string) ([]byte, error)

GetBinFromBase64String will convert the string parameter and return a `[]byte` object.

Special thanks: (1) https://github.com/tomchristie/django-rest-framework/pull/1268 (2) https://stackoverflow.com/a/39587386

func GetS3Obj

func GetS3Obj(s3Client *s3.S3, bucketName string, s3key string) (*s3.GetObjectOutput, error)

func GetS3ObjBin

func GetS3ObjBin(s3Client *s3.S3, bucketName string, s3key string) (io.ReadCloser, error)

Function will get the s3 file and return the file binary.

func HashPassword

func HashPassword(password string) (string, error)

Function takes the plaintext string and returns a hash string.

func HashPasswordAlgorithm

func HashPasswordAlgorithm() string

Function returns the algorithm used for hashing.

func HeaderSize

func HeaderSize(h http.Header) int64

func IPFromHostPort

func IPFromHostPort(hp string) string

func JsonPrettyPrint

func JsonPrettyPrint(in string) string

Utility function nicely prints string data of JSON formatted contents. SOURCE: https://stackoverflow.com/a/36544455

func ListAllS3ObjectsInBucket

func ListAllS3ObjectsInBucket(s3Client *s3.S3, bucketName string) *s3.ListObjectsOutput

Function returns a list of all the S3 stored objects sin a specific bucket.

func NewS3Client

func NewS3Client(key, secret, endpoint, region string) *s3.S3

Function connects to a specific S3 bucket instance and returns a connected instance structure.

func NowTimestampString

func NowTimestampString() string

func ProcessJWTToken

func ProcessJWTToken(hmacSecret []byte, reqToken string) (string, error)

ProcessJWTToken validates either the `access token` or `refresh token` and returns either the `uuid` if success or error on failure.

func UploadBinToS3

func UploadBinToS3(s3Client *s3.S3, bucketName string, s3key string, body string, acl string) error

Types

type LogEntry

type LogEntry struct {
	ReceivedTime      time.Time
	RequestMethod     string
	RequestURL        string
	RequestHeaderSize int64
	RequestBodySize   int64
	UserAgent         string
	Referer           string
	Proto             string

	RemoteIP string
	ServerIP string

	Status             int
	ResponseHeaderSize int64
	ResponseBodySize   int64
	Latency            time.Duration
}

type S3Util

type S3Util struct {
	S3Client   *s3.S3
	BucketName string
}

func NewS3Util

func NewS3Util(key, secret, endpoint, region, bucketName string) *S3Util

func (*S3Util) GetURL

func (s3u *S3Util) GetURL(key string, expire time.Duration) (string, error)

GetURL will return a URL string for a link to the access of the file for the key. https://github.com/aws/aws-sdk-go/blob/e2d6cb448883e4f4fcc5246650f89bde349041ec/aws/request/request.go#L315

func (*S3Util) Upload

func (s3u *S3Util) Upload(s3key string, body string, acl string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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