utils

package
v1.16.1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2023 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DirExists

func DirExists(path string) bool

DirExists returns true if the directory is present on disk

func ExtractTextFromHTML

func ExtractTextFromHTML(s string) string

ExtractTextFromHTML returns a string with only the text version of the web page

func FileExists

func FileExists(filename string) bool

FileExists returns true if the file is present on disk

func FlatStruct added in v0.9.1

func FlatStruct(s interface{}) map[string]string

FlatStruct tries to flat a struct object in a map[string]string

func IsFlagPassed

func IsFlagPassed(name string) bool

IsFlagPassed returns true if the flag is present on the command line

func MD5Sum added in v0.8.2

func MD5Sum(content interface{}) string

MD5Sum calculate the MD5 Hash of a string or []byte

func Md5File added in v0.8.2

func Md5File(filename string) (string, error)

Md5File calculate the MD5 Hash of a file

func ParseCookieFile

func ParseCookieFile(filename string) ([]*http.Cookie, error)

ParseCookieFile transforms JSON file in slice of http.Cookie

Types

type Cookies

type Cookies []struct {
	Domain         string  `json:"domain"`
	ExpirationDate float64 `json:"expirationDate,omitempty"`
	HostOnly       bool    `json:"hostOnly"`
	HTTPOnly       bool    `json:"httpOnly"`
	Name           string  `json:"name"`
	Path           string  `json:"path"`
	SameSite       string  `json:"sameSite"`
	Secure         bool    `json:"secure"`
	Session        bool    `json:"session"`
	StoreID        string  `json:"storeId"`
	Value          string  `json:"value"`
	ID             int     `json:"id"`
}

Cookies maps the json file exported from Chrome containing the cookies

type GlobalTTLMap added in v0.8.2

type GlobalTTLMap struct {
	Caches map[string]*TTLMap
}

GlobalTTLMap is a cache shared between all the rules

func GetGlobalTTLMapInstance added in v0.8.2

func GetGlobalTTLMapInstance(gcdelay time.Duration) *GlobalTTLMap

GetGlobalTTLMapInstance returns the unique GlobalTTLMap (singleton)

type HTMLMeta

type HTMLMeta struct {
	Title       string `json:"title"`
	Description string `json:"description"`
	Image       string `json:"image"`
	SiteName    string `json:"site_name"`
}

HTMLMeta contains information from the HTML page

func GetMetaFromHTML

func GetMetaFromHTML(s string) *HTMLMeta

GetMetaFromHTML extracts info from an HTML page and store them on a HTMLMeta struct

type TTLMap added in v0.8.2

type TTLMap struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

TTLMap is a cache with ttl

func GetNamedTTLMap added in v1.14.0

func GetNamedTTLMap(name string, gcdelay time.Duration) *TTLMap

GetNamedTTLMap return a Cache stored on the globalTTLMap with a name

func NewTTLMap added in v0.8.2

func NewTTLMap(gcdelay time.Duration) (m *TTLMap)

NewTTLMap creates a TTLMap instance

func (*TTLMap) Close added in v1.3.1

func (m *TTLMap) Close()

Close is closing the map

func (*TTLMap) Get added in v0.8.2

func (m *TTLMap) Get(k interface{}) (interface{}, bool)

Get returns the value of the associated key from the cache

func (*TTLMap) Len added in v0.8.2

func (m *TTLMap) Len() int

Len returns the number of cached keys

func (*TTLMap) Put added in v0.8.2

func (m *TTLMap) Put(k, v interface{}, ttl int64)

Put inserts a key => value pair in the cache

func (*TTLMap) SetPersistence added in v0.9.1

func (m *TTLMap) SetPersistence(filename string) error

SetPersistence load the map from a file (it can be used only the first time)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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