chore: use gofumpt for code formatting
This commit is contained in:
@@ -15,7 +15,8 @@ import (
|
||||
// to the given selection. The filtered servers are deep copied so they
|
||||
// are safe for mutation by the caller.
|
||||
func (s *Storage) FilterServers(provider string, selection settings.ServerSelection) (
|
||||
servers []models.Server, err error) {
|
||||
servers []models.Server, err error,
|
||||
) {
|
||||
if provider == providers.Custom {
|
||||
return nil, nil
|
||||
}
|
||||
@@ -47,7 +48,8 @@ func (s *Storage) FilterServers(provider string, selection settings.ServerSelect
|
||||
}
|
||||
|
||||
func filterServer(server models.Server,
|
||||
selection settings.ServerSelection) (filtered bool) {
|
||||
selection settings.ServerSelection,
|
||||
) (filtered bool) {
|
||||
// Note each condition is split to make sure
|
||||
// we have full testing coverage.
|
||||
if server.VPN != selection.VPN {
|
||||
@@ -151,7 +153,8 @@ func filterAnyByPossibilities(values, possibilities []string) (filtered bool) {
|
||||
}
|
||||
|
||||
func filterByProtocol(selection settings.ServerSelection,
|
||||
serverTCP, serverUDP bool) (filtered bool) {
|
||||
serverTCP, serverUDP bool,
|
||||
) (filtered bool) {
|
||||
switch selection.VPN {
|
||||
case vpn.Wireguard:
|
||||
return !serverUDP
|
||||
|
||||
@@ -21,7 +21,7 @@ func (s *Storage) FlushToFile(path string) error {
|
||||
// flushToFile flushes the merged servers data to the file
|
||||
// specified by path, as indented JSON. It is not thread-safe.
|
||||
func (s *Storage) flushToFile(path string) error {
|
||||
const permission = 0644
|
||||
const permission = 0o644
|
||||
dirPath := filepath.Dir(path)
|
||||
if err := os.MkdirAll(dirPath, permission); err != nil {
|
||||
return err
|
||||
|
||||
@@ -27,7 +27,8 @@ func (s *Storage) mergeServers(hardcoded, persisted models.AllServers) models.Al
|
||||
}
|
||||
|
||||
func (s *Storage) mergeProviderServers(provider string,
|
||||
hardcoded, persisted models.Servers) (merged models.Servers) {
|
||||
hardcoded, persisted models.Servers,
|
||||
) (merged models.Servers) {
|
||||
if persisted.Timestamp > hardcoded.Timestamp {
|
||||
diff := time.Unix(persisted.Timestamp, 0).Sub(time.Unix(hardcoded.Timestamp, 0))
|
||||
if diff < 0 {
|
||||
|
||||
@@ -16,7 +16,8 @@ import (
|
||||
// It only reads servers that have the same version as the hardcoded servers version
|
||||
// to avoid JSON decoding errors.
|
||||
func (s *Storage) readFromFile(filepath string, hardcodedVersions map[string]uint16) (
|
||||
servers models.AllServers, err error) {
|
||||
servers models.AllServers, err error,
|
||||
) {
|
||||
file, err := os.Open(filepath)
|
||||
if os.IsNotExist(err) {
|
||||
return servers, nil
|
||||
@@ -37,7 +38,8 @@ func (s *Storage) readFromFile(filepath string, hardcodedVersions map[string]uin
|
||||
}
|
||||
|
||||
func (s *Storage) extractServersFromBytes(b []byte, hardcodedVersions map[string]uint16) (
|
||||
servers models.AllServers, err error) {
|
||||
servers models.AllServers, err error,
|
||||
) {
|
||||
rawMessages := make(map[string]json.RawMessage)
|
||||
if err := json.Unmarshal(b, &rawMessages); err != nil {
|
||||
return servers, fmt.Errorf("decoding servers: %w", err)
|
||||
@@ -80,7 +82,8 @@ func (s *Storage) extractServersFromBytes(b []byte, hardcodedVersions map[string
|
||||
|
||||
func (s *Storage) readServers(provider string, hardcodedVersion uint16,
|
||||
rawMessage json.RawMessage, titleCaser cases.Caser) (servers models.Servers,
|
||||
versionsMatch bool, err error) {
|
||||
versionsMatch bool, err error,
|
||||
) {
|
||||
provider = titleCaser.String(provider)
|
||||
|
||||
var versionObject struct {
|
||||
|
||||
Reference in New Issue
Block a user