• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

foomo / contentserver / 19674387362

25 Nov 2025 03:12PM UTC coverage: 41.746% (+0.08%) from 41.662%
19674387362

Pull #67

github

web-flow
Merge cabb48f16 into e7e5d09f5
Pull Request #67: Add Multi-Cloud Blob Storage Support (AWS S3, Azure, GCS)

166 of 366 new or added lines in 11 files covered. (45.36%)

3 existing lines in 2 files now uncovered.

875 of 2096 relevant lines covered (41.75%)

22387.85 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/cmd/socket.go
1
package cmd
2

3
import (
4
        "context"
5
        "fmt"
6
        "net"
7

8
        "github.com/foomo/contentserver/pkg/handler"
9
        "github.com/foomo/contentserver/pkg/repo"
10
        "github.com/foomo/keel/log"
11
        keelhttp "github.com/foomo/keel/net/http"
12
        "github.com/spf13/cobra"
13
        "github.com/spf13/viper"
14
        "go.uber.org/zap"
15
)
16

17
func NewSocketCommand() *cobra.Command {
×
18
        v := viper.New()
×
19
        cmd := &cobra.Command{
×
20
                Use:   "socket <url>",
×
21
                Short: "Start socket server",
×
22
                Args:  cobra.ExactArgs(1),
×
23
                ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
×
24
                        var comps []string
×
25
                        if len(args) == 0 {
×
26
                                comps = cobra.AppendActiveHelp(comps, "You must specify the URL for the repository you are adding")
×
27
                        } else {
×
28
                                comps = cobra.AppendActiveHelp(comps, "This command does not take any more arguments")
×
29
                        }
×
30
                        return comps, cobra.ShellCompDirectiveNoFileComp
×
31
                },
32
                RunE: func(cmd *cobra.Command, args []string) error {
×
33
                        l := log.Logger()
×
34

×
NEW
35
                        // Create storage based on configuration
×
NEW
36
                        storage, err := createStorage(cmd.Context(), v, l)
×
NEW
37
                        if err != nil {
×
NEW
38
                                return fmt.Errorf("failed to create storage: %w", err)
×
NEW
39
                        }
×
40

NEW
41
                        history, err := repo.NewHistory(l,
×
NEW
42
                                repo.HistoryWithStorage(storage),
×
NEW
43
                                repo.HistoryWithHistoryDir(historyDirFlag(v)),
×
NEW
44
                                repo.HistoryWithHistoryLimit(historyLimitFlag(v)),
×
NEW
45
                        )
×
NEW
46
                        if err != nil {
×
NEW
47
                                return fmt.Errorf("failed to create history: %w", err)
×
NEW
48
                        }
×
NEW
49
                        defer func() {
×
NEW
50
                                if closeErr := history.Close(); closeErr != nil {
×
NEW
51
                                        l.Error("failed to close history storage", zap.Error(closeErr))
×
NEW
52
                                }
×
53
                        }()
54

55
                        r := repo.New(l,
×
56
                                args[0],
×
NEW
57
                                history,
×
58
                                repo.WithHTTPClient(
×
59
                                        keelhttp.NewHTTPClient(
×
NEW
60
                                                keelhttp.HTTPClientWithTimeout(repositoryTimeoutFlag(v)),
×
61
                                                keelhttp.HTTPClientWithTelemetry(),
×
62
                                        ),
×
63
                                ),
×
64
                                repo.WithPoll(pollFlag(v)),
×
65
                                repo.WithPollInterval(pollIntevalFlag(v)),
×
66
                        )
×
67

×
68
                        // create socket server
×
69
                        handle := handler.NewSocket(l, r)
×
70

×
71
                        // listen on socket
×
NEW
72
                        var lc net.ListenConfig
×
NEW
73
                        ln, err := lc.Listen(cmd.Context(), "tcp", addressFlag(v))
×
74
                        if err != nil {
×
75
                                return err
×
76
                        }
×
77

78
                        // start repo
79
                        up := make(chan bool, 1)
×
80
                        r.OnLoaded(func() {
×
81
                                up <- true
×
82
                        })
×
83
                        go r.Start(context.Background()) //nolint:errcheck
×
84
                        <-up
×
85

×
86
                        l.Info("started listening", zap.String("address", addressFlag(v)))
×
87

×
88
                        for {
×
89
                                // this blocks until connection or error
×
90
                                conn, err := ln.Accept()
×
91
                                if err != nil {
×
92
                                        l.Error("runSocketServer: could not accept connection", zap.Error(err))
×
93
                                        continue
×
94
                                }
95

96
                                // a goroutine handles conn so that the loop can accept other connections
97
                                go func() {
×
98
                                        l.Debug("accepted connection", zap.String("source", conn.RemoteAddr().String()))
×
99
                                        handle.Serve(conn)
×
100
                                        if err := conn.Close(); err != nil {
×
101
                                                l.Warn("failed to close connection", zap.Error(err))
×
102
                                        }
×
103
                                }()
104
                        }
105
                },
106
        }
107

108
        flags := cmd.Flags()
×
109
        addAddressFlag(flags, v)
×
110
        addPollFlag(flags, v)
×
111
        addPollIntervalFlag(flags, v)
×
112
        addHistoryDirFlag(flags, v)
×
113
        addHistoryLimitFlag(flags, v)
×
NEW
114
        addStorageTypeFlag(flags, v)
×
NEW
115
        addStorageBlobBucketFlag(flags, v)
×
NEW
116
        addStorageBlobPrefixFlag(flags, v)
×
NEW
117
        addRepositoryTimeoutFlag(flags, v)
×
118

×
119
        return cmd
×
120
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc