platform: github.com/brw31415/platform/utils Index | Files

package utils

import "github.com/brw31415/platform/utils"

Index

Package Files

config.go diagnostic.go lru.go mail.go random.go textgeneration.go time.go urlencode.go

Constants

const (
    MODE_DEV        = "dev"
    MODE_BETA       = "beta"
    MODE_PROD       = "prod"
    LOG_ROTATE_SIZE = 10000
)
const (
    DIAGNOSTIC_URL = "https://d7zmvsa9e04kk.cloudfront.net"

    PROP_DIAGNOSTIC_ID                = "id"
    PROP_DIAGNOSTIC_CATEGORY          = "c"
    VAL_DIAGNOSTIC_CATEGORY_DEFAULT   = "d"
    PROP_DIAGNOSTIC_BUILD             = "b"
    PROP_DIAGNOSTIC_DATABASE          = "db"
    PROP_DIAGNOSTIC_OS                = "os"
    PROP_DIAGNOSTIC_USER_COUNT        = "uc"
    PROP_DIAGNOSTIC_ACTIVE_USER_COUNT = "auc"
    PROP_DIAGNOSTIC_UNIT_TESTS        = "ut"
)
const (
    ALPHANUMERIC = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890"
    LOWERCASE    = "abcdefghijklmnopqrstuvwxyz"
)
const GIBBERISH_TEXT = "" /* 9070 byte string literal not displayed */

Lovely giberish for all to use

Variables

var Cfg *model.Config = &model.Config{}
var CfgDiagnosticId = ""
var CfgFileName string = ""
var CfgLastModified int64 = 0
var ClientCfg map[string]string = map[string]string{}
var FUZZY_STRINGS_EMAILS = []string{
    "sue@thatmightbe",
    "sue@thatmightbe.c",
    "sue@thatmightbe.co",
    "su+san@thatmightbe.com",
    "1@2.am",
    "a@b.co.uk",
    "a@b.cancerresearch",
    "su+s+an@thatmightbe.com",
    "per.iod@thatmightbe.com",
}

Strings that should pass as acceptable emails

var FUZZY_STRINGS_NAMES = []string{
    "*",
    "?",
    ".",
    "}{][)(><",
    "{}[]()<>",

    "qahwah ( قهوة)",
    "שָׁלוֹם עֲלֵיכֶם",
    "Ramen チャーシュー chāshū",
    "言而无信",
    "Ṫ͌ó̍ ̍͂̓̍̍̀i̊ͯ͒",
    "&amp; &lt; &qu",

    "' or '1'='1' -- ",
    "' or '1'='1' ({ ",
    "' or '1'='1' /* ",
    "1;DROP TABLE users",

    "<b><i><u><strong><em>",

    "sue@thatmightbe",
    "sue@thatmightbe.",
    "sue@thatmightbe.c",
    "sue@thatmightbe.co",
    "sue @ thatmightbe.com",
    "apos'trophe@thatmightbe.com",
    "apos''''trophe@thatmightbe.com",
    "su+san@thatmightbe.com",
    "su+s+an@thatmightbe.com",
    "per.iod@thatmightbe.com",
    "per..iods@thatmightbe.com",
    ".period@thatmightbe.com",
    "tom(comment)@thatmightbe.com",
    "(comment)tom@thatmightbe.com",
    "\"quotes\"@thatmightbe.com",
    "\"\\\"(),:;<>@[\\]\"@thatmightbe.com",
    "a!#$%&'*+-/=?^_`{|}~b@thatmightbe.com",
    "local@[127.0.0.1]",
    "jill@(comment)example.com",
    "jill@example.com(comment)",
    "a@b.中国",
    "1@2.am",
    "a@b.co.uk",
    "a@b.cancerresearch",

    "<a href=\"//www.google.com\">Teh Googles</a>",
    "<img src=\"//upload.wikimedia.org/wikipelogo-v2_2x.png\" />",
    "<b><i><u><strong><em>",
    "&amp; &lt; &quot; &apos;",

    ";alert('Well this is awkward.');",
    "<script type='text/javascript'>alert('yay puppies');</script>",

    "Ṫ͌ó̍ ̍͂̓̍̍̀i̊ͯ͒nͧ̍̓̃͋v",
    "H҉̵̞̟̠̖̗̘Ȅ̐̐̑̒̚OMI҉̵̞̟̠",
}

