misc

package
v2.4.7 Latest Latest
Warning

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

Go to latest
Published: Jun 4, 2023 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Overview

Package misc contains some miscellaneous functions and constants that don't really fit elsewhere.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// EmailValidation (const)
	EmailValidation = regexp.MustCompile("^[a-zA-Z0-9.!#$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$")
)

Functions

func IsEmailValid

func IsEmailValid(email string) bool

IsEmailValid checks if the given email is valid using regex only.

Identical to the function found on this page: https://golangcode.com/validate-an-email-address/.

Example

Check if the email:

test@example.com

Is valid and then check whether some normal text is valid.

// Valid example
e := "test@example.com"
if IsEmailValid(e) {
	fmt.Println(e + " is a valid email")
}

// Invalid example
if !IsEmailValid("just text") {
	fmt.Println("not a valid email")
}
Output:
test@example.com is a valid email
not a valid email

Types

type Ordered added in v2.4.7

type Ordered int
const (
	Less    Ordered = -1
	Equal   Ordered = 0
	Greater Ordered = 1
)

func Compare added in v2.4.7

func Compare[V constraints.Ordered](a, b V) Ordered

Compare compares the two constraints.Ordered values and returns:

  • Less: a < b
  • Equal: a == b
  • Greater: a > b
Example

Compare some constraints.Ordered values!

fmt.Printf("Compare(1, 2) = %s\n", Compare(1, 2))
fmt.Printf("Compare(1.23, 1.23) = %s\n", Compare(1.23, 1.23))
fmt.Printf("Compare(\"world\", \"hello\") = %s\n", Compare("world", "hello"))
Output:
Compare(1, 2) = Less
Compare(1.23, 1.23) = Equal
Compare("world", "hello") = Greater

func (Ordered) String added in v2.4.7

func (o Ordered) String() string

Jump to

Keyboard shortcuts

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