Pull request 2302: upd-all

Squashed commit of the following:

commit f920006277f39b74c803139af2a9039aa45effae
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Fri Nov 8 16:14:41 2024 +0300

    all: fix pre-commit; upd dnsproxy

commit 391f79b244348c6075f5ba0fccfb8882791bf3f1
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Nov 7 18:53:28 2024 +0300

    scripts: imp install

commit 35324db80b591831c32b7ea45930eefee82a6320
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Nov 7 18:20:23 2024 +0300

    all: imp docs, scripts

commit d2724cfaefdb8659efbdb5bf181a28721a909f07
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Nov 7 17:26:23 2024 +0300

    all: upd go, deps, tools, scripts
This commit is contained in:
Ainar Garipov
2024-11-08 17:18:16 +03:00
parent 6673bb175a
commit ac5a96fada
40 changed files with 834 additions and 916 deletions

View File

@@ -16,6 +16,7 @@ import (
"text/template"
"time"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/logutil/slogutil"
)
@@ -30,14 +31,13 @@ func main() {
// Validate the URL.
_, err := url.Parse(urlStr)
check(err)
errors.Check(err)
c := &http.Client{
Timeout: 10 * time.Second,
}
resp, err := c.Get(urlStr)
check(err)
resp := errors.Must(c.Get(urlStr))
defer slogutil.CloseAndLog(ctx, l, resp.Body, slog.LevelError)
if resp.StatusCode != http.StatusOK {
@@ -46,7 +46,7 @@ func main() {
hlSvcs := &hlServices{}
err = json.NewDecoder(resp.Body).Decode(hlSvcs)
check(err)
errors.Check(err)
// Sort all services and rules to make the output more predictable.
slices.SortStableFunc(hlSvcs.BlockedServices, func(a, b *hlServicesService) (res int) {
@@ -59,20 +59,20 @@ func main() {
// Use another set of delimiters to prevent them interfering with the Go
// code.
tmpl, err := template.New("main").Delims("<%", "%>").Funcs(template.FuncMap{
"isnotlast": func(idx, sliceLen int) (ok bool) { return idx != sliceLen-1 },
"isnotlast": func(idx, sliceLen int) (ok bool) {
return idx != sliceLen-1
},
}).Parse(tmplStr)
check(err)
errors.Check(err)
f, err := os.OpenFile(
f := errors.Must(os.OpenFile(
"./internal/filtering/servicelist.go",
os.O_CREATE|os.O_TRUNC|os.O_WRONLY,
0o644,
)
check(err)
))
defer slogutil.CloseAndLog(ctx, l, f, slog.LevelError)
err = tmpl.Execute(f, hlSvcs)
check(err)
errors.Check(tmpl.Execute(f, hlSvcs))
}
// tmplStr is the template for the Go source file with the services.
@@ -100,13 +100,6 @@ var blockedServices = []blockedService{<% $l := len .BlockedServices %>
}<% if isnotlast $i $l %>, <% end %><% end %>}
`
// check is a simple error-checking helper for scripts.
func check(err error) {
if err != nil {
panic(err)
}
}
// hlServices is the JSON structure for the Hostlists Registry blocked service
// index.
type hlServices struct {