代码拉取完成,页面将自动刷新
// Copyright 2014 mqant Author. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package conf
import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"
)
var (
LenStackBuf = 1024
Conf = Config{}
)
func LoadConfig(Path string) {
// Read config.
if err := readFileInto(Path); err != nil {
panic(err)
}
if Conf.Rpc.MaxCoroutine == 0 {
Conf.Rpc.MaxCoroutine = 100
}
}
type Config struct {
Log map[string]interface{}
Rpc Rpc
Module map[string][]*ModuleSettings
Mqtt Mqtt
Master Master
Settings map[string]interface{}
}
type Rpc struct {
MaxCoroutine int //模块同时可以创建的最大协程数量默认是100
RpcExpired int //远程访问最后期限值 单位秒[默认5秒] 这个值指定了在客户端可以等待服务端多长时间来应答
LogSuccess bool //是否打印请求处理成功的日志
Log bool //是否打印RPC的日志
}
type Rabbitmq struct {
Uri string
Exchange string
ExchangeType string
Queue string
BindingKey string //
ConsumerTag string //消费者TAG
}
type Redis struct {
Uri string //redis://:[password]@[ip]:[port]/[db]
Queue string
}
type ModuleSettings struct {
Id string
Host string
ProcessID string
Settings map[string]interface{}
Rabbitmq *Rabbitmq
Redis *Redis
}
type Mqtt struct {
WirteLoopChanNum int // Should > 1 // 最大写入包队列缓存
ReadPackLoop int // 最大读取包队列缓存
ReadTimeout int // 读取超时
WriteTimeout int // 写入超时
}
type SSH struct {
Host string
Port int
User string
Password string
}
/**
host:port
*/
func (s *SSH) GetSSHHost() string {
return fmt.Sprintf("%s:%d", s.Host, s.Port)
}
type Process struct {
ProcessID string
Host string
//执行文件
Execfile string
//日志文件目录
//pid.nohup.log
//pid.access.log
//pid.error.log
LogDir string
//自定义的参数
Args map[string]interface{}
}
type Master struct {
Enable bool
WebRoot string
WebHost string
SSH []*SSH
Process []*Process
}
func (m *Master) GetSSH(host string) *SSH {
for _, ssh := range m.SSH {
if ssh.Host == host {
return ssh
}
}
return nil
}
func readFileInto(path string) error {
var data []byte
buf := new(bytes.Buffer)
f, err := os.Open(path)
if err != nil {
return err
}
defer f.Close()
r := bufio.NewReader(f)
for {
line, err := r.ReadSlice('\n')
if err != nil {
if len(line) > 0 {
buf.Write(line)
}
break
}
if !strings.HasPrefix(strings.TrimLeft(string(line), "\t "), "//") {
buf.Write(line)
}
}
data = buf.Bytes()
//fmt.Print(string(data))
return json.Unmarshal(data, &Conf)
}
// If read the file has an error,it will throws a panic.
func fileToStruct(path string, ptr *[]byte) {
data, err := ioutil.ReadFile(path)
if err != nil {
panic(err)
}
*ptr = data
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。