Maint: use qdm12/gosplash
This commit is contained in:
@@ -22,7 +22,6 @@ import (
|
|||||||
"github.com/qdm12/gluetun/internal/firewall"
|
"github.com/qdm12/gluetun/internal/firewall"
|
||||||
"github.com/qdm12/gluetun/internal/healthcheck"
|
"github.com/qdm12/gluetun/internal/healthcheck"
|
||||||
"github.com/qdm12/gluetun/internal/httpproxy"
|
"github.com/qdm12/gluetun/internal/httpproxy"
|
||||||
gluetunLogging "github.com/qdm12/gluetun/internal/logging"
|
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
"github.com/qdm12/gluetun/internal/openvpn"
|
"github.com/qdm12/gluetun/internal/openvpn"
|
||||||
"github.com/qdm12/gluetun/internal/publicip"
|
"github.com/qdm12/gluetun/internal/publicip"
|
||||||
@@ -38,6 +37,7 @@ import (
|
|||||||
"github.com/qdm12/golibs/os/user"
|
"github.com/qdm12/golibs/os/user"
|
||||||
"github.com/qdm12/golibs/params"
|
"github.com/qdm12/golibs/params"
|
||||||
"github.com/qdm12/goshutdown"
|
"github.com/qdm12/goshutdown"
|
||||||
|
"github.com/qdm12/gosplash"
|
||||||
"github.com/qdm12/updated/pkg/dnscrypto"
|
"github.com/qdm12/updated/pkg/dnscrypto"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -147,7 +147,26 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
|||||||
logger.NewChild(logging.Settings{Prefix: "firewall: "}),
|
logger.NewChild(logging.Settings{Prefix: "firewall: "}),
|
||||||
routingConf, os.OpenFile)
|
routingConf, os.OpenFile)
|
||||||
|
|
||||||
fmt.Println(gluetunLogging.Splash(buildInfo))
|
announcementExp, err := time.Parse(time.RFC3339, "2021-07-22T00:00:00Z")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
splashSettings := gosplash.Settings{
|
||||||
|
User: "qdm12",
|
||||||
|
Repository: "gluetun",
|
||||||
|
Emails: []string{"quentin.mcgaw@gmail.com"},
|
||||||
|
Version: buildInfo.Version,
|
||||||
|
Commit: buildInfo.Commit,
|
||||||
|
BuildDate: buildInfo.Created,
|
||||||
|
Announcement: "",
|
||||||
|
AnnounceExp: announcementExp,
|
||||||
|
// Sponsor information
|
||||||
|
PaypalUser: "qmcgaw",
|
||||||
|
GithubSponsor: "qdm12",
|
||||||
|
}
|
||||||
|
for _, line := range gosplash.MakeLines(splashSettings) {
|
||||||
|
fmt.Println(line)
|
||||||
|
}
|
||||||
|
|
||||||
if err := printVersions(ctx, logger, []printVersionElement{
|
if err := printVersions(ctx, logger, []printVersionElement{
|
||||||
{name: "Alpine", getVersion: alpineConf.Version},
|
{name: "Alpine", getVersion: alpineConf.Version},
|
||||||
@@ -160,7 +179,7 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
|||||||
}
|
}
|
||||||
|
|
||||||
var allSettings configuration.Settings
|
var allSettings configuration.Settings
|
||||||
err := allSettings.Read(env, os,
|
err = allSettings.Read(env, os,
|
||||||
logger.NewChild(logging.Settings{Prefix: "configuration: "}))
|
logger.NewChild(logging.Settings{Prefix: "configuration: "}))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
1
go.mod
1
go.mod
@@ -8,6 +8,7 @@ require (
|
|||||||
github.com/qdm12/dns v1.9.0
|
github.com/qdm12/dns v1.9.0
|
||||||
github.com/qdm12/golibs v0.0.0-20210716185557-66793f4ddd80
|
github.com/qdm12/golibs v0.0.0-20210716185557-66793f4ddd80
|
||||||
github.com/qdm12/goshutdown v0.1.0
|
github.com/qdm12/goshutdown v0.1.0
|
||||||
|
github.com/qdm12/gosplash v0.1.0
|
||||||
github.com/qdm12/ss-server v0.2.0
|
github.com/qdm12/ss-server v0.2.0
|
||||||
github.com/qdm12/updated v0.0.0-20210603204757-205acfe6937e
|
github.com/qdm12/updated v0.0.0-20210603204757-205acfe6937e
|
||||||
github.com/stretchr/testify v1.7.0
|
github.com/stretchr/testify v1.7.0
|
||||||
|
|||||||
2
go.sum
2
go.sum
@@ -70,6 +70,8 @@ github.com/qdm12/golibs v0.0.0-20210716185557-66793f4ddd80 h1:rvH2MSs8RXEfuXivzo
|
|||||||
github.com/qdm12/golibs v0.0.0-20210716185557-66793f4ddd80/go.mod h1:15RBzkun0i8XB7ADIoLJWp9ITRgsz3LroEI2FiOXLRg=
|
github.com/qdm12/golibs v0.0.0-20210716185557-66793f4ddd80/go.mod h1:15RBzkun0i8XB7ADIoLJWp9ITRgsz3LroEI2FiOXLRg=
|
||||||
github.com/qdm12/goshutdown v0.1.0 h1:lmwnygdXtnr2pa6VqfR/bm8077/BnBef1+7CP96B7Sw=
|
github.com/qdm12/goshutdown v0.1.0 h1:lmwnygdXtnr2pa6VqfR/bm8077/BnBef1+7CP96B7Sw=
|
||||||
github.com/qdm12/goshutdown v0.1.0/go.mod h1:/LP3MWLqI+wGH/ijfaUG+RHzBbKXIiVKnrg5vXOCf6Q=
|
github.com/qdm12/goshutdown v0.1.0/go.mod h1:/LP3MWLqI+wGH/ijfaUG+RHzBbKXIiVKnrg5vXOCf6Q=
|
||||||
|
github.com/qdm12/gosplash v0.1.0 h1:Sfl+zIjFZFP7b0iqf2l5UkmEY97XBnaKkH3FNY6Gf7g=
|
||||||
|
github.com/qdm12/gosplash v0.1.0/go.mod h1:+A3fWW4/rUeDXhY3ieBzwghKdnIPFJgD8K3qQkenJlw=
|
||||||
github.com/qdm12/ss-server v0.2.0 h1:+togLzeeLAJ68MD1JqOWvYi9rl9t/fx1Qh7wKzZhY1g=
|
github.com/qdm12/ss-server v0.2.0 h1:+togLzeeLAJ68MD1JqOWvYi9rl9t/fx1Qh7wKzZhY1g=
|
||||||
github.com/qdm12/ss-server v0.2.0/go.mod h1:+1bWO1EfWNvsGM5Cuep6vneChK2OHniqtAsED9Fh1y0=
|
github.com/qdm12/ss-server v0.2.0/go.mod h1:+1bWO1EfWNvsGM5Cuep6vneChK2OHniqtAsED9Fh1y0=
|
||||||
github.com/qdm12/updated v0.0.0-20210603204757-205acfe6937e h1:4q+uFLawkaQRq3yARYLsjJPZd2wYwxn4g6G/5v0xW1g=
|
github.com/qdm12/updated v0.0.0-20210603204757-205acfe6937e h1:4q+uFLawkaQRq3yARYLsjJPZd2wYwxn4g6G/5v0xW1g=
|
||||||
|
|||||||
@@ -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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func FormatDuration(duration time.Duration) string {
|
func Duration(duration time.Duration) string {
|
||||||
switch {
|
switch {
|
||||||
case duration < time.Minute:
|
case duration < time.Minute:
|
||||||
seconds := int(duration.Round(time.Second).Seconds())
|
seconds := int(duration.Round(time.Second).Seconds())
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package logging
|
package format
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_FormatDuration(t *testing.T) {
|
func Test_Duration(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
testCases := map[string]struct {
|
testCases := map[string]struct {
|
||||||
duration time.Duration
|
duration time.Duration
|
||||||
@@ -57,7 +57,7 @@ func Test_FormatDuration(t *testing.T) {
|
|||||||
testCase := testCase
|
testCase := testCase
|
||||||
t.Run(name, func(t *testing.T) {
|
t.Run(name, func(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
s := FormatDuration(testCase.duration)
|
s := Duration(testCase.duration)
|
||||||
assert.Equal(t, testCase.s, s)
|
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/constants"
|
||||||
"github.com/qdm12/gluetun/internal/firewall"
|
"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/logging"
|
||||||
"github.com/qdm12/golibs/os"
|
"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 " +
|
logger.Warn("Forwarded port data expired on " +
|
||||||
data.Expiration.Format(time.RFC1123) + ", getting another one")
|
data.Expiration.Format(time.RFC1123) + ", getting another one")
|
||||||
} else {
|
} 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())
|
durationToExpiration = data.Expiration.Sub(p.timeNow())
|
||||||
}
|
}
|
||||||
logger.Info("Port forwarded is " + strconv.Itoa(int(data.Port)) +
|
logger.Info("Port forwarded is " + strconv.Itoa(int(data.Port)) +
|
||||||
" expiring in " + format.FormatDuration(durationToExpiration))
|
" expiring in " + format.Duration(durationToExpiration))
|
||||||
|
|
||||||
// First time binding
|
// First time binding
|
||||||
tryUntilSuccessful(ctx, logger, func() error {
|
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())
|
durationToExpiration := data.Expiration.Sub(p.timeNow())
|
||||||
logger.Info("Port forwarded is " + strconv.Itoa(int(data.Port)) +
|
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 {
|
if err := fw.RemoveAllowedPort(ctx, oldPort); err != nil {
|
||||||
logger.Error(err)
|
logger.Error(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/logging"
|
"github.com/qdm12/gluetun/internal/format"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ func GetMessage(ctx context.Context, buildInfo models.BuildInformation,
|
|||||||
if tagName == buildInfo.Version {
|
if tagName == buildInfo.Version {
|
||||||
return fmt.Sprintf("You are running the latest release %s", buildInfo.Version), nil
|
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",
|
return fmt.Sprintf("There is a new release %s (%s) created %s ago",
|
||||||
tagName, name, timeSinceRelease),
|
tagName, name, timeSinceRelease),
|
||||||
nil
|
nil
|
||||||
|
|||||||
Reference in New Issue
Block a user