Skip to content

Commit 6aecc26

Browse files
committed
cmd/ursrv: Merge ursrv and uraggregate as subcommands
1 parent c55b205 commit 6aecc26

16 files changed

+1193
-1177
lines changed

build.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,17 @@ var targets = map[string]target{
214214
binaryName: "stupgrades",
215215
},
216216
"stcrashreceiver": {
217-
name: "stupgrastcrashreceiverdes",
217+
name: "stcrashreceiver",
218218
description: "Syncthing Crash Server",
219219
buildPkgs: []string{"github.com/syncthing/syncthing/cmd/stcrashreceiver"},
220220
binaryName: "stcrashreceiver",
221221
},
222+
"ursrv": {
223+
name: "ursrv",
224+
description: "Syncthing Usage Reporting Server",
225+
buildPkgs: []string{"github.com/syncthing/syncthing/cmd/ursrv"},
226+
binaryName: "ursrv",
227+
},
222228
}
223229

224230
func initTargets() {
Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,33 @@
44
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
55
// You can obtain one at https://mozilla.org/MPL/2.0/.
66

7-
package main
7+
package aggregate
88

99
import (
1010
"database/sql"
11+
"fmt"
1112
"log"
1213
"os"
1314
"time"
1415

1516
_ "github.com/lib/pq"
1617
)
1718

18-
var dbConn = getEnvDefault("UR_DB_URL", "postgres://user:password@localhost/ur?sslmode=disable")
19-
20-
func getEnvDefault(key, def string) string {
21-
if val := os.Getenv(key); val != "" {
22-
return val
23-
}
24-
return def
19+
type CLI struct {
20+
DBConn string `env:"UR_DB_URL" default:"postgres://user:password@localhost/ur?sslmode=disable"`
2521
}
2622

27-
func main() {
23+
func (cli *CLI) Run() error {
2824
log.SetFlags(log.Ltime | log.Ldate)
2925
log.SetOutput(os.Stdout)
3026

31-
db, err := sql.Open("postgres", dbConn)
27+
db, err := sql.Open("postgres", cli.DBConn)
3228
if err != nil {
33-
log.Fatalln("database:", err)
29+
return fmt.Errorf("database: %w", err)
3430
}
3531
err = setupDB(db)
3632
if err != nil {
37-
log.Fatalln("database:", err)
33+
return fmt.Errorf("database: %w", err)
3834
}
3935

4036
for {

0 commit comments

Comments
 (0)