utils

package
v0.0.0-...-40d815b Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorTAG = 1
	InfoTAG  = 2
	DebugTAG = 3
)

tag definitions

Variables

View Source
var HostIP, _ = GetOutboundIP()

HostIP variable stores the IPv4 address of the host machine

Functions

func CompareHashWithPassword

func CompareHashWithPassword(hashedPassword, password string) bool

CompareHashWithPassword returns true if given password matches with the hash and false otherwise

func Contains

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

Contains check if an string is present in the given string array

func GetFreePort

func GetFreePort() (int, error)

GetFreePort asks the kernel for a free open port that is ready to use.

func GetFreePorts

func GetFreePorts(count int) ([]int, error)

GetFreePorts asks the kernel for free open ports that are ready to use.

func GetMapKeys

func GetMapKeys(data map[string]string) []string

GetMapKeys returns the keys present in a map

func GetOutboundIP

func GetOutboundIP() (string, error)

GetOutboundIP returns the preferred outbound IP of this machine

func HashPassword

func HashPassword(password string) (string, error)

HashPassword creates the hash of the password to be stored in database

func IsGenDNSAlive

func IsGenDNSAlive(url string) bool

IsGenDNSAlive checks if a GenDNS instance is alive or not

func IsValidPort

func IsValidPort(port int) bool

IsValidPort checks if the port is valid and free to use

func Log

func Log(context, message string, TAG int)

Log logs to the console with your custom TAG

func LogDebug

func LogDebug(context, template string, args ...interface{})

LogDebug logs debug messages to console

func LogError

func LogError(context string, err error)

LogError logs type error to console

func LogInfo

func LogInfo(context, template string, args ...interface{})

LogInfo logs information to the console

func LogResErr

func LogResErr(context string, e types.ResponseError)

LogResErr logs type ResponseError to console

func NewTarArchiveFromContent

func NewTarArchiveFromContent(content []byte, filename string, mode int64) (io.Reader, error)

NewTarArchiveFromContent returns an io.Reader type tar archive from content in []byte

func NewTarArchiveFromPath

func NewTarArchiveFromPath(path string) (io.Reader, error)

NewTarArchiveFromPath returns an io.Reader type tar archive from content in given path

func NotAlive

func NotAlive(url string) bool

NotAlive checks if a given instance is alive or not

func QueryToFilter

func QueryToFilter(queries map[string][]string) types.M

QueryToFilter filters out queries from the URL parameters

func SendServerErrorResponse

func SendServerErrorResponse(c *gin.Context, err error)

SendServerErrorResponse sends internal server error messages to the client depending on development mode or production mode

func ToStringSlice

func ToStringSlice(v interface{}) []string

ToStringSlice converts interface{} to []string

Types

type Scheduler

type Scheduler struct {
	// contains filtered or unexported fields
}

Scheduler deals with running and managing various tasks at defined intervals

func NewScheduler

func NewScheduler(interval time.Duration, task func()) *Scheduler

NewScheduler returns a pointer to a Scheduler object

func (*Scheduler) Run

func (s *Scheduler) Run()

Run starts scheduling the given task

func (*Scheduler) RunAsync

func (s *Scheduler) RunAsync()

RunAsync starts scheduling the given task in a non-blocking manner

func (*Scheduler) Terminate

func (s *Scheduler) Terminate()

Terminate stops the scheduler

Jump to

Keyboard shortcuts

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