gohelper

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2023 License: MIT Imports: 19 Imported by: 0

README

go-helper

collection of functions to help my project

Documentation

Index

Constants

View Source
const DefaultFTPPort = 21 // default ftp port
View Source
const DefaultFTPSPort = 990 // default ftps port
View Source
const DefaultSFTPPort = 22 // default sftp

Variables

This section is empty.

Functions

func AddTime

func AddTime(yourTime time.Time, addedTime int64, timeType string) (resultTime time.Time, err error)

AddTime adding additional time to your time.

func CheckFamily

func CheckFamily(redisSession *redis.Client, username, oldUuid string) (isUsed bool, err error)

CheckFamily check family

func CheckToken

func CheckToken(redisSession *redis.Client, username, uuid string) (isExistAccess, isExistRefresh bool, err error)

func DeleteAllSession

func DeleteAllSession(redisSession *redis.Client, username string, uuid string) (err error)

func GeneratePassword

func GeneratePassword(password Passwords, passwordCost int8) (hash *string, err error)

GeneratePassword generates bcrypt hash string of the given plaintext password because generate password is by using bcrypt, to check hash and password, please use bycrypt CompareHashAndPassword

func GenerateRandString

func GenerateRandString(strSize int, randType string) string

func GetAllSessions

func GetAllSessions(redisSession *redis.Client, username string) ([]interface{}, error)

func GetCurrentUser

func GetCurrentUser(redisSession *redis.Client, uuidIdentifier string) (interface{}, error)

GetCurrentUser get current user session from cookie uuid, uuid already set when jwt claim already set. you can access it by -> uuid, _ := ctx.Get("uuid") TODO: change return to users and device login details

func GetCurrentUserRefresh

func GetCurrentUserRefresh(redisSession *redis.Client, uuidIdentifier string) (interface{}, error)

GetCurrentUserRefresh get current user session from cookie uuid, uuid already set when jwt claim already set. you can access it by -> uuid, _ := ctx.Get("uuid") TODO: change return to users and device login details

func InArray

func InArray[T ArrayType](haystack []T, needle T) (bool, int, error)

func InArrayComplex

func InArrayComplex(haystack []any, needle any) (bool, int, error)

InArray checks whether needle is in haystack. if haystack is an array of struck, then needle need to be a function example : https://stackoverflow.com/questions/38654383/how-to-search-for-an-element-in-a-golang-slice

func RemoveRedisSession

func RemoveRedisSession(redisSession *redis.Client, username, uuid string) (totalLogin int64, err error)

func SetFamily

func SetFamily(redisSession *redis.Client, username, oldUuid, newUuid string, expiration int64) (err error)

SetFamily set family

func SetupLoginSession

func SetupLoginSession(redisSession *redis.Client, username string, data SessionData) (totalLogin int64, err error)

Types

type ArrayType

type ArrayType interface {
	int | int8 | int16 | int32 | int64 |
		uint | uint8 | uint16 | uint32 | uint64 |
		float32 | float64 |
		complex64 | complex128 |
		string |
		uintptr
}

type FamilyCheck

type FamilyCheck struct {
	OldUuid  string `json:"old_uuid"`
	NewUuid  string `json:"new_uuid"`
	Username string `json:"username"`
}

type FtpCredential

type FtpCredential struct {
	FtpHost     string `json:"ftp_host"`
	FtpPort     string `json:"ftp_port"`
	FtpUser     string `json:"ftp_user"`
	FtpPassword string `json:"ftp_password"`
	SshUser     string `json:"ssh_user"`
	SshPassword string `json:"ssh_password"`
	SshKeyFile  string `json:"ssh_key_file"`
}

type HelperFtp

type HelperFtp struct {
	FtpCredential FtpCredential `json:"ftp_credential"`
	// contains filtered or unexported fields
}

func BaseHelperFtp

func BaseHelperFtp(isTest bool) *HelperFtp

func (*HelperFtp) SendFile

func (helper *HelperFtp) SendFile(file interface{}) error

func (*HelperFtp) SetCredential

func (helper *HelperFtp) SetCredential(ftpCredential FtpCredential) *HelperFtp

func (*HelperFtp) SetFtpFile

func (helper *HelperFtp) SetFtpFile(targetFileLocation string, filename string) *HelperFtp

type KeyRedisSessionData

type KeyRedisSessionData struct {
	KeyAccess       string
	KeyRefresh      string
	KeyTotalAccess  string
	KeyTotalRefresh string
	KeyFamily       string
}

type Passwords

type Passwords struct {
	Email    string
	Username string
	Password string
}

type SessionData

type SessionData struct {
	Token SessionToken

	SessionDetails SessionDetails `json:"session_details"`
	Authorization  bool           `json:"authorization"`
}

type SessionDetails

type SessionDetails struct {
	UserDetails   interface{}
	DeviceDetails interface{}
}

type SessionToken

type SessionToken struct {
	Uuid             string `json:"uuid"`
	AccessExpiredAt  int64  `json:"access_expired_at"`
	RefreshExpiredAt int64  `json:"refresh_expired_at"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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