pkg

package
v1.2.8 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	ProjectDirectory = filepath.Dir(filepath.Dir(filePath))
)

Functions

func CheckPasswordHash

func CheckPasswordHash(password, hash string) bool

func ConvertHTMLToPDF

func ConvertHTMLToPDF(converter string, outputFile string, data []byte, header, footer []byte) error

func DecodeFromBase64

func DecodeFromBase64(v interface{}, enc string) error

func EncodeToBase64

func EncodeToBase64(v interface{}) (string, error)

func FormatDocuments

func FormatDocuments(docs any, cols ...string) string

func HashPassword

func HashPassword(password string) (string, error)

func LevenshteinDistance added in v1.1.0

func LevenshteinDistance(s, t string, ignoreCase bool) int

LevenshteinDistance compares two strings and returns the levenshtein distance between them.

Example
package main

import (
	"fmt"
	"strings"

	"github.com/masudur-rahman/expense-tracker-bot/models"
	"github.com/masudur-rahman/expense-tracker-bot/pkg"
)

func main() {
	a := "snack"

	md := 10000
	var rs string

	for _, subcat := range models.TxnSubcategories {
		ld := min(pkg.LevenshteinDistance(subcat.ID, a, true),
			pkg.LevenshteinDistance(subcat.Name, a, true))
		suggestByLevenshtein := ld <= 3
		suggestByPrefix := strings.HasPrefix(strings.ToLower(subcat.Name), strings.ToLower(a))
		if suggestByLevenshtein && ld < md || suggestByPrefix {
			md = ld
			rs = subcat.Name
		}
	}

	fmt.Printf("Distance between `%v` and `%v` is %v\n", a, rs, md)
}
Output:

Hello

func MustHashPassword

func MustHashPassword(password string) string

func ParseDate

func ParseDate(date string) (time.Time, error)

func ParseGraphQLData

func ParseGraphQLData(src *graphql.Result, dst any, key string) error

func ParseInto

func ParseInto(src any, dst any) error

func ParseProtoAnyInto

func ParseProtoAnyInto(src *anypb.Any, dst any) error

func ParseTime

func ParseTime(tim string) (time.Time, error)

func ProtoAnyToMap

func ProtoAnyToMap(in *anypb.Any) (map[string]interface{}, error)

func SplitString

func SplitString(input string, sep rune) []string

func StartOfMonth

func StartOfMonth() time.Time

func ToProtoAny

func ToProtoAny(in any) (*anypb.Any, error)

Types

type Options

type Options struct {
	Style        table.Style
	EnableStdout bool
	RenderType   RenderType
}

type Printer

type Printer interface {
	PrintDocument(doc interface{}) string
	PrintDocuments(docs interface{}) string

	WithColumns(columns ...string) Printer
	WithExceptColumns(exceptColumns []string) Printer
	WithAllColumns() Printer
	WithStyle(style table.Style) Printer
	WithStdout(stdout bool) Printer
	WithRenderType(typ RenderType) Printer

	ClearColumns()
}

func NewPrinter

func NewPrinter(options Options) Printer

type RenderType

type RenderType string
const (
	RenderTypeDefault  RenderType = "default"
	RenderTypeCSV      RenderType = "csv"
	RenderTypeHTML     RenderType = "html"
	RenderTypeMarkdown RenderType = "markdown"
)

Jump to

Keyboard shortcuts

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