Skip to content

Commit

Permalink
Make conf embed reentrant
Browse files Browse the repository at this point in the history
  • Loading branch information
sergystepanov committed Jul 26, 2023
1 parent b884f0b commit a8b45cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions pkg/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package config

import (
"bytes"
"embed"
"os"
"path/filepath"
"strings"

_ "embed"
"github.com/knadh/koanf/maps"
"github.com/knadh/koanf/v2"
"gopkg.in/yaml.v3"
Expand All @@ -16,7 +16,7 @@ const EnvPrefix = "CLOUD_GAME_"

var (
//go:embed config.yaml
conf Bytes
conf embed.FS
)

type Kv = map[string]any
Expand Down Expand Up @@ -124,10 +124,14 @@ func LoadConfig(config any, path string) (loaded []string, err error) {

k := koanf.New("_") // move to global scope if configs become dynamic
defer k.Delete("")
data, err := conf.ReadFile("config.yaml")
if err != nil {
return nil, err
}
conf := Bytes(data)
if err := k.Load(&conf, &YAML{}); err != nil {
return nil, err
}
conf = nil
loaded = append(loaded, "default")

for _, dir := range dirs {
Expand Down
2 changes: 1 addition & 1 deletion pkg/worker/room_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package worker
import (
"flag"
"fmt"
"github.com/giongto35/cloud-game/v3/pkg/worker/emulator/libretro/manager"
"hash/crc32"
"image"
"image/color"
Expand All @@ -22,6 +21,7 @@ import (
"github.com/giongto35/cloud-game/v3/pkg/logger"
"github.com/giongto35/cloud-game/v3/pkg/worker/emulator"
image2 "github.com/giongto35/cloud-game/v3/pkg/worker/emulator/image"
"github.com/giongto35/cloud-game/v3/pkg/worker/emulator/libretro/manager"
"github.com/giongto35/cloud-game/v3/pkg/worker/encoder"
"github.com/giongto35/cloud-game/v3/pkg/worker/thread"
"golang.org/x/image/font"
Expand Down

0 comments on commit a8b45cd

Please sign in to comment.