Strings that should pass as acceptable team names

var FUZZY_STRINGS_POSTS = []string{
    ""  /* 159 byte string literal not displayed */+
        "```" + `
multi-line code block<enter here>
multi-line code block
emoji that should not render in code block: :ice_cream:
` + "```" + `
` + "`monospace`" + "" /* 250 byte string literal not displayed */,

    "" /* 263 byte string literal not displayed */,

    "" /* 496 byte string literal not displayed */,

    ` **[4]** - **[More Markdown Tests]**
# This is a heading

I am a multiline
text.

#### I am a level four heading

` + "```tex" + `
f(x) = \int_{-\infty}^\infty
    \hat f(\xi)\,e^{2 \pi i \xi x}
    \,d\xi
` + "```" + `
* This was some tex code*
`,

    "" /* 246 byte string literal not displayed */,

    "" /* 486 byte string literal not displayed */,

    `**[7] [Image Test]**

## this *should* display an image

http://37.media.tumblr.com/tumblr_mavsumGGAd1qboaw8o1_500.jpg
`,

    "" /* 3917 byte string literal not displayed */,

    "" /* 3338 byte string literal not displayed */,

    "" /* 3471 byte string literal not displayed */,

    ""  /* 1013 byte string literal not displayed */+
        "`" + `http://example.com` + "`" + `
[example.com](example.com) links to ` + "`" + `http://example.com` + "`" + `
[example.com/other](example.com) links to ` + "`" + `http://example.com` + "`" + `
[example.com/other_link](example.com/example) links to ` + "`" + `http://example.com/example` + "`" + `
www.example.com links to ` + "`" + `http://www.example.com` + "`" + `
https://example.com links to ` + "`" + `https://example.com` + "`" + `and not ` + "`" + `http://example.com` + "`" + "" /* 210 byte string literal not displayed */+
        "`" + `mailto:test@example.com` + "`" + `
[email link](mailto:test@example.com) links to ` + "`" + `mailto:test@example.com` + "`" + `and not ` + "`" + `http://mailto:test@example.com` + "`" + `
[other link](ts3server://example.com) links to ` + "`" + `ts3server://example.com` + "`" + `and not ` + "`" + `http://ts3server://example.com` + "`" + "" /* 693 byte string literal not displayed */,

    "*", "?", ".", "}{][)(><", "{}[]()<>",

    "qahwah ( قهوة)",
    "שָׁלוֹם עֲלֵיכֶם",
    "Ramen チャーシュー chāshū",
    "言而无信",
    "Ṫ͌ó̍ ̍͂̓̍̍̀i̊ͯ͒",
    "&amp; &lt; &qu",

    "' or '1'='1' -- ",
    "' or '1'='1' ({ ",
    "' or '1'='1' /* ",
    "1;DROP TABLE users",

    "<b><i><u><strong><em>",

    "sue@thatmightbe",
    "sue@thatmightbe.",
    "sue@thatmightbe.c",
    "sue@thatmightbe.co",
    "su+san@thatmightbe.com",
    "a@b.中国",
    "1@2.am",
    "a@b.co.uk",
    "a@b.cancerresearch",
    "local@[127.0.0.1]",

    "!@$%^&:*.,/|;'\"+=?`~#",
    "'\"/\\\"\"''\\/",
    "gggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg",
    "" /* 1026 byte string literal not displayed */,
    "ą ć ę ł ń ó ś ź ż č ď ě ň ř š ť ž ă î ø å æ á é í ó ú Ç Ğ İ Ö Ş Ü",
    "abcdefghijklmnopqrstuvwrxyz0123456789 -_",
    "" /* 329 byte string literal not displayed */,
    "" /* 254 byte string literal not displayed */,

    "<a href=\"//www.google.com\">Teh Googles</a>",
    "<img src=\"//upload.wikimedia.org/wikipedia/meta/b/be/Wikipedia-logo-v2_2x.png\" />",
    "&amp; &lt; &quot; &apos;",
    "" /* 149 byte string literal not displayed */,

    ";alert('Well this is awkward.');",
    "<script type='text/javascript'>alert('yay puppies');</script>",

    "" /* 163 byte string literal not displayed */,

    "apos'trophe@thatmightbe.com",
    "apos''''trophe@thatmightbe.com",
    "su+s+an@thatmightbe.com",
    "per.iod@thatmightbe.com",
    "per..iods@thatmightbe.com",
    ".period@thatmightbe.com",
    "tom(comment)@thatmightbe.com",
    "(comment)tom@thatmightbe.com",
    "\"quotes\"@thatmightbe.com",
    "\"\\\"(),:;<>@[\\]\"@thatmightbe.com",
    "a!#$%&'*+-/=?^_`{|}~b@thatmightbe.com",
    "jill@(comment)example.com",
    "jill@example.com(comment)",
    "ben@ggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg.com",
    "" /* 137 byte string literal not displayed */,
    "" /* 325 byte string literal not displayed */,
}

