Skip to content

Commit 1e93998

Browse files
committed
all: switch from github.com/ghodss/yaml to gopkg.in/yaml.v3
yaml.v3 is the more widely used yaml. The main difference between the two is that ghodss converts yaml to JSON as an intermediate to marshalling and unmarshalling. That means we need to add yaml struct tags to use yaml.v3. Add yaml tags to ConfigOverride and QuotaSettings because yaml.v3 lowercases the names of fields by default and the configs have used uppercase names. Change a test experiment config to use lowercase names since that's what's used in most other configs. For golang/go#61399 Change-Id: Id7f09f2635ee013506b1573bfe555ec0348e60e4 Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/514522 TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Michael Matloob <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Jamal Carvalho <[email protected]> kokoro-CI: kokoro <[email protected]>
1 parent b486dfa commit 1e93998

File tree

6 files changed

+20
-22
lines changed

6 files changed

+20
-22
lines changed

devtools/cmd/create_experiment_config/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"sort"
1414
"strings"
1515

16-
"github.com/ghodss/yaml"
1716
"golang.org/x/pkgsite/internal"
17+
"gopkg.in/yaml.v3"
1818
)
1919

2020
type Experiment struct {

go.mod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ require (
1616
github.com/alicebob/miniredis/v2 v2.17.0
1717
github.com/andybalholm/cascadia v1.3.1
1818
github.com/evanw/esbuild v0.17.8
19-
github.com/ghodss/yaml v1.0.0
2019
github.com/go-redis/redis/v8 v8.11.4
2120
github.com/go-redis/redis_rate/v9 v9.1.2
2221
github.com/golang-migrate/migrate/v4 v4.15.1
@@ -43,6 +42,7 @@ require (
4342
google.golang.org/genproto v0.0.0-20211208223120-3a66f561d7aa
4443
google.golang.org/grpc v1.43.0
4544
google.golang.org/protobuf v1.27.1
45+
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
4646
)
4747

4848
require (
@@ -91,5 +91,4 @@ require (
9191
golang.org/x/sys v0.10.0 // indirect
9292
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
9393
google.golang.org/appengine v1.6.7 // indirect
94-
gopkg.in/yaml.v2 v2.4.0 // indirect
9594
)

go.sum

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,6 @@ github.com/gabriel-vasile/mimetype v1.3.1/go.mod h1:fA8fi6KUiG7MgQQ+mEWotXoEOvmx
405405
github.com/gabriel-vasile/mimetype v1.4.0/go.mod h1:fA8fi6KUiG7MgQQ+mEWotXoEOvmxRtOJlERCzSmRvr8=
406406
github.com/garyburd/redigo v0.0.0-20150301180006-535138d7bcd7/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
407407
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
408-
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
409408
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
410409
github.com/go-fonts/dejavu v0.1.0/go.mod h1:4Wt4I4OU2Nq9asgDCteaAaWZOV24E+0/Pwo0gppep4g=
411410
github.com/go-fonts/latin-modern v0.2.0/go.mod h1:rQVLdDMK+mK1xscDwsqM5J8U2jrRa3T0ecnM9pNujks=

internal/config/config.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import (
2424
"time"
2525

2626
"cloud.google.com/go/storage"
27-
"github.com/ghodss/yaml"
2827
"golang.org/x/net/context/ctxhttp"
2928
"golang.org/x/pkgsite/internal/derrors"
3029
"golang.org/x/pkgsite/internal/log"
3130
"golang.org/x/pkgsite/internal/secrets"
3231
mrpb "google.golang.org/genproto/googleapis/api/monitoredres"
32+
"gopkg.in/yaml.v3"
3333
)
3434

3535
// GetEnv looks up the given key from the environment, returning its value if
@@ -159,7 +159,7 @@ type Config struct {
159159

160160
DBSecret, DBUser, DBHost, DBPort, DBName, DBSSL string
161161
DBSecondaryHost string // DB host to use if first one is down
162-
DBPassword string `json:"-"`
162+
DBPassword string `json:"-" yaml:"-"`
163163

164164
// Configuration for redis page cache.
165165
RedisCacheHost, RedisBetaCacheHost, RedisCachePort string
@@ -331,25 +331,25 @@ func (c *Config) Application() string {
331331

332332
// configOverride holds selected config settings that can be dynamically overridden.
333333
type configOverride struct {
334-
DBHost string
335-
DBSecondaryHost string
336-
DBName string
337-
Quota QuotaSettings
334+
DBHost string `yaml:"DBHost"`
335+
DBSecondaryHost string `yaml:"DBSecondaryHost"`
336+
DBName string `yaml:"DBName"`
337+
Quota QuotaSettings `yaml:"Quota"`
338338
}
339339

340340
// QuotaSettings is config for internal/middleware/quota.go
341341
type QuotaSettings struct {
342-
Enable bool
343-
QPS int // allowed queries per second, per IP block
344-
Burst int // maximum requests per second, per block; the size of the token bucket
345-
MaxEntries int // maximum number of entries to keep track of
342+
Enable bool `yaml:"Enable"`
343+
QPS int `yaml:"QPS"` // allowed queries per second, per IP block
344+
Burst int `yaml:"Burst"` // maximum requests per second, per block; the size of the token bucket
345+
MaxEntries int `yaml:"MaxEntries"` // maximum number of entries to keep track of
346346
// Record data about blocking, but do not actually block.
347347
// This is a *bool, so we can distinguish "not present" from "false" in an override
348-
RecordOnly *bool
348+
RecordOnly *bool `yaml:"RecordOnly"`
349349
// AuthValues is the set of values that could be set on the AuthHeader, in
350350
// order to bypass checks by the quota server.
351-
AuthValues []string
352-
HMACKey []byte `json:"-"` // key for obfuscating IPs
351+
AuthValues []string `yaml:"AuthValues"`
352+
HMACKey []byte `json:"-" yaml:"-"` // key for obfuscating IPs
353353
}
354354

355355
// Init resolves all configuration values provided by the config package. It

internal/config/dynconfig/dynconfig.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ import (
1515
"strings"
1616

1717
"cloud.google.com/go/storage"
18-
"github.com/ghodss/yaml"
1918
"golang.org/x/pkgsite/internal"
2019
"golang.org/x/pkgsite/internal/derrors"
2120
"golang.org/x/pkgsite/internal/log"
21+
"gopkg.in/yaml.v3"
2222
)
2323

2424
// DynamicConfig holds configuration that can change over the lifetime of the

tests/search/config.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
experiments:
2-
- Name: search-grouping
3-
Rollout: 100
4-
- Name: symbol-search
5-
Rollout: 100
2+
- name: search-grouping
3+
rollout: 100
4+
- name: symbol-search
5+
rollout: 100

0 commit comments

Comments
 (0)