package config

import (
	"fmt"
	"github.com/fsnotify/fsnotify"
	"github.com/golang/protobuf/proto"
	"github.com/spf13/viper"
)

var ProtoRequestMap = make(map[int]proto.Message)
var ProtoResponseMap = make(map[int]proto.Message)

func RegisterProto(protoId int, req proto.Message, resp proto.Message) {
	ProtoRequestMap[protoId] = req
	ProtoResponseMap[protoId] = resp
}

func InitConfig(name string, path string) {
	viper.SetConfigType("json")
	viper.SetConfigName(name)
	viper.AddConfigPath(path)
	err := viper.ReadInConfig()
	if err != nil {
		panic(fmt.Errorf("Fatal error config file: %s \n", err))
	}
	viper.WatchConfig()
	viper.OnConfigChange(func(e fsnotify.Event) {
		fmt.Println("监听到文件发生了变化:", e)
	})
}