Strings that should pass as acceptable posts

func ConfigureCmdLineLog Uses

func ConfigureCmdLineLog()

func EndOfDay Uses

func EndOfDay(t time.Time) time.Time

func FindConfigFile Uses

func FindConfigFile(fileName string) string

func FindDir Uses

func FindDir(dir string) string

func FuzzEmail Uses

func FuzzEmail() string

func FuzzName Uses

func FuzzName() string

func FuzzPost Uses

func FuzzPost() string

func GetLogFileLocation Uses

func GetLogFileLocation(fileLocation string) string

func LoadConfig Uses

func LoadConfig(fileName string)

LoadConfig will try to search around for the corresponding config file. It will search /tmp/fileName then attempt ./config/fileName, then ../config/fileName and last it will look at fileName

func MillisFromTime Uses

func MillisFromTime(t time.Time) int64

func RandIntFromRange Uses

func RandIntFromRange(r Range) int

func RandString Uses

func RandString(l int, charset string) string

func RandomEmail Uses

func RandomEmail(length Range, charset string) string

func RandomName Uses

func RandomName(length Range, charset string) string

func RandomText Uses

func RandomText(length Range, hashtags Range, mentions Range, users []string) string

Random selection of text for post

func SaveConfig Uses

func SaveConfig(fileName string, config *model.Config) *model.AppError

func SendDiagnostic Uses

func SendDiagnostic(values url.Values)

func SendMail Uses

func SendMail(to, subject, body string) *model.AppError

func SendMailUsingConfig Uses

func SendMailUsingConfig(to, subject, body string, config *model.Config) *model.AppError

func StartOfDay Uses

func StartOfDay(t time.Time) time.Time

func TestConnection Uses

func TestConnection(config *model.Config)

func UrlEncode Uses

func UrlEncode(str string) string

func Yesterday Uses

func Yesterday() time.Time

type Cache Uses

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

Cache is a thread-safe fixed size LRU cache.

func NewLru Uses

func NewLru(size int) *Cache

New creates an LRU of the given size

func NewLruWithEvict Uses

func NewLruWithEvict(size int, onEvicted func(key interface{}, value interface{})) (*Cache, error)

func (*Cache) Add Uses

func (c *Cache) Add(key, value interface{}) bool

func (*Cache) AddWithExpiresInSecs Uses

func (c *Cache) AddWithExpiresInSecs(key, value interface{}, expireAtSecs int64) bool

Add adds a value to the cache. Returns true if an eviction occured.

func (*Cache) Get Uses

func (c *Cache) Get(key interface{}) (value interface{}, ok bool)

Get looks up a key's value from the cache.

func (*Cache) Keys Uses

func (c *Cache) Keys() []interface{}

Keys returns a slice of the keys in the cache, from oldest to newest.

func (*Cache) Len Uses

func (c *Cache) Len() int

Len returns the number of items in the cache.

func (*Cache) Purge Uses

func (c *Cache) Purge()

Purge is used to completely clear the cache

func (*Cache) Remove Uses

func (c *Cache) Remove(key interface{})

Remove removes the provided key from the cache.

func (*Cache) RemoveOldest Uses

func (c *Cache) RemoveOldest()

RemoveOldest removes the oldest item from the cache.

type Range Uses

type Range struct {
    Begin int
    End   int
}

Package utils imports 21 packages (graph). Updated 2017-06-29. Refresh now. Tools for package owners. This is a dead-end fork (no commits since the fork).