2 Star 2 Fork 0

yanghy/http-server

Create your Gitee Account
Explore and code with more than 13.5 million developers,Free private repositories !:)
Sign up
文件
Clone or Download
config.go 1.46 KB
Copy Edit Raw Blame History
yanghy authored 2022-05-04 20:31 +08:00 . server config
package config
import (
"encoding/json"
"gitee.com/snxamdf/golcl/lcl/types/colors"
"gitee.com/snxamdf/http-server/src/entity"
"io/ioutil"
)
var Cfg = &Config{
ROOT: "root", //解析网站文件目录,默认root文件夹
}
type Config struct {
ROOT string `json:"root"`
Server Server
Proxy
Sqlite3 Sqlite3
}
type Server struct {
IP string `json:"ip"`
PORT string `json:"port"`
}
type Proxy struct {
Proxy map[string]ProxyTarget `json:"proxy"`
}
type ProxyTarget struct {
Target string `json:"target"`
ProxyTargetRewrite
}
type ProxyTargetRewrite struct {
Rewrite map[string]string `json:"rewrite"`
}
type Sqlite3 struct {
Path string `json:"path"`
Name string `json:"name"`
}
func (m *Config) ToJSON() []byte {
b, err := json.Marshal(m)
if err != nil {
return nil
}
return b
}
func (m *Proxy) ToJSON() []byte {
b, err := json.Marshal(m)
if err != nil {
return nil
}
return b
}
func init() {
defer func() {
if err := recover(); err != nil {
entity.AppInitSuccess = false
entity.PutColorMessage(colors.ClRed, "读取配置文件 致命错误 ", (err.(error)).Error())
}
}()
byt, err := ioutil.ReadFile("hs.conf.json")
if err != nil {
entity.AppInitSuccess = false
entity.PutColorMessage(colors.ClRed, "读取配置文件错误:", err.Error())
return
}
err = json.Unmarshal(byt, Cfg)
if err != nil {
entity.AppInitSuccess = false
entity.PutColorMessage(colors.ClRed, "解析配置文件错误:", err.Error())
return
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/snxamdf/http-server.git
git@gitee.com:snxamdf/http-server.git
snxamdf
http-server
http-server
v1.0.0

Search