diff options
author | Michael Li <alimy@gility.net> | 2022-03-17 14:05:09 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-17 14:05:09 +0800 |
commit | 32c454ba5faea9dc4236c12e28e0b65f01117cc1 (patch) | |
tree | 1eea30a83f78b311983924ba3bab00884633f508 /internal/conf | |
parent | 39f64a1371cdb01e02aeeb04839d2689052ae1d3 (diff) |
assets: convert usage of go-bindata to Go embed (#6851)
Co-authored-by: Joe Chen <jc@unknwon.io>
Diffstat (limited to 'internal/conf')
-rw-r--r-- | internal/conf/conf.go | 27 | ||||
-rw-r--r-- | internal/conf/conf_test.go | 21 |
2 files changed, 8 insertions, 40 deletions
diff --git a/internal/conf/conf.go b/internal/conf/conf.go index fed5bca4..f7a6f886 100644 --- a/internal/conf/conf.go +++ b/internal/conf/conf.go @@ -22,7 +22,7 @@ import ( "gopkg.in/ini.v1" log "unknwon.dev/clog/v2" - "gogs.io/gogs/internal/assets/conf" + "gogs.io/gogs/conf" "gogs.io/gogs/internal/osutil" "gogs.io/gogs/internal/semverutil" ) @@ -35,21 +35,6 @@ func init() { } } -// Asset is a wrapper for getting conf assets. -func Asset(name string) ([]byte, error) { - return conf.Asset(name) -} - -// AssetDir is a wrapper for getting conf assets. -func AssetDir(name string) ([]string, error) { - return conf.AssetDir(name) -} - -// MustAsset is a wrapper for getting conf assets. -func MustAsset(name string) []byte { - return conf.MustAsset(name) -} - // File is the configuration object. var File *ini.File @@ -62,12 +47,16 @@ var File *ini.File // // ⚠️ WARNING: Do not print anything in this function other than warnings. func Init(customConf string) error { - var err error + data, err := conf.Files.ReadFile("app.ini") + if err != nil { + return errors.Wrap(err, `read default "app.ini"`) + } + File, err = ini.LoadSources(ini.LoadOptions{ IgnoreInlineComment: true, - }, conf.MustAsset("conf/app.ini")) + }, data) if err != nil { - return errors.Wrap(err, "parse 'conf/app.ini'") + return errors.Wrap(err, `parse "app.ini"`) } File.NameMapper = ini.SnackCase diff --git a/internal/conf/conf_test.go b/internal/conf/conf_test.go index c5159bed..1ac64d6c 100644 --- a/internal/conf/conf_test.go +++ b/internal/conf/conf_test.go @@ -15,27 +15,6 @@ import ( "gogs.io/gogs/internal/testutil" ) -func TestAsset(t *testing.T) { - // Make sure it does not blow up - _, err := Asset("conf/app.ini") - if err != nil { - t.Fatal(err) - } -} - -func TestAssetDir(t *testing.T) { - // Make sure it does not blow up - _, err := AssetDir("conf") - if err != nil { - t.Fatal(err) - } -} - -func TestMustAsset(_ *testing.T) { - // Make sure it does not blow up - MustAsset("conf/app.ini") -} - func TestInit(t *testing.T) { ini.PrettyFormat = false defer func() { |