NextGB, web demo powerd by vue
This commit is contained in:
@ -3,16 +3,85 @@ package config
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
// 通用配置
|
||||
type CommonConfig struct {
|
||||
LogLevel string `yaml:"log-level"`
|
||||
LogFile string `yaml:"log-file"`
|
||||
}
|
||||
|
||||
// GB28181配置
|
||||
type GB28181AuthConfig struct {
|
||||
Enable bool `yaml:"enable"`
|
||||
Password string `yaml:"password"`
|
||||
}
|
||||
|
||||
type GB28181Config struct {
|
||||
Serial string `yaml:"serial"`
|
||||
Realm string `yaml:"realm"`
|
||||
Host string `yaml:"host"`
|
||||
Port int `yaml:"port"`
|
||||
Auth GB28181AuthConfig `yaml:"auth"`
|
||||
}
|
||||
|
||||
// HTTP服务配置
|
||||
type HttpConfig struct {
|
||||
Port int `yaml:"listen"`
|
||||
Dir string `yaml:"dir"`
|
||||
}
|
||||
|
||||
// 主配置结构
|
||||
type MainConfig struct {
|
||||
Serial string `ymal:"serial"`
|
||||
Realm string `ymal:"realm"`
|
||||
SipHost string `ymal:"sip-host"`
|
||||
SipPort int `ymal:"sip-port"`
|
||||
MediaAddr string `ymal:"media-addr"`
|
||||
HttpServerPort int `ymal:"http-server-port"`
|
||||
APIPort int `ymal:"api-port"`
|
||||
Common CommonConfig `yaml:"common"`
|
||||
GB28181 GB28181Config `yaml:"gb28181"`
|
||||
Http HttpConfig `yaml:"http"`
|
||||
}
|
||||
|
||||
// 获取默认配置
|
||||
func DefaultConfig() *MainConfig {
|
||||
return &MainConfig{
|
||||
Common: CommonConfig{
|
||||
LogLevel: "info",
|
||||
LogFile: "app.log",
|
||||
},
|
||||
GB28181: GB28181Config{
|
||||
Serial: "34020000002000000001",
|
||||
Realm: "3402000000",
|
||||
Host: "0.0.0.0",
|
||||
Port: 5060,
|
||||
Auth: GB28181AuthConfig{
|
||||
Enable: false,
|
||||
Password: "123456",
|
||||
},
|
||||
},
|
||||
Http: HttpConfig{
|
||||
Port: 8025,
|
||||
Dir: "./html",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func LoadConfig(filename string) (*MainConfig, error) {
|
||||
// 如果配置文件不存在,返回默认配置
|
||||
if _, err := os.Stat(filename); os.IsNotExist(err) {
|
||||
return DefaultConfig(), nil
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read config file failed: %v", err)
|
||||
}
|
||||
|
||||
var config MainConfig
|
||||
if err := yaml.Unmarshal(data, &config); err != nil {
|
||||
return nil, fmt.Errorf("parse config file failed: %v", err)
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
func GetLocalIP() (string, error) {
|
||||
|
||||
Reference in New Issue
Block a user