all: upd golibs, imp code

This commit is contained in:
Stanislav Chzhen 2023-07-11 19:56:29 +03:00
parent 0498960b00
commit 1e5385c33a
4 changed files with 23 additions and 25 deletions

2
go.mod
View File

@ -5,7 +5,7 @@ go 1.19
require ( require (
// TODO(a.garipov): Update to a tagged version when it's released. // TODO(a.garipov): Update to a tagged version when it's released.
github.com/AdguardTeam/dnsproxy v0.50.3-0.20230628054307-31e374065768 github.com/AdguardTeam/dnsproxy v0.50.3-0.20230628054307-31e374065768
github.com/AdguardTeam/golibs v0.13.3 github.com/AdguardTeam/golibs v0.13.4
github.com/AdguardTeam/urlfilter v0.16.1 github.com/AdguardTeam/urlfilter v0.16.1
github.com/NYTimes/gziphandler v1.1.1 github.com/NYTimes/gziphandler v1.1.1
github.com/ameshkov/dnscrypt/v2 v2.2.7 github.com/ameshkov/dnscrypt/v2 v2.2.7

4
go.sum
View File

@ -2,8 +2,8 @@ github.com/AdguardTeam/dnsproxy v0.50.3-0.20230628054307-31e374065768 h1:5Ia6wA+
github.com/AdguardTeam/dnsproxy v0.50.3-0.20230628054307-31e374065768/go.mod h1:CQhZTkqC8X0ID6glrtyaxgqRRdiYfn1gJulC1cZ5Dn8= github.com/AdguardTeam/dnsproxy v0.50.3-0.20230628054307-31e374065768/go.mod h1:CQhZTkqC8X0ID6glrtyaxgqRRdiYfn1gJulC1cZ5Dn8=
github.com/AdguardTeam/golibs v0.4.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= github.com/AdguardTeam/golibs v0.4.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4=
github.com/AdguardTeam/golibs v0.10.4/go.mod h1:rSfQRGHIdgfxriDDNgNJ7HmE5zRoURq8R+VdR81Zuzw= github.com/AdguardTeam/golibs v0.10.4/go.mod h1:rSfQRGHIdgfxriDDNgNJ7HmE5zRoURq8R+VdR81Zuzw=
github.com/AdguardTeam/golibs v0.13.3 h1:RT3QbzThtaLiFLkIUDS6/hlGEXrh0zYvdf4bd7UWpGo= github.com/AdguardTeam/golibs v0.13.4 h1:ACTwIR1pEENBijHcEWtiMbSh4wWQOlIHRxmUB8oBHf8=
github.com/AdguardTeam/golibs v0.13.3/go.mod h1:wkJ6EUsN4np/9Gp7+9QeooY9E2U2WCLJYAioLCzkHsI= github.com/AdguardTeam/golibs v0.13.4/go.mod h1:wkJ6EUsN4np/9Gp7+9QeooY9E2U2WCLJYAioLCzkHsI=
github.com/AdguardTeam/gomitmproxy v0.2.0/go.mod h1:Qdv0Mktnzer5zpdpi5rAwixNJzW2FN91LjKJCkVbYGU= github.com/AdguardTeam/gomitmproxy v0.2.0/go.mod h1:Qdv0Mktnzer5zpdpi5rAwixNJzW2FN91LjKJCkVbYGU=
github.com/AdguardTeam/urlfilter v0.16.1 h1:ZPi0rjqo8cQf2FVdzo6cqumNoHZx2KPXj2yZa1A5BBw= github.com/AdguardTeam/urlfilter v0.16.1 h1:ZPi0rjqo8cQf2FVdzo6cqumNoHZx2KPXj2yZa1A5BBw=
github.com/AdguardTeam/urlfilter v0.16.1/go.mod h1:46YZDOV1+qtdRDuhZKVPSSp7JWWes0KayqHrKAFBdEI= github.com/AdguardTeam/urlfilter v0.16.1/go.mod h1:46YZDOV1+qtdRDuhZKVPSSp7JWWes0KayqHrKAFBdEI=

View File

@ -54,28 +54,28 @@ func main() {
usage("") usage("")
} }
twosky, err := readTwoskyConf() conf, err := readTwoskyConfig()
check(err) check(err)
var client *twoskyClient var cli *twoskyClient
switch os.Args[1] { switch os.Args[1] {
case "summary": case "summary":
err = summary(twosky.Languages) err = summary(conf.Languages)
case "download": case "download":
client, err = twosky.toClient() cli, err = conf.toClient()
check(err) check(err)
err = client.download() err = cli.download()
case "unused": case "unused":
err = unused(twosky.LocalizableFiles[0]) err = unused(conf.LocalizableFiles[0])
case "upload": case "upload":
client, err = twosky.toClient() cli, err = conf.toClient()
check(err) check(err)
err = client.upload() err = cli.upload()
case "auto-add": case "auto-add":
err = autoAdd(twosky.LocalizableFiles[0]) err = autoAdd(conf.LocalizableFiles[0])
default: default:
usage("unknown command") usage("unknown command")
} }
@ -120,17 +120,17 @@ Commands:
os.Exit(0) os.Exit(0)
} }
// twoskyConf is the configuration structure for localization. // twoskyConfig is the configuration structure for localization.
type twoskyConf struct { type twoskyConfig struct {
Languages languages `json:"languages"` Languages languages `json:"languages"`
ProjectID string `json:"project_id"` ProjectID string `json:"project_id"`
BaseLangcode langCode `json:"base_locale"` BaseLangcode langCode `json:"base_locale"`
LocalizableFiles []string `json:"localizable_files"` LocalizableFiles []string `json:"localizable_files"`
} }
// readTwoskyConf returns configuration. // readTwoskyConfig returns twosky configuration.
func readTwoskyConf() (t *twoskyConf, err error) { func readTwoskyConfig() (t *twoskyConfig, err error) {
defer func() { err = errors.Annotate(err, "parsing twosky conf: %w") }() defer func() { err = errors.Annotate(err, "parsing twosky config: %w") }()
b, err := os.ReadFile(twoskyConfFile) b, err := os.ReadFile(twoskyConfFile)
if err != nil { if err != nil {
@ -138,7 +138,7 @@ func readTwoskyConf() (t *twoskyConf, err error) {
return nil, err return nil, err
} }
var tsc []twoskyConf var tsc []twoskyConfig
err = json.Unmarshal(b, &tsc) err = json.Unmarshal(b, &tsc)
if err != nil { if err != nil {
err = fmt.Errorf("unmarshalling %q: %w", twoskyConfFile, err) err = fmt.Errorf("unmarshalling %q: %w", twoskyConfFile, err)
@ -185,7 +185,7 @@ type twoskyClient struct {
// toClient reads values from environment variables or defaults, validates // toClient reads values from environment variables or defaults, validates
// them, and returns the twosky client. // them, and returns the twosky client.
func (t *twoskyConf) toClient() (conf *twoskyClient, err error) { func (t *twoskyConfig) toClient() (cli *twoskyClient, err error) {
defer func() { err = errors.Annotate(err, "filling config: %w") }() defer func() { err = errors.Annotate(err, "filling config: %w") }()
uriStr := os.Getenv("TWOSKY_URI") uriStr := os.Getenv("TWOSKY_URI")

View File

@ -13,6 +13,7 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp" "github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
"github.com/AdguardTeam/golibs/errors" "github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/httphdr" "github.com/AdguardTeam/golibs/httphdr"
"github.com/AdguardTeam/golibs/mapsutil"
) )
// upload base translation. // upload base translation.
@ -51,12 +52,9 @@ func prepareMultipartMsg(
w := multipart.NewWriter(buf) w := multipart.NewWriter(buf)
var fw io.Writer var fw io.Writer
// TODO(s.chzhen): Consider using OrderedRangeError from [agdmaps] package. err = mapsutil.OrderedRangeError(formData, w.WriteField)
for k, v := range formData { if err != nil {
err = w.WriteField(k, v) return nil, "", fmt.Errorf("writing field: %w", err)
if err != nil {
return nil, "", fmt.Errorf("writing field: %w", err)
}
} }
file, err := os.Open(basePath) file, err := os.Open(basePath)