cmd/ursrv: Merge ursrv and uraggregate as subcommands

This commit is contained in:
Jakob Borg 2023-07-10 09:00:57 +02:00
parent c55b205a0b
commit 6aecc2622c
16 changed files with 1193 additions and 1177 deletions

View File

@ -214,11 +214,17 @@ var targets = map[string]target{
binaryName: "stupgrades", binaryName: "stupgrades",
}, },
"stcrashreceiver": { "stcrashreceiver": {
name: "stupgrastcrashreceiverdes", name: "stcrashreceiver",
description: "Syncthing Crash Server", description: "Syncthing Crash Server",
buildPkgs: []string{"github.com/syncthing/syncthing/cmd/stcrashreceiver"}, buildPkgs: []string{"github.com/syncthing/syncthing/cmd/stcrashreceiver"},
binaryName: "stcrashreceiver", binaryName: "stcrashreceiver",
}, },
"ursrv": {
name: "ursrv",
description: "Syncthing Usage Reporting Server",
buildPkgs: []string{"github.com/syncthing/syncthing/cmd/ursrv"},
binaryName: "ursrv",
},
} }
func initTargets() { func initTargets() {

View File

@ -4,10 +4,11 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this file, // License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/. // You can obtain one at https://mozilla.org/MPL/2.0/.
package main package aggregate
import ( import (
"database/sql" "database/sql"
"fmt"
"log" "log"
"os" "os"
"time" "time"
@ -15,26 +16,21 @@ import (
_ "github.com/lib/pq" _ "github.com/lib/pq"
) )
var dbConn = getEnvDefault("UR_DB_URL", "postgres://user:password@localhost/ur?sslmode=disable") type CLI struct {
DBConn string `env:"UR_DB_URL" default:"postgres://user:password@localhost/ur?sslmode=disable"`
func getEnvDefault(key, def string) string {
if val := os.Getenv(key); val != "" {
return val
}
return def
} }
func main() { func (cli *CLI) Run() error {
log.SetFlags(log.Ltime | log.Ldate) log.SetFlags(log.Ltime | log.Ldate)
log.SetOutput(os.Stdout) log.SetOutput(os.Stdout)
db, err := sql.Open("postgres", dbConn) db, err := sql.Open("postgres", cli.DBConn)
if err != nil { if err != nil {
log.Fatalln("database:", err) return fmt.Errorf("database: %w", err)
} }
err = setupDB(db) err = setupDB(db)
if err != nil { if err != nil {
log.Fatalln("database:", err) return fmt.Errorf("database: %w", err)
} }
for { for {

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this file, // License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/. // You can obtain one at https://mozilla.org/MPL/2.0/.
package main package serve
import ( import (
"regexp" "regexp"

View File

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this file, // License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/. // You can obtain one at https://mozilla.org/MPL/2.0/.
package main package serve
import "testing" import "testing"

View File

@ -4,7 +4,7 @@
// License, v. 2.0. If a copy of the MPL was not distributed with this file, // License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/. // You can obtain one at https://mozilla.org/MPL/2.0/.
package main package serve
import ( import (
"bytes" "bytes"

1167
cmd/ursrv/serve/serve.go Normal file

File diff suppressed because it is too large Load Diff

View File

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

Before

Width:  |  Height:  |  Size: 61 KiB

After

Width:  |  Height:  |  Size: 61 KiB