Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyenought committed Aug 29, 2023
1 parent 32ebfd5 commit 77c14f1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 21 deletions.
22 changes: 11 additions & 11 deletions .github/workflows/govulncheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,44 +37,44 @@ jobs:
run: go install golang.org/x/vuln/cmd/govulncheck@latest
- name: Run govulncheck (paseto)
working-directory: ./paseto
run: govulncheck ./...
run: go mod tidy && govulncheck ./...
# -----
- name: Run govulncheck (fiberzap)
working-directory: ./fiberzap
run: govulncheck ./...
run: go mod tidy && govulncheck ./...
# -----
- name: Run govulncheck (otelfiber)
working-directory: ./otelfiber
run: govulncheck ./...
run: go mod tidy && govulncheck ./...
- name: Run govulncheck (swagger)
working-directory: ./swagger
run: govulncheck ./...
run: go mod tidy && govulncheck ./...
# -----
- name: Run govulncheck (casbin)
working-directory: ./casbin
run: govulncheck ./...
run: go mod tidy && govulncheck ./...
# -----
- name: Run govulncheck (fibernewrelic)
working-directory: ./fibernewrelic
run: govulncheck ./...
run: go mod tidy && govulncheck ./...
# -----
- name: Run govulncheck (opafiber)
working-directory: ./opafiber
run: govulncheck ./...
run: go mod tidy && govulncheck ./...
# -----
- name: Run govulncheck (fiberi18n)
working-directory: ./fiberi18n
run: govulncheck ./...
run: go mod tidy && govulncheck ./...
# -----
- name: Run govulncheck (fiberzerolog)
working-directory: ./fiberzerolog
run: govulncheck ./...
run: go mod tidy && govulncheck ./...
# -----
- name: Run govulncheck (jwt)
working-directory: ./jwt
run: govulncheck ./...
run: go mod tidy && govulncheck ./...
# -----
- name: Run govulncheck (websocket)
working-directory: ./websocket
run: govulncheck ./...
run: go mod tidy && govulncheck ./...
# -----
2 changes: 1 addition & 1 deletion .github/workflows/test-fiberi18n.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ jobs:
go-version: '${{ matrix.go-version }}'
- name: Run Test
working-directory: ./fiberi18n
run: go test -v -race ./...
run: go mod tidy && go test -v -race ./...
1 change: 1 addition & 0 deletions fiberi18n/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type Config struct {

bundle *i18n.Bundle
localizerMap *sync.Map
mu sync.Mutex
}

type Loader interface {
Expand Down
19 changes: 12 additions & 7 deletions fiberi18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ import (

// New creates a new middleware handler
func New(config ...*Config) fiber.Handler {
appCfg := configDefault(config...)
cfg := configDefault(config...)
// init bundle
bundle := i18n.NewBundle(appCfg.DefaultLanguage)
bundle.RegisterUnmarshalFunc(appCfg.FormatBundleFile, appCfg.UnmarshalFunc)
appCfg.bundle = bundle
bundle := i18n.NewBundle(cfg.DefaultLanguage)
bundle.RegisterUnmarshalFunc(cfg.FormatBundleFile, cfg.UnmarshalFunc)
cfg.bundle = bundle

appCfg.loadMessages().initLocalizerMap()
cfg.loadMessages()
cfg.initLocalizerMap()

return func(c *fiber.Ctx) error {
if appCfg.Next != nil && appCfg.Next(c) {
if cfg.Next != nil && cfg.Next(c) {
return c.Next()
}
c.Locals("fiberi18n", appCfg)
c.Locals("fiberi18n", cfg)
return c.Next()
}
}
Expand All @@ -40,6 +41,8 @@ func (c *Config) loadMessage(filepath string) {
}

func (c *Config) loadMessages() *Config {
c.mu.Lock()
defer c.mu.Unlock()
for _, lang := range c.AcceptLanguages {
bundleFilePath := fmt.Sprintf("%s.%s", lang.String(), c.FormatBundleFile)
filepath := path.Join(c.RootPath, bundleFilePath)
Expand All @@ -60,6 +63,8 @@ func (c *Config) initLocalizerMap() {
if _, ok := localizerMap.Load(lang); !ok {
localizerMap.Store(lang, i18n.NewLocalizer(c.bundle, lang))
}
c.mu.Lock()
defer c.mu.Unlock()
c.localizerMap = localizerMap
}

Expand Down
3 changes: 1 addition & 2 deletions fiberi18n/i18n_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ func TestLocalize(t *testing.T) {
}

func Test_defaultLangHandler(t *testing.T) {
t.Parallel()
app := fiber.New()
app.Use(New())
app.Get("/", func(c *fiber.Ctx) error {
Expand All @@ -215,7 +214,7 @@ func Test_defaultLangHandler(t *testing.T) {
app.Get("/test", func(c *fiber.Ctx) error {
return c.SendString(defaultLangHandler(c, language.English.String()))
})

t.Parallel()
t.Run("test nil ctx", func(t *testing.T) {
var wg sync.WaitGroup
want := 100
Expand Down

0 comments on commit 77c14f1

Please sign in to comment.