Skip to content

Commit

Permalink
interface{} → any
Browse files Browse the repository at this point in the history
  • Loading branch information
arp242 committed Jan 17, 2023
1 parent 6a7c988 commit 5cbc382
Show file tree
Hide file tree
Showing 30 changed files with 86 additions and 86 deletions.
2 changes: 1 addition & 1 deletion acme/acme.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func Make(ctx context.Context, domain string) error {
var resolveSelf singleflight.Group

func validForwarding(ctx context.Context, domain string) bool {
x, _, _ := resolveSelf.Do("resolveSelf", func() (interface{}, error) {
x, _, _ := resolveSelf.Do("resolveSelf", func() (any, error) {
// For "serve" we don't know what the end destination will be, so always
// check.
if !goatcounter.Config(ctx).GoatcounterCom {
Expand Down
10 changes: 5 additions & 5 deletions db/migrate/gomig/2021-12-08-1-set-chart-text.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@ func KeepAsText(ctx context.Context) error {
}

set := func(settings []byte) (string, error) {
var s map[string]interface{}
var s map[string]any
err := json.Unmarshal(settings, &s)
if err != nil {
return "", err
}

wid := s["widgets"].([]interface{})
wid := s["widgets"].([]any)
for i, w := range wid {
ww := w.(map[string]interface{})
ww := w.(map[string]any)
if ww["n"].(string) == "pages" {
s, ok := ww["s"].(map[string]interface{})
s, ok := ww["s"].(map[string]any)
if !ok {
s = make(map[string]interface{})
s = make(map[string]any)
}
s["style"] = "text"
ww["s"] = s
Expand Down
4 changes: 2 additions & 2 deletions handlers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func (h api) test(w http.ResponseWriter, r *http.Request) error {

if args.Context {
info, _ := zdb.Info(r.Context())
return zhttp.JSON(w, map[string]interface{}{
return zhttp.JSON(w, map[string]any{
"site_id": Site(r.Context()).ID,
"serve": !goatcounter.Config(r.Context()).GoatcounterCom,
"db": info.Version,
Expand Down Expand Up @@ -602,7 +602,7 @@ func (h api) count(w http.ResponseWriter, r *http.Request) error {
}
if len(errs) > 0 {
w.WriteHeader(400)
return zhttp.JSON(w, map[string]interface{}{
return zhttp.JSON(w, map[string]any{
"errors": errs,
})
}
Expand Down
8 changes: 4 additions & 4 deletions handlers/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestAPIBasics(t *testing.T) {
})

t.Run("no-perm", func(t *testing.T) {
body := bytes.NewReader(zjson.MustMarshal(map[string]interface{}{
body := bytes.NewReader(zjson.MustMarshal(map[string]any{
"perm": goatcounter.APIPermExport | goatcounter.APIPermCount,
}))
ctx := gctest.DB(t)
Expand Down Expand Up @@ -178,7 +178,7 @@ func TestAPIBasics(t *testing.T) {

ctx := gctest.DB(t)
r, rr := newAPITest(ctx, t, "POST", "/api/v0/test",
bytes.NewReader(zjson.MustMarshal(map[string]interface{}{
bytes.NewReader(zjson.MustMarshal(map[string]any{
"validate": v,
})),
0)
Expand All @@ -196,7 +196,7 @@ func TestAPIBasics(t *testing.T) {
t.Run("context", func(t *testing.T) {
ctx := gctest.DB(t)
r, rr := newAPITest(ctx, t, "POST", "/api/v0/test",
bytes.NewReader(zjson.MustMarshal(map[string]interface{}{
bytes.NewReader(zjson.MustMarshal(map[string]any{
"context": true,
})),
0)
Expand All @@ -216,7 +216,7 @@ func TestAPIBasics(t *testing.T) {
t.Run("check-perm", func(t *testing.T) {
ctx := gctest.DB(t)

body := bytes.NewReader(zjson.MustMarshal(map[string]interface{}{
body := bytes.NewReader(zjson.MustMarshal(map[string]any{
"perm": goatcounter.APIPermExport | goatcounter.APIPermCount,
}))
r, rr := newAPITest(ctx, t, "POST", "/api/v0/test", body,
Expand Down
2 changes: 1 addition & 1 deletion handlers/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func TestBackendPagesMore(t *testing.T) {
newBackend(zdb.MustGetDB(ctx)).ServeHTTP(rr, r)
ztest.Code(t, rr, 200)

var body map[string]interface{}
var body map[string]any
zjson.MustUnmarshal(rr.Body.Bytes(), &body)

haveHTML := grep("tr id=", string(body["html"].(string)))
Expand Down
4 changes: 2 additions & 2 deletions handlers/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ func (h backend) dashboard(w http.ResponseWriter, r *http.Request) error {
run.Run(func() {
getData(w)
getHTML(w)
loader.sendJSON(r, connectID, map[string]interface{}{
loader.sendJSON(r, connectID, map[string]any{
"id": w.ID(),
"html": w.HTML(),
})
Expand Down Expand Up @@ -324,7 +324,7 @@ func (h backend) loadWidget(w http.ResponseWriter, r *http.Request) error {
wid.SetSettings(s)
}

ret := make(map[string]interface{})
ret := make(map[string]any)
switch wid.Name() {
case "pages":
p := wid.(*widgets.Pages)
Expand Down
2 changes: 1 addition & 1 deletion handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type Globals struct {
HideUI bool
}

func (g Globals) T(msg string, data ...interface{}) template.HTML {
func (g Globals) T(msg string, data ...any) template.HTML {
return template.HTML(z18n.T(g.Context, msg, data...))
}

Expand Down
4 changes: 2 additions & 2 deletions handlers/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type handlerTest struct {
path string
method string
auth bool
body interface{}
body any
wantCode int
wantFormCode int
wantBody string
Expand Down Expand Up @@ -209,7 +209,7 @@ func newTest(ctx context.Context, method, path string, body io.Reader) (*http.Re
// Use github.com/teamwork/test.Multipart for a multipart form.
//
// Note: this is primitive, but enough for now.
func formBody(i interface{}) string {
func formBody(i any) string {
var m map[string]string
zjson.MustUnmarshal(zjson.MustMarshal(i), &m)

Expand Down
2 changes: 1 addition & 1 deletion handlers/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func (h i18n) save(w http.ResponseWriter, r *http.Request) error {
return err
}

return zhttp.JSON(w, map[string]interface{}{"success": true})
return zhttp.JSON(w, map[string]any{"success": true})
}

func (h i18n) set(w http.ResponseWriter, r *http.Request) error {
Expand Down
2 changes: 1 addition & 1 deletion handlers/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (l *loaderT) connect(r *http.Request, id zint.Uint128, c *websocket.Conn) {
l.conns.Set(id, &loaderClient{conn: c})
}

func (l *loaderT) sendJSON(r *http.Request, id zint.Uint128, data interface{}) {
func (l *loaderT) sendJSON(r *http.Request, id zint.Uint128, data any) {
c, ok := l.conns.Get(id)
if !ok {
// No connection yet; this shouldn't happen, but does happen quite a lot
Expand Down
2 changes: 1 addition & 1 deletion handlers/mw.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func addctx(db zdb.DB, loadSite bool, dashTimeout int) func(http.Handler) http.H
// Intercept /status here so it works everywhere.
if r.URL.Path == "/status" {
info, _ := zdb.Info(ctx)
j, err := json.Marshal(map[string]interface{}{
j, err := json.Marshal(map[string]any{
"uptime": ztime.Now().Sub(Started).Round(time.Second).String(),
"version": goatcounter.Version,
"database": zdb.SQLDialect(ctx).String() + " " + string(info.Version),
Expand Down
4 changes: 2 additions & 2 deletions handlers/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ func (h settings) exportStart(w http.ResponseWriter, r *http.Request) error {

func (h settings) delete(verr *zvalidate.Validator) zhttp.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) error {
del := map[string]interface{}{
del := map[string]any{
"ContactMe": r.URL.Query().Get("contact_me") == "true",
"Reason": r.URL.Query().Get("reason"),
}
Expand All @@ -675,7 +675,7 @@ func (h settings) delete(verr *zvalidate.Validator) zhttp.HandlerFunc {
Globals
Sites goatcounter.Sites
Validate *zvalidate.Validator
Delete map[string]interface{}
Delete map[string]any
}{newGlobals(w, r), sites, verr, del})
}
}
Expand Down
4 changes: 2 additions & 2 deletions handlers/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (h website) tpl(w http.ResponseWriter, r *http.Request) error {

// For the message form
Validate *zvalidate.Validator
Args interface{}
Args any
}{newGlobals(w, r), t, metaDesc[t], loggedIn, nil, nil})
}

Expand Down Expand Up @@ -525,7 +525,7 @@ func (h website) help(w http.ResponseWriter, r *http.Request) error {

// For the message form
Validate *zvalidate.Validator
Args interface{}
Args any
}{newGlobals(w, r), "help", cp, "Documentation – GoatCounter",
dc, site.URL(r.Context()), site.Domain(r.Context()), h.fromWWW,
nil, nil})
Expand Down
2 changes: 1 addition & 1 deletion path.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (p Path) updateTitle(ctx context.Context, currentTitle, newTitle string) er
}

var titles []string
cacheChangedTitles(ctx).Modify(k, func(v interface{}) interface{} {
cacheChangedTitles(ctx).Modify(k, func(v any) any {
vv := v.([]string)
vv = append(vv, newTitle)
titles = vv
Expand Down
46 changes: 23 additions & 23 deletions settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type (

// Widgets is a list of widgets to be printed, in order.
Widgets []Widget
Widget map[string]interface{}
Widget map[string]any

WidgetSettings map[string]WidgetSetting
WidgetSetting struct {
Expand All @@ -100,8 +100,8 @@ type (
Help string
Options [][2]string
OptionsFunc func(context.Context) [][2]string
Validate func(*zvalidate.Validator, interface{})
Value interface{}
Validate func(*zvalidate.Validator, any)
Value any
}

// Views for the dashboard; these settings apply to all widget and are
Expand All @@ -125,7 +125,7 @@ func defaultWidgets(ctx context.Context) Widgets {
s := defaultWidgetSettings(ctx)
w := Widgets{}
for _, n := range []string{"pages", "totalpages", "toprefs", "campaigns", "browsers", "systems", "locations", "languages", "sizes"} {
w = append(w, map[string]interface{}{"n": n, "s": s[n].getMap()})
w = append(w, map[string]any{"n": n, "s": s[n].getMap()})
}
return w
}
Expand All @@ -139,7 +139,7 @@ func defaultWidgetSettings(ctx context.Context) map[string]WidgetSettings {
Label: z18n.T(ctx, "widget-setting/label/page-size|Page size"),
Help: z18n.T(ctx, "widget-setting/help/page-size|Number of pages to load"),
Value: float64(10),
Validate: func(v *zvalidate.Validator, val interface{}) {
Validate: func(v *zvalidate.Validator, val any) {
v.Range("limit_pages", int64(val.(float64)), 1, 100)
},
},
Expand All @@ -148,7 +148,7 @@ func defaultWidgetSettings(ctx context.Context) map[string]WidgetSettings {
Label: z18n.T(ctx, "widget-setting/label/ref-page-size|Referrers page size"),
Help: z18n.T(ctx, "widget-setting/help/ref-page-size|Number of referrers to load when clicking on a path"),
Value: float64(10),
Validate: func(v *zvalidate.Validator, val interface{}) {
Validate: func(v *zvalidate.Validator, val any) {
v.Range("limit_pages", int64(val.(float64)), 1, 100)
},
},
Expand All @@ -174,7 +174,7 @@ func defaultWidgetSettings(ctx context.Context) map[string]WidgetSettings {
[2]string{"bar", z18n.T(ctx, "widget-settings/bar-chart|Bar chart")},
[2]string{"text", z18n.T(ctx, "widget-settings/text-chart|Text table")},
},
Validate: func(v *zvalidate.Validator, val interface{}) {
Validate: func(v *zvalidate.Validator, val any) {
v.Include("style", val.(string), []string{"line", "bar", "text"})
},
},
Expand All @@ -201,7 +201,7 @@ func defaultWidgetSettings(ctx context.Context) map[string]WidgetSettings {
[2]string{"line", z18n.T(ctx, "widget-settings/line-chart|Line chart")},
[2]string{"bar", z18n.T(ctx, "widget-settings/bar-chart|Bar chart")},
},
Validate: func(v *zvalidate.Validator, val interface{}) {
Validate: func(v *zvalidate.Validator, val any) {
v.Include("style", val.(string), []string{"line", "bar"})
},
},
Expand All @@ -212,7 +212,7 @@ func defaultWidgetSettings(ctx context.Context) map[string]WidgetSettings {
Label: z18n.T(ctx, "widget-setting/label/page-size|Page size"),
Help: z18n.T(ctx, "widget-setting/help/page-size|Number of pages to load"),
Value: float64(6),
Validate: func(v *zvalidate.Validator, val interface{}) {
Validate: func(v *zvalidate.Validator, val any) {
v.Range("limit", int64(val.(float64)), 1, 20)
},
},
Expand All @@ -224,7 +224,7 @@ func defaultWidgetSettings(ctx context.Context) map[string]WidgetSettings {
Label: z18n.T(ctx, "widget-setting/label/page-size|Page size"),
Help: z18n.T(ctx, "widget-setting/help/page-size|Number of pages to load"),
Value: float64(6),
Validate: func(v *zvalidate.Validator, val interface{}) {
Validate: func(v *zvalidate.Validator, val any) {
v.Range("limit", int64(val.(float64)), 1, 20)
},
},
Expand All @@ -236,7 +236,7 @@ func defaultWidgetSettings(ctx context.Context) map[string]WidgetSettings {
Label: z18n.T(ctx, "widget-setting/label/page-size|Page size"),
Help: z18n.T(ctx, "widget-setting/help/page-size|Number of pages to load"),
Value: float64(6),
Validate: func(v *zvalidate.Validator, val interface{}) {
Validate: func(v *zvalidate.Validator, val any) {
v.Range("limit", int64(val.(float64)), 1, 20)
},
},
Expand All @@ -251,7 +251,7 @@ func defaultWidgetSettings(ctx context.Context) map[string]WidgetSettings {
Label: z18n.T(ctx, "widget-setting/label/page-size|Page size"),
Help: z18n.T(ctx, "widget-setting/help/page-size|Number of pages to load"),
Value: float64(6),
Validate: func(v *zvalidate.Validator, val interface{}) {
Validate: func(v *zvalidate.Validator, val any) {
v.Range("limit", int64(val.(float64)), 1, 20)
},
},
Expand Down Expand Up @@ -281,7 +281,7 @@ func defaultWidgetSettings(ctx context.Context) map[string]WidgetSettings {
Label: z18n.T(ctx, "widget-setting/label/page-size|Page size"),
Help: z18n.T(ctx, "widget-setting/help/page-size|Number of pages to load"),
Value: float64(6),
Validate: func(v *zvalidate.Validator, val interface{}) {
Validate: func(v *zvalidate.Validator, val any) {
v.Range("limit", int64(val.(float64)), 1, 20)
},
},
Expand All @@ -292,7 +292,7 @@ func defaultWidgetSettings(ctx context.Context) map[string]WidgetSettings {
Label: z18n.T(ctx, "widget-setting/label/page-size|Page size"),
Help: z18n.T(ctx, "widget-setting/help/page-size|Number of pages to load"),
Value: float64(6),
Validate: func(v *zvalidate.Validator, val interface{}) {
Validate: func(v *zvalidate.Validator, val any) {
v.Range("limit", int64(val.(float64)), 1, 20)
},
},
Expand All @@ -303,7 +303,7 @@ func defaultWidgetSettings(ctx context.Context) map[string]WidgetSettings {

func (ss SiteSettings) String() string { return string(zjson.MustMarshal(ss)) }
func (ss SiteSettings) Value() (driver.Value, error) { return json.Marshal(ss) }
func (ss *SiteSettings) Scan(v interface{}) error {
func (ss *SiteSettings) Scan(v any) error {
switch vv := v.(type) {
case []byte:
return json.Unmarshal(vv, ss)
Expand All @@ -315,7 +315,7 @@ func (ss *SiteSettings) Scan(v interface{}) error {
}
func (ss UserSettings) String() string { return string(zjson.MustMarshal(ss)) }
func (ss UserSettings) Value() (driver.Value, error) { return json.Marshal(ss) }
func (ss *UserSettings) Scan(v interface{}) error {
func (ss *UserSettings) Scan(v any) error {
switch vv := v.(type) {
case []byte:
return json.Unmarshal(vv, ss)
Expand Down Expand Up @@ -441,15 +441,15 @@ func (ss SiteSettings) CollectFlags(ctx context.Context) []CollectFlag {
}
}

func (s *WidgetSettings) Set(k string, v interface{}) {
func (s *WidgetSettings) Set(k string, v any) {
ss := *s
m := ss[k]
m.Value = v
ss[k] = m
}

func (s WidgetSettings) getMap() map[string]interface{} {
m := make(map[string]interface{})
func (s WidgetSettings) getMap() map[string]any {
m := make(map[string]any)
for k, v := range s {
m[k] = v.Value
}
Expand Down Expand Up @@ -513,9 +513,9 @@ func (w Widget) SetSetting(ctx context.Context, widget, setting, value string) e
return fmt.Errorf("Widget.SetSetting: no such setting %q for widget %q", setting, widget)
}

s, ok := w["s"].(map[string]interface{})
s, ok := w["s"].(map[string]any)
if !ok {
s = make(map[string]interface{})
s = make(map[string]any)
}
switch def.Type {
case "number":
Expand All @@ -536,7 +536,7 @@ func (w Widget) SetSetting(ctx context.Context, widget, setting, value string) e
// Name gets this widget's name.
func (w Widget) Name() string { return w["n"].(string) }

func (w Widget) GetSetting(ctx context.Context, n string) interface{} {
func (w Widget) GetSetting(ctx context.Context, n string) any {
for k, v := range w.GetSettings(ctx) {
if k == n {
return v.Value
Expand All @@ -553,7 +553,7 @@ func (w Widget) GetSettings(ctx context.Context) WidgetSettings {
}
s, ok := w["s"]
if ok {
for k, v := range s.(map[string]interface{}) {
for k, v := range s.(map[string]any) {
if v != nil {
d := def[k]
d.Value = v
Expand Down
Loading

0 comments on commit 5cbc382

Please sign in to comment.