我用Iris版本12构建了一个Go Web项目,现在有一个名为,我可以通过包含的文件夹中的shell脚本输出,但是去注意我。
该文件夹的结构如下:config.goconfig.jsoncat ../config.jsonconfig.gopanic: open ../config.json: no such file or directory
.
├── config
│ └── config.go
├── config.json
├── config.yml
├── controller
├── datasource
├── go.mod
├── go.sum
├── main.go
├── model
│ └── user.go
├── service
├── static
│ ├── css
│ │ └── app.85873a69abe58e3fc37a13d571ef59e2.css
│ ├── favicons
│ │ └── favicon.ico
│ ├── fonts
│ │ └── element-icons.b02bdc1.ttf
│ ├── img
│ │ └── default.jpg
│ ├── index.html
│ └── js
│ ├── 0.6e924665f4f8679a8f0b.js
└── util
附言我还尝试了在shell中可用,在Go中不可用。./../config.json
具体如下:config.go
package config
import (
"encoding/json"
"os"
)
type AppConfig struct {
AppName string `json:"app_name"` // Project name
Port int `json:"port"` // Server port
StaticPath string `json:"static_path"` // The path of static resources
Mode string `json:"mode"` // Development mode
}
func InitConfig() *AppConfig {
file, err := os.Open("../config.json")
if err != nil {
panic(err.Error())
}
decoder := json.NewDecoder(file)
conf := AppConfig{}
err = decoder.Decode(&conf)
if err != nil {
panic(err.Error())
}
return &conf
}
桃花长相依
守着一只汪
相关分类