summaryrefslogtreecommitdiffstats
path: root/vendor
diff options
context:
space:
mode:
authorJesús Espino <jespinog@gmail.com>2018-03-27 10:23:33 +0200
committerGitHub <noreply@github.com>2018-03-27 10:23:33 +0200
commit9e6db178b09387e21ac19ce85369cf1ca7a443e8 (patch)
tree9e51141b285b24b00cf187204077fa8526d9183e /vendor
parent8491ba5740e2d9942b2612ce06aef90bb10ad4c0 (diff)
downloadchat-9e6db178b09387e21ac19ce85369cf1ca7a443e8.tar.gz
chat-9e6db178b09387e21ac19ce85369cf1ca7a443e8.tar.bz2
chat-9e6db178b09387e21ac19ce85369cf1ca7a443e8.zip
Adding durafmt library and use it from enterprise global relay export (#8487)
* Adding durafmt library and use it from enterprise global relay export * Allow to specify different server host and server name on smtp connections * Fixing utils/smtp tests
Diffstat (limited to 'vendor')
-rw-r--r--vendor/github.com/hako/durafmt/.gitignore24
-rw-r--r--vendor/github.com/hako/durafmt/.travis.yml21
-rw-r--r--vendor/github.com/hako/durafmt/CODE_OF_CONDUCT.md46
-rw-r--r--vendor/github.com/hako/durafmt/CONTRIBUTING.md9
-rw-r--r--vendor/github.com/hako/durafmt/LICENSE21
-rw-r--r--vendor/github.com/hako/durafmt/README.md80
-rw-r--r--vendor/github.com/hako/durafmt/durafmt.go120
-rw-r--r--vendor/github.com/hako/durafmt/durafmt_test.go174
8 files changed, 495 insertions, 0 deletions
diff --git a/vendor/github.com/hako/durafmt/.gitignore b/vendor/github.com/hako/durafmt/.gitignore
new file mode 100644
index 000000000..daf913b1b
--- /dev/null
+++ b/vendor/github.com/hako/durafmt/.gitignore
@@ -0,0 +1,24 @@
+# Compiled Object files, Static and Dynamic libs (Shared Objects)
+*.o
+*.a
+*.so
+
+# Folders
+_obj
+_test
+
+# Architecture specific extensions/prefixes
+*.[568vq]
+[568vq].out
+
+*.cgo1.go
+*.cgo2.c
+_cgo_defun.c
+_cgo_gotypes.go
+_cgo_export.*
+
+_testmain.go
+
+*.exe
+*.test
+*.prof
diff --git a/vendor/github.com/hako/durafmt/.travis.yml b/vendor/github.com/hako/durafmt/.travis.yml
new file mode 100644
index 000000000..77f8c12ca
--- /dev/null
+++ b/vendor/github.com/hako/durafmt/.travis.yml
@@ -0,0 +1,21 @@
+language: go
+
+go:
+ - 1.5
+ - 1.6
+ - 1.7
+ - 1.8
+ - 1.9
+ - tip
+
+before_install:
+ - go get golang.org/x/tools/cmd/cover
+
+script:
+ - GOARCH=386 go test # test 32bit architectures.
+ - go test -coverprofile=coverage.txt -covermode=atomic
+
+after_success:
+ - bash <(curl -s https://codecov.io/bash)
+
+sudo: false
diff --git a/vendor/github.com/hako/durafmt/CODE_OF_CONDUCT.md b/vendor/github.com/hako/durafmt/CODE_OF_CONDUCT.md
new file mode 100644
index 000000000..19a95e513
--- /dev/null
+++ b/vendor/github.com/hako/durafmt/CODE_OF_CONDUCT.md
@@ -0,0 +1,46 @@
+# Contributor Covenant Code of Conduct
+
+## Our Pledge
+
+In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
+
+## Our Standards
+
+Examples of behavior that contributes to creating a positive environment include:
+
+* Using welcoming and inclusive language
+* Being respectful of differing viewpoints and experiences
+* Gracefully accepting constructive criticism
+* Focusing on what is best for the community
+* Showing empathy towards other community members
+
+Examples of unacceptable behavior by participants include:
+
+* The use of sexualized language or imagery and unwelcome sexual attention or advances
+* Trolling, insulting/derogatory comments, and personal or political attacks
+* Public or private harassment
+* Publishing others' private information, such as a physical or electronic address, without explicit permission
+* Other conduct which could reasonably be considered inappropriate in a professional setting
+
+## Our Responsibilities
+
+Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
+
+Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
+
+## Scope
+
+This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
+
+## Enforcement
+
+Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at wesley@hakobaito.co.uk. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
+
+Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
+
+## Attribution
+
+This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
+
+[homepage]: http://contributor-covenant.org
+[version]: http://contributor-covenant.org/version/1/4/
diff --git a/vendor/github.com/hako/durafmt/CONTRIBUTING.md b/vendor/github.com/hako/durafmt/CONTRIBUTING.md
new file mode 100644
index 000000000..bdfb376fc
--- /dev/null
+++ b/vendor/github.com/hako/durafmt/CONTRIBUTING.md
@@ -0,0 +1,9 @@
+# Contributing
+
+Contributions are welcome! Fork this repo and add your changes and submit a PR.
+
+If you would like to fix a bug, add a feature or provide feedback you can do so in the issues section.
+
+You can run tests by runnning `go test`. Running `go test; go vet; golint` is recommended.
+
+durafmt is also tested against `gometalinter`.
diff --git a/vendor/github.com/hako/durafmt/LICENSE b/vendor/github.com/hako/durafmt/LICENSE
new file mode 100644
index 000000000..ccb595049
--- /dev/null
+++ b/vendor/github.com/hako/durafmt/LICENSE
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2016 Wesley Hill
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/vendor/github.com/hako/durafmt/README.md b/vendor/github.com/hako/durafmt/README.md
new file mode 100644
index 000000000..128819282
--- /dev/null
+++ b/vendor/github.com/hako/durafmt/README.md
@@ -0,0 +1,80 @@
+# durafmt
+
+[![Build Status](https://travis-ci.org/hako/durafmt.svg?branch=master)](https://travis-ci.org/hako/durafmt) [![Go Report Card](https://goreportcard.com/badge/github.com/hako/durafmt)](https://goreportcard.com/report/github.com/hako/durafmt) [![codecov](https://codecov.io/gh/hako/durafmt/branch/master/graph/badge.svg)](https://codecov.io/gh/hako/durafmt) [![GoDoc](https://godoc.org/github.com/hako/durafmt?status.svg)](https://godoc.org/github.com/hako/durafmt)
+[![Open Source Helpers](https://www.codetriage.com/hako/durafmt/badges/users.svg)](https://www.codetriage.com/hako/durafmt)
+
+
+
+durafmt is a tiny Go library that formats `time.Duration` strings into a human readable format.
+
+```
+go get github.com/hako/durafmt
+```
+
+# Why
+
+If you've worked with `time.Duration` in Go, you most likely have come across this:
+
+```
+53m28.587093086s // :)
+```
+
+The above seems very easy to read, unless your duration looks like this:
+
+```
+354h22m3.24s // :S
+```
+
+# Usage
+
+### durafmt.ParseString()
+
+```go
+package main
+
+import (
+ "fmt"
+ "github.com/hako/durafmt"
+)
+
+func main() {
+ duration, err := durafmt.ParseString("354h22m3.24s")
+ if err != nil {
+ fmt.Println(err)
+ }
+ fmt.Println(duration) // 2 weeks 18 hours 22 minutes 3 seconds
+ // duration.String() // String representation. "2 weeks 18 hours 22 minutes 3 seconds"
+}
+```
+
+### durafmt.Parse()
+
+```go
+package main
+
+import (
+ "fmt"
+ "time"
+ "github.com/hako/durafmt"
+)
+
+func main() {
+ timeduration := (354 * time.Hour) + (22 * time.Minute) + (3 * time.Second)
+ duration := durafmt.Parse(timeduration).String()
+ fmt.Println(duration) // 2 weeks 18 hours 22 minutes 3 seconds
+}
+```
+
+# Contributing
+
+Contributions are welcome! Fork this repo and add your changes and submit a PR.
+
+If you would like to fix a bug, add a feature or provide feedback you can do so in the issues section.
+
+You can run tests by runnning `go test`. Running `go test; go vet; golint` is recommended.
+
+durafmt is also tested against `gometalinter`.
+
+# License
+
+MIT \ No newline at end of file
diff --git a/vendor/github.com/hako/durafmt/durafmt.go b/vendor/github.com/hako/durafmt/durafmt.go
new file mode 100644
index 000000000..a7e0a48c2
--- /dev/null
+++ b/vendor/github.com/hako/durafmt/durafmt.go
@@ -0,0 +1,120 @@
+// Package durafmt formats time.Duration into a human readable format.
+package durafmt
+
+import (
+ "errors"
+ "strconv"
+ "strings"
+ "time"
+)
+
+var (
+ units = []string{"years", "weeks", "days", "hours", "minutes", "seconds", "milliseconds"}
+)
+
+// Durafmt holds the parsed duration and the original input duration.
+type Durafmt struct {
+ duration time.Duration
+ input string // Used as reference.
+}
+
+// Parse creates a new *Durafmt struct, returns error if input is invalid.
+func Parse(dinput time.Duration) *Durafmt {
+ input := dinput.String()
+ return &Durafmt{dinput, input}
+}
+
+// ParseString creates a new *Durafmt struct from a string.
+// returns an error if input is invalid.
+func ParseString(input string) (*Durafmt, error) {
+ if input == "0" || input == "-0" {
+ return nil, errors.New("durafmt: missing unit in duration " + input)
+ }
+ duration, err := time.ParseDuration(input)
+ if err != nil {
+ return nil, err
+ }
+ return &Durafmt{duration, input}, nil
+}
+
+// String parses d *Durafmt into a human readable duration.
+func (d *Durafmt) String() string {
+ var duration string
+
+ // Check for minus durations.
+ if string(d.input[0]) == "-" {
+ duration += "-"
+ d.duration = -d.duration
+ }
+
+ // Convert duration.
+ seconds := int64(d.duration.Seconds()) % 60
+ minutes := int64(d.duration.Minutes()) % 60
+ hours := int64(d.duration.Hours()) % 24
+ days := int64(d.duration/(24*time.Hour)) % 365 % 7
+
+ // Edge case between 364 and 365 days.
+ // We need to calculate weeks from what is left from years
+ leftYearDays := int64(d.duration/(24*time.Hour)) % 365
+ weeks := leftYearDays / 7
+ if leftYearDays >= 364 && leftYearDays < 365 {
+ weeks = 52
+ }
+
+ years := int64(d.duration/(24*time.Hour)) / 365
+ milliseconds := int64(d.duration/time.Millisecond) -
+ (seconds * 1000) - (minutes * 60000) - (hours * 3600000) -
+ (days * 86400000) - (weeks * 604800000) - (years * 31536000000)
+
+ // Create a map of the converted duration time.
+ durationMap := map[string]int64{
+ "milliseconds": milliseconds,
+ "seconds": seconds,
+ "minutes": minutes,
+ "hours": hours,
+ "days": days,
+ "weeks": weeks,
+ "years": years,
+ }
+
+ // Construct duration string.
+ for _, u := range units {
+ v := durationMap[u]
+ strval := strconv.FormatInt(v, 10)
+ switch {
+ // add to the duration string if v > 1.
+ case v > 1:
+ duration += strval + " " + u + " "
+ // remove the plural 's', if v is 1.
+ case v == 1:
+ duration += strval + " " + strings.TrimRight(u, "s") + " "
+ // omit any value with 0s or 0.
+ case d.duration.String() == "0" || d.duration.String() == "0s":
+ // note: milliseconds and minutes have the same suffix (m)
+ // so we have to check if the units match with the suffix.
+
+ // check for a suffix that is NOT the milliseconds suffix.
+ if strings.HasSuffix(d.input, string(u[0])) && !strings.Contains(d.input, "ms") {
+ // if it happens that the units are milliseconds, skip.
+ if u == "milliseconds" {
+ continue
+ }
+ duration += strval + " " + u
+ }
+ // process milliseconds here.
+ if u == "milliseconds" {
+ if strings.Contains(d.input, "ms") {
+ duration += strval + " " + u
+ break
+ }
+ }
+ break
+ // omit any value with 0.
+ case v == 0:
+ continue
+ }
+ }
+ // trim any remaining spaces.
+ duration = strings.TrimSpace(duration)
+ return duration
+}
diff --git a/vendor/github.com/hako/durafmt/durafmt_test.go b/vendor/github.com/hako/durafmt/durafmt_test.go
new file mode 100644
index 000000000..1a94f026f
--- /dev/null
+++ b/vendor/github.com/hako/durafmt/durafmt_test.go
@@ -0,0 +1,174 @@
+package durafmt
+
+import (
+ "testing"
+ "time"
+)
+
+var (
+ testStrings []struct {
+ test string
+ expected string
+ }
+ testTimes []struct {
+ test time.Duration
+ expected string
+ }
+)
+
+// TestParse for durafmt time.Duration conversion.
+func TestParse(t *testing.T) {
+ testTimes = []struct {
+ test time.Duration
+ expected string
+ }{
+ {1 * time.Millisecond, "1 millisecond"},
+ {1 * time.Second, "1 second"},
+ {1 * time.Hour, "1 hour"},
+ {1 * time.Minute, "1 minute"},
+ {2 * time.Millisecond, "2 milliseconds"},
+ {2 * time.Second, "2 seconds"},
+ {2 * time.Minute, "2 minutes"},
+ {1 * time.Hour, "1 hour"},
+ {2 * time.Hour, "2 hours"},
+ {10 * time.Hour, "10 hours"},
+ {24 * time.Hour, "1 day"},
+ {48 * time.Hour, "2 days"},
+ {120 * time.Hour, "5 days"},
+ {168 * time.Hour, "1 week"},
+ {672 * time.Hour, "4 weeks"},
+ {8759 * time.Hour, "52 weeks 23 hours"},
+ {8760 * time.Hour, "1 year"},
+ {17519 * time.Hour, "1 year 52 weeks 23 hours"},
+ {17520 * time.Hour, "2 years"},
+ {26279 * time.Hour, "2 years 52 weeks 23 hours"},
+ {26280 * time.Hour, "3 years"},
+ {201479 * time.Hour, "22 years 52 weeks 23 hours"},
+ {201480 * time.Hour, "23 years"},
+ {-1 * time.Second, "-1 second"},
+ {-10 * time.Second, "-10 seconds"},
+ {-100 * time.Second, "-1 minute 40 seconds"},
+ {-1 * time.Millisecond, "-1 millisecond"},
+ {-10 * time.Millisecond, "-10 milliseconds"},
+ {-100 * time.Millisecond, "-100 milliseconds"},
+ }
+
+ for _, table := range testTimes {
+ result := Parse(table.test).String()
+ if result != table.expected {
+ t.Errorf("Parse(%q).String() = %q. got %q, expected %q",
+ table.test, result, result, table.expected)
+ }
+ }
+}
+
+// TestParseString for durafmt duration string conversion.
+func TestParseString(t *testing.T) {
+ testStrings = []struct {
+ test string
+ expected string
+ }{
+ {"1ms", "1 millisecond"},
+ {"2ms", "2 milliseconds"},
+ {"1s", "1 second"},
+ {"2s", "2 seconds"},
+ {"1m", "1 minute"},
+ {"2m", "2 minutes"},
+ {"1h", "1 hour"},
+ {"2h", "2 hours"},
+ {"10h", "10 hours"},
+ {"24h", "1 day"},
+ {"48h", "2 days"},
+ {"120h", "5 days"},
+ {"168h", "1 week"},
+ {"672h", "4 weeks"},
+ {"8759h", "52 weeks 23 hours"},
+ {"8760h", "1 year"},
+ {"17519h", "1 year 52 weeks 23 hours"},
+ {"17520h", "2 years"},
+ {"26279h", "2 years 52 weeks 23 hours"},
+ {"26280h", "3 years"},
+ {"201479h", "22 years 52 weeks 23 hours"},
+ {"201480h", "23 years"},
+ {"1m0s", "1 minute"},
+ {"1m2s", "1 minute 2 seconds"},
+ {"3h4m5s", "3 hours 4 minutes 5 seconds"},
+ {"6h7m8s9ms", "6 hours 7 minutes 8 seconds 9 milliseconds"},
+ {"0ms", "0 milliseconds"},
+ {"0s", "0 seconds"},
+ {"0m", "0 minutes"},
+ {"0h", "0 hours"},
+ {"0m1ms", "1 millisecond"},
+ {"0m1s", "1 second"},
+ {"0m1m", "1 minute"},
+ {"0m2ms", "2 milliseconds"},
+ {"0m2s", "2 seconds"},
+ {"0m2m", "2 minutes"},
+ {"0m2m3h", "3 hours 2 minutes"},
+ {"0m2m34h", "1 day 10 hours 2 minutes"},
+ {"0m56h7m8ms", "2 days 8 hours 7 minutes 8 milliseconds"},
+ {"-1ms", "-1 millisecond"},
+ {"-1s", "-1 second"},
+ {"-1m", "-1 minute"},
+ {"-1h", "-1 hour"},
+ {"-2ms", "-2 milliseconds"},
+ {"-2s", "-2 seconds"},
+ {"-2m", "-2 minutes"},
+ {"-2h", "-2 hours"},
+ {"-10h", "-10 hours"},
+ {"-24h", "-1 day"},
+ {"-48h", "-2 days"},
+ {"-120h", "-5 days"},
+ {"-168h", "-1 week"},
+ {"-672h", "-4 weeks"},
+ {"-8760h", "-1 year"},
+ {"-1m0s", "-1 minute"},
+ {"-0m2s", "-2 seconds"},
+ {"-0m2m", "-2 minutes"},
+ {"-0m2m3h", "-3 hours 2 minutes"},
+ {"-0m2m34h", "-1 day 10 hours 2 minutes"},
+ {"-0ms", "-0 milliseconds"},
+ {"-0s", "-0 seconds"},
+ {"-0m", "-0 minutes"},
+ {"-0h", "-0 hours"},
+ }
+
+ for _, table := range testStrings {
+ d, err := ParseString(table.test)
+ if err != nil {
+ t.Errorf("%q", err)
+ }
+ result := d.String()
+ if result != table.expected {
+ t.Errorf("d.String() = %q. got %q, expected %q",
+ table.test, result, table.expected)
+ }
+ }
+}
+
+// TestInvalidDuration for invalid inputs.
+func TestInvalidDuration(t *testing.T) {
+ testStrings = []struct {
+ test string
+ expected string
+ }{
+ {"1", ""},
+ {"1d", ""},
+ {"1w", ""},
+ {"1wk", ""},
+ {"1y", ""},
+ {"", ""},
+ {"m1", ""},
+ {"1nmd", ""},
+ {"0", ""},
+ {"-0", ""},
+ }
+
+ for _, table := range testStrings {
+ _, err := ParseString(table.test)
+ if err == nil {
+ t.Errorf("ParseString(%q). got %q, expected %q",
+ table.test, err, table.expected)
+ }
+ }
+}