Skip to content

Commit

Permalink
add config file to embed
Browse files Browse the repository at this point in the history
Signed-off-by: hantmac <[email protected]>
  • Loading branch information
hantmac committed May 31, 2021
1 parent 017abef commit 7025e44
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion cmd/fuckdb/cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var serverCmd = &cobra.Command{
}
logrus.Infoln("config init success")

tplFile := viper.GetString("customTmpl")
tplFile := viper.GetString("example.tpl")
if tplFile != "" {
tmpl, err := template.ParseFiles(tplFile)
if err != nil {
Expand Down
9 changes: 0 additions & 9 deletions config/conf/config.yaml

This file was deleted.

9 changes: 4 additions & 5 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package config

import (
"bytes"
"embed"
_ "embed"
"github.com/fsnotify/fsnotify"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
)

//go:embed conf
var configBytes embed.FS
//go:embed config.yaml
var configBytes []byte

type Config struct {
Name string
Expand All @@ -23,9 +23,8 @@ func (c *Config) WatchConfig() {
}

func (c *Config) Init() error {
by, err := configBytes.ReadFile("conf/config.yaml")
viper.SetConfigType("yaml")
err = viper.ReadConfig(bytes.NewBufferString(string(by)))
err := viper.ReadConfig(bytes.NewBufferString(string(configBytes)))
if err != nil {
return err
}
Expand Down
8 changes: 8 additions & 0 deletions config/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: DbToGoStruct # API Server的名字
gormlog: true
server:
host: 127.0.0.1
port: 8000


genFilePath: ./

0 comments on commit 7025e44

Please sign in to comment.