Maint: use qdm12/gosplash
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
package constants
|
||||
|
||||
const (
|
||||
// Announcement is a message announcement.
|
||||
Announcement = "New Docker image qmcgaw/gluetun"
|
||||
// AnnouncementExpiration is the expiration date of the announcement in format yyyy-mm-dd.
|
||||
AnnouncementExpiration = "2021-01-20"
|
||||
)
|
||||
|
||||
const (
|
||||
// IssueLink is the link for users to use to create issues.
|
||||
IssueLink = "https://github.com/qdm12/gluetun/issues/new"
|
||||
)
|
||||
@@ -1,17 +0,0 @@
|
||||
package constants
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_AnnouncementExpiration(t *testing.T) {
|
||||
t.Parallel()
|
||||
if len(AnnouncementExpiration) == 0 {
|
||||
return
|
||||
}
|
||||
_, err := time.Parse("2006-01-02", AnnouncementExpiration)
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package logging
|
||||
package format
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func FormatDuration(duration time.Duration) string {
|
||||
func Duration(duration time.Duration) string {
|
||||
switch {
|
||||
case duration < time.Minute:
|
||||
seconds := int(duration.Round(time.Second).Seconds())
|
||||
@@ -1,4 +1,4 @@
|
||||
package logging
|
||||
package format
|
||||
|
||||
import (
|
||||
"testing"
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_FormatDuration(t *testing.T) {
|
||||
func Test_Duration(t *testing.T) {
|
||||
t.Parallel()
|
||||
testCases := map[string]struct {
|
||||
duration time.Duration
|
||||
@@ -57,7 +57,7 @@ func Test_FormatDuration(t *testing.T) {
|
||||
testCase := testCase
|
||||
t.Run(name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
s := FormatDuration(testCase.duration)
|
||||
s := Duration(testCase.duration)
|
||||
assert.Equal(t, testCase.s, s)
|
||||
})
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
// Package logging defines helper functions for logging.
|
||||
package logging
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
// Splash returns the welcome spash message.
|
||||
func Splash(buildInfo models.BuildInformation) string {
|
||||
lines := title()
|
||||
lines = append(lines, "")
|
||||
lines = append(lines, fmt.Sprintf("Running version %s built on %s (commit %s)",
|
||||
buildInfo.Version, buildInfo.Created, buildInfo.Commit))
|
||||
lines = append(lines, "")
|
||||
lines = append(lines, announcement()...)
|
||||
lines = append(lines, "")
|
||||
lines = append(lines, links()...)
|
||||
return strings.Join(lines, "\n")
|
||||
}
|
||||
|
||||
func title() []string {
|
||||
return []string{
|
||||
"=========================================",
|
||||
"================ Gluetun ================",
|
||||
"=========================================",
|
||||
"==== A mix of OpenVPN, DNS over TLS, ====",
|
||||
"======= Shadowsocks and HTTP proxy ======",
|
||||
"========= all glued up with Go ==========",
|
||||
"=========================================",
|
||||
"=========== For tunneling to ============",
|
||||
"======== your favorite VPN server =======",
|
||||
"=========================================",
|
||||
"=== Made with ❤️ by github.com/qdm12 ====",
|
||||
"=========================================",
|
||||
}
|
||||
}
|
||||
|
||||
func announcement() []string {
|
||||
if len(constants.Announcement) == 0 {
|
||||
return nil
|
||||
}
|
||||
expirationDate, _ := time.Parse("2006-01-02", constants.AnnouncementExpiration) // error covered by a unit test
|
||||
if time.Now().After(expirationDate) {
|
||||
return nil
|
||||
}
|
||||
return []string{"📣" + constants.Announcement}
|
||||
}
|
||||
|
||||
func links() []string {
|
||||
return []string{
|
||||
"🔧 Need help? " + constants.IssueLink,
|
||||
"💻 Email? quentin.mcgaw@gmail.com",
|
||||
"☕ Slack? Join from the Slack button on Github",
|
||||
"💰 Help me? https://github.com/sponsors/qdm12",
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
|
||||
"github.com/qdm12/gluetun/internal/constants"
|
||||
"github.com/qdm12/gluetun/internal/firewall"
|
||||
format "github.com/qdm12/gluetun/internal/logging"
|
||||
"github.com/qdm12/gluetun/internal/format"
|
||||
"github.com/qdm12/golibs/logging"
|
||||
"github.com/qdm12/golibs/os"
|
||||
)
|
||||
@@ -61,7 +61,7 @@ func (p *PIA) PortForward(ctx context.Context, client *http.Client,
|
||||
logger.Warn("Forwarded port data expired on " +
|
||||
data.Expiration.Format(time.RFC1123) + ", getting another one")
|
||||
} else {
|
||||
logger.Info("Forwarded port data expires in " + format.FormatDuration(durationToExpiration))
|
||||
logger.Info("Forwarded port data expires in " + format.Duration(durationToExpiration))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ func (p *PIA) PortForward(ctx context.Context, client *http.Client,
|
||||
durationToExpiration = data.Expiration.Sub(p.timeNow())
|
||||
}
|
||||
logger.Info("Port forwarded is " + strconv.Itoa(int(data.Port)) +
|
||||
" expiring in " + format.FormatDuration(durationToExpiration))
|
||||
" expiring in " + format.Duration(durationToExpiration))
|
||||
|
||||
// First time binding
|
||||
tryUntilSuccessful(ctx, logger, func() error {
|
||||
@@ -137,7 +137,7 @@ func (p *PIA) PortForward(ctx context.Context, client *http.Client,
|
||||
}
|
||||
durationToExpiration := data.Expiration.Sub(p.timeNow())
|
||||
logger.Info("Port forwarded is " + strconv.Itoa(int(data.Port)) +
|
||||
" expiring in " + format.FormatDuration(durationToExpiration))
|
||||
" expiring in " + format.Duration(durationToExpiration))
|
||||
if err := fw.RemoveAllowedPort(ctx, oldPort); err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/qdm12/gluetun/internal/logging"
|
||||
"github.com/qdm12/gluetun/internal/format"
|
||||
"github.com/qdm12/gluetun/internal/models"
|
||||
)
|
||||
|
||||
@@ -38,7 +38,7 @@ func GetMessage(ctx context.Context, buildInfo models.BuildInformation,
|
||||
if tagName == buildInfo.Version {
|
||||
return fmt.Sprintf("You are running the latest release %s", buildInfo.Version), nil
|
||||
}
|
||||
timeSinceRelease := logging.FormatDuration(time.Since(releaseTime))
|
||||
timeSinceRelease := format.Duration(time.Since(releaseTime))
|
||||
return fmt.Sprintf("There is a new release %s (%s) created %s ago",
|
||||
tagName, name, timeSinceRelease),
|
||||
nil
|
||||
|
||||
Reference in New Issue
Block a user