package handler import ( "matrix-common/pkg/logger" "matrix-dnslog-service/pkg/cache" "matrix-dnslog-service/pkg/handler/type" "strings" ) func ProcessHandler(data string) { handlers := []_type.Handler{ createData, appendData, endData, } datum := strings.Split(data, ".") if len(datum) != 5 { return } command := datum[0] id := datum[1] seq := datum[2] d := datum[3] logger.Log().Infof("command: %s, id: %s, seq: %s, data: %s", command, id, seq, d) for _, handler := range handlers { if handler(command, id, seq, d) { return } } } var createData = func(command, id, seq, data string) bool { if command != "s" { return false } logger.Log().Infof("[dnslog] (开始记录) id: %s 数据: %s", id, data) cache.Append(id, seq, data) return true } var appendData = func(command, id, seq, data string) bool { if command != "a" { return false } cache.Append(id, seq, data) return true } var endData = func(command, id, seq, data string) bool { if command != "e" { return false } logger.Log().Infof("[dnslog] (完成) id: %s 数据: %s", id, cache.Get(id)) return true }