utils

package
v0.0.0-...-27c9e6d Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const ForgetPasswordUseCase = "forget_password" // for security_code table (user management)

constants

Variables

View Source
var ErrDatabaseJobIsPending = errors.New("datbase job status is pending")
View Source
var ErrDatabaseJobResultAlreadyExists = errors.New("database job result already exists")
View Source
var ErrDomainNotAvailable = errors.New("domain isn't available")
View Source
var ErrIntegrationNotFound = errors.New("integration not found")
View Source
var ErrPageNotFound = errors.New("page not found")
View Source
var ErrProjectNotFound = errors.New("project not found")
View Source
var ErrReachLimitationOfPlan = errors.New("you have reached your limit. please upgrade your plan")

Errors

View Source
var ErrUserDatabaseNotFound = errors.New("database not found. this error occurs when your project has not database")
View Source
var ErrUserNotFound = errors.New("user not found")
View Source
var FullRunes = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

TODO: ADD COMMENT! Why are there magic strings in the code?

View Source
var GitIntegrationProviders = []string{"github", "gitlab", "bitbucket"}
View Source
var LowercaseRunes = []rune("0123456789abcdefghijklmnopqrstuvwxyz")
View Source
var SpecialProviders = []string{"slack", "instagram", "typeform", "ebay", "mailchimp", "airtable", "gumroad", "hubspot"}

SpecialProviders are not supported by goth package (https://github.com/markbates/goth)

View Source
var UserDatabaseDefaultTables = []string{"user_info", "user_group", "security_code", "views"}

Functions

func Base64URLBytesEncode

func Base64URLBytesEncode(str []byte) string

func CheckErrorExist

func CheckErrorExist(ctx *gin.Context, err error, statusCode int) bool

func CheckPermission

func CheckPermission(action, tableName string, userGroup *models.UserGroup) bool

func ContainsString

func ContainsString(s []string, e string) bool

func CopyFile

func CopyFile(sourceBucket, destinationBucket string, sourceObjectKey, destinationObjectKey string) error

func CreateHostedZone

func CreateHostedZone(externalDomain string) (hostedZoneId string, nsRecords []string, err error)

func Decode

func Decode(s string) []byte

func Decrypt

func Decrypt(text, MySecret string) (string, error)

Decrypt method is to extract back the encrypted text

func DeleteAllResourceRecordSets

func DeleteAllResourceRecordSets(hostedZoneID string) error

func DeleteObject

func DeleteObject(bucketName, objectKey string) error

func DeleteS3Folder

func DeleteS3Folder(bucket, folder string) error

func Encode

func Encode(b []byte) string

func Encrypt

func Encrypt(text, MySecret string) (string, error)

Encrypt method is to encrypt or hide any classified text

func FailOnError

func FailOnError(err error, msg string)

func GeneratToken

func GeneratToken() (string, error)

func GenerateJwtToken

func GenerateJwtToken() (accToken string, err error)

GenerateJwtToken function generates a jwt token based on HS256 algorithm

func GenerateTpJwtToken

func GenerateTpJwtToken(accountId, tpAccountId, userGroup string) (accToken string, err error)

GenerateJwtToken function generates a jwt token based on HS256 algorithm

func GetAccountId

func GetAccountId(c *gin.Context) (string, error)

func GetAccountIdField

func GetAccountIdField(tokenString string) (string, error)

func GetAuthorizedField

func GetAuthorizedField(tokenString string) (bool, error)

func GetFlatOfArray

func GetFlatOfArray(values []interface{}) (interface{}, error)

func GetFlatOfInterface

func GetFlatOfInterface(values interface{}, ended *bool) interface{}

func GetFromNestedJson

func GetFromNestedJson(jsonBytes []byte, keys []string, index int) (interface{}, error)

func GetMD5Hash

func GetMD5Hash(text string) string

func GetNewUuid

func GetNewUuid() string

func GetObjectSize

func GetObjectSize(bucketName, objectKey string) (int64, error)

func GetObjectURL

func GetObjectURL(bucketName, objectKey string, duration time.Duration) (string, error)

func GetProjectDatabaseName

func GetProjectDatabaseName(accountId string, projectName string) string

func GetThirdPartyAccountId

func GetThirdPartyAccountId(c *gin.Context) (tpAccountId string, err error)

func GetTpAccountIdField

func GetTpAccountIdField(tokenString string) (string, error)

func GetUserGroup

func GetUserGroup(tokenString string) (string, error)

func GetUserPlan

func GetUserPlan(accountId, projectType string) (map[string]interface{}, error)

func HashPassword

func HashPassword(password string) (hashedPassword string, err error)

HashPassword function hashes a plain text password with bcrypt package and return result

func InitializeDB

func InitializeDB() (*dbPkg.DB, error)

func InitializeIntegrationConsts

func InitializeIntegrationConsts(address string)

func InitializeMockDB

func InitializeMockDB() (*dbPkg.DB, sqlmock.Sqlmock, error)

func MakeObjectPublic

func MakeObjectPublic(bucketName, objectKey string) error

func RandStringRunes

func RandStringRunes(n int, letterRunes []rune) string

func RegisterCustomValidators

func RegisterCustomValidators()

func RequestSubdomainCertificate

func RequestSubdomainCertificate(fqdn string) (certificateArn, validationRecordName, validationRecordValue string, err error)

RequestCertificate requests a certificate from AWS Certificate Manager and returns the ARN of the certificate plus the validation record name and value

func SetUpRouter

func SetUpRouter() *gin.Engine

func ShouldRedirectWithError

func ShouldRedirectWithError(ctx *gin.Context, err error, url string) bool

func UploadByteSliceToS3

func UploadByteSliceToS3(fileBytes []byte, bucket string, fileName string, size int64, contentType string) error

func UploadFileToS3

func UploadFileToS3(file multipart.File, bucketName, fileName string, size int64, isPublic bool) error

This function uploads a file to S3 bucket. You can specify the bucket name, file name, file size and whether the file is public or not.

func UpsertRoute53Record

func UpsertRoute53Record(domain, value, hostedZoneId, recordType string) error

func ValidateCertificate

func ValidateCertificate(tlsArn string) (bool, error)

Types

type Header struct {
	Key   string
	Value string
}

type HttpClient

type HttpClient interface {
	Do(req *http.Request) (resp *http.Response, err error)
}

func NewHttpClient

func NewHttpClient() HttpClient

type HttpHelper

type HttpHelper interface {
	HttpRequest(method string, url string, body io.Reader, headers []Header, timeout time.Duration, followRedirect bool) (out []byte, err error, statusCode int, header *http.Header)
}

func NewHttpHelper

func NewHttpHelper(client HttpClient) HttpHelper

Jump to

Keyboard shortcuts

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