helper

package
v0.0.0-...-9dd9c43 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Production      = 2 // Please set to 1 if in production.
	Domain          = "https://lin.ks/"
	CookieName      = "lin.ks"
	NodeID          = "N1|"                              // Increase per node by value as "N2|", "N3|"... for multiple node
	DBFolder        = "/home/ubuntu/go/src/shortlink/db" // Without trailing slash at the end.
	AddFromToken    = 3                                  // firt N character to get from token and use it in ShortID
	ShortIDToken    = 7                                  // Further added from 1st N char of AddFromToken+NodeID: total=12
	APITokenLength  = 32
	BypassLockGuard = false // set to true if DB is read from multiple instance.
	DB101           = "Failed to Load Read-Heavy database, Please try again!"
	DB102           = "Failed to Load Write-Heavy database, Please try again!"
	CO101           = "Error CO101: Something went wrong! Please try again!"
	ID101           = "Error ID101: Can not create"
	ID102           = "Error ID102: Can not create due to Numbher issue"
	ID103           = "Error ID103: Authorization Token Missing"
	ID104           = "Error ID104: Failed to generate Short ID, Please try again!"
	ID105           = "Error ID105: Can't fetch Short URL"
	ID106           = "Error ID106: Invalid Short URL"
	ID107           = "Error ID107: Failed to Delete, Please try again"
	ID108           = "Error ID108: Invalid Old Long URL"
	ID109           = "Error ID109: Provided Long URL already exists in your Account"
)

Variables

This section is empty.

Functions

func CheckBDB

func CheckBDB(key []byte, bdb *badger.DB) bool

CheckBDB is to get the key & value from badger database

func CreateMD5Hash

func CreateMD5Hash(text string) string

createMD5Hash md5 hash the URL

func ErrorPrint

func ErrorPrint(devError string, prodError string) string

errorPrint based on development or production server

func FindBDB

func FindBDB(key []byte, bdb *badger.DB) (string, error)

findBDB is to get the key & value from badger database

func FindDB

func FindDB(key []byte, db *pogreb.DB) (string, error)

findDB is to get the key & value from badger database

func GenerateToken

func GenerateToken(salt string, num int) (string, error)

generateToken generates uniqiue Token

func IPs

func IPs(ips []string) string

Ips

func ParseToken

func ParseToken(authToken string) string

parseToken - Parse Token from Authorization Header and get the Token

func PutBDB

func PutBDB(key []byte, value []byte, ifDelete []byte, bdb *badger.DB) error

putBDB is to store key & value in badger database

func PutDB

func PutDB(key []byte, value []byte, ifDelete []byte, db *pogreb.DB) error

putDB is to store key & value in badger database

func ValidateURL

func ValidateURL(url string) bool

validateURL is basic and not 100% correct validate URL, but this can be starting place...

Types

type CreateURL

type CreateURL struct {
	URL string `json:"url"`
}

CreateURL

type DeleteURL

type DeleteURL struct {
	URL     string `json:"long"`
	ShortID string `json:"short"`
}

DeleteURL - Delete

type UpdateURL

type UpdateURL struct {
	OURL    string `json:"old"`
	NURL    string `json:"new"`
	ShortID string `json:"short"`
}

UpdateURL - Delete

Jump to

Keyboard shortcuts

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