1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-09-20 02:46:10 -04:00
v2fly/app/point/config/json/json.go

66 lines
1.6 KiB
Go
Raw Normal View History

package json
import (
2015-09-19 09:35:20 -04:00
"encoding/json"
"io/ioutil"
2015-09-20 05:45:40 -04:00
"os"
2015-09-19 09:35:20 -04:00
2015-10-30 17:50:45 -04:00
"github.com/v2ray/v2ray-core/app/point/config"
2015-09-19 18:50:21 -04:00
"github.com/v2ray/v2ray-core/common/log"
2015-10-30 17:42:24 -04:00
proxyconfig "github.com/v2ray/v2ray-core/proxy/common/config"
)
// Config is the config for Point server.
type Config struct {
2015-09-19 09:35:20 -04:00
PortValue uint16 `json:"port"` // Port of this Point server.
2015-10-09 11:43:27 -04:00
LogConfigValue *LogConfig `json:"log"`
InboundConfigValue *ConnectionConfig `json:"inbound"`
OutboundConfigValue *ConnectionConfig `json:"outbound"`
}
func (config *Config) Port() uint16 {
2015-09-19 09:35:20 -04:00
return config.PortValue
}
2015-10-09 11:43:27 -04:00
func (config *Config) LogConfig() config.LogConfig {
2015-10-10 06:14:21 -04:00
if config.LogConfigValue == nil {
return nil
}
2015-10-09 11:43:27 -04:00
return config.LogConfigValue
}
2015-10-06 17:11:08 -04:00
func (config *Config) InboundConfig() config.ConnectionConfig {
2015-10-10 06:14:21 -04:00
if config.InboundConfigValue == nil {
return nil
}
2015-09-19 09:35:20 -04:00
return config.InboundConfigValue
}
2015-10-06 17:11:08 -04:00
func (config *Config) OutboundConfig() config.ConnectionConfig {
2015-10-10 06:14:21 -04:00
if config.OutboundConfigValue == nil {
return nil
}
2015-09-19 09:35:20 -04:00
return config.OutboundConfigValue
}
func LoadConfig(file string) (*Config, error) {
2015-09-20 05:45:40 -04:00
fixedFile := os.ExpandEnv(file)
rawConfig, err := ioutil.ReadFile(fixedFile)
2015-09-19 09:35:20 -04:00
if err != nil {
2015-10-06 17:11:08 -04:00
log.Error("Failed to read server config file (%s): %v", file, err)
2015-09-19 09:35:20 -04:00
return nil, err
}
jsonConfig := &Config{}
err = json.Unmarshal(rawConfig, jsonConfig)
2015-10-04 10:53:37 -04:00
if err != nil {
2015-10-06 17:11:08 -04:00
log.Error("Failed to load server config: %v", err)
2015-10-04 10:53:37 -04:00
return nil, err
}
2015-09-19 09:35:20 -04:00
2015-10-30 17:42:24 -04:00
jsonConfig.InboundConfigValue.Type = proxyconfig.TypeInbound
jsonConfig.OutboundConfigValue.Type = proxyconfig.TypeOutbound
return jsonConfig, err
}