当前位置: 首页>>代码示例>>Golang>>正文


Golang flow.Check函数代码示例

本文整理汇总了Golang中github.com/jcw/flow.Check函数的典型用法代码示例。如果您正苦于以下问题:Golang Check函数的具体用法?Golang Check怎么用?Golang Check使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Check函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Run

func (g *importCmd) Run() {
	data, err := ioutil.ReadFile(flag.Arg(1))
	flow.Check(err)

	var values map[string]map[string]interface{}
	err = json.Unmarshal(data, &values)
	flow.Check(err)

	OpenDatabase()
	for prefix, entries := range values {
		var ndel, nadd int

		// get and print all the key/value pairs from the database
		dbIterateOverKeys(prefix, "", func(k string, v []byte) {
			err = db.Delete([]byte(k), nil)
			flow.Check(err)
			ndel++
		})

		for k, v := range entries {
			val, err := json.Marshal(v)
			flow.Check(err)
			err = db.Put([]byte(prefix+k), val, nil)
			flow.Check(err)
			nadd++
		}

		fmt.Printf("%d deleted, %d added for prefix %q\n", ndel, nadd, prefix)
	}
}
开发者ID:x4rMa,项目名称:jeebus,代码行数:30,代码来源:commands.go

示例2: logOneLine

func (w *Logger) logOneLine(asof time.Time, text, port string) {
	// figure out name of logfile based on UTC date, with daily rotation
	year, month, day := asof.Date()
	path := fmt.Sprintf("%s/%d", w.dir, year)
	err := os.MkdirAll(path, os.ModePerm)
	flow.Check(err)
	// e.g. "./logger/2014/20140122.txt"
	datePath := fmt.Sprintf("%s/%d.txt", path, (year*100+int(month))*100+day)

	if w.fd == nil || datePath != w.fd.Name() {
		if w.fd != nil {
			name := w.fd.Name()
			w.fd.Close()
			w.Out.Send(name) // report the closed file
		}
		mode := os.O_WRONLY | os.O_APPEND | os.O_CREATE
		fd, err := os.OpenFile(datePath, mode, os.ModePerm)
		flow.Check(err)
		w.fd = fd
	}
	// append a new log entry, here is an example of the format used:
	// 	L 01:02:03.537 usb-A40117UK OK 9 25 54 66 235 61 210 226 33 19
	hour, min, sec := asof.Clock()
	line := fmt.Sprintf("L %02d:%02d:%02d.%03d %s %s\n",
		hour, min, sec, jeebus.TimeToMs(asof)%1000, port, text)
	w.fd.WriteString(line)
}
开发者ID:jcw,项目名称:housemon,代码行数:27,代码来源:logger.go

示例3: Run

// Start collecting values, emit aggregated results when a time step occurs.
func (g *Aggregator) Run() {
	g.stats = map[string]accumulator{}

	g.step = "1h"
	if s, ok := <-g.Step; ok {
		g.step = s.(string)
	}
	d, err := time.ParseDuration(g.step)
	flow.Check(err)
	g.stepMs = d.Nanoseconds() / 1e6

	// collect data and aggregate for each parameter
	for m := range g.In {
		if t, ok := m.(flow.Tag); ok {
			n := strings.LastIndex(t.Tag, "/")
			// expects input tags like these:
			// 	sensor/meterkast/c3/1396556362024 = 2396
			if n > 0 {
				prefix := t.Tag[:n+1]
				ms, err := strconv.ParseInt(t.Tag[n+1:], 10, 64)
				flow.Check(err)
				g.process(prefix, ms, t.Msg.(int))
			}
		}
	}

	for k := range g.stats {
		g.flush(k)
	}
}
开发者ID:jcw,项目名称:housemon,代码行数:31,代码来源:stats.go

示例4: Run

// Start listening and subscribing to MQTT.
func (w *MQTTSub) Run() {
	port := getInputOrConfig(w.Port, "MQTT_PORT")
	sock, err := net.Dial("tcp", port)
	flow.Check(err)
	client := mqtt.NewClientConn(sock)
	err = client.Connect("", "")
	flow.Check(err)

	for t := range w.In {
		topic := t.(string)
		glog.V(2).Infoln("mqtt-sub", topic)
		if strings.HasSuffix(topic, "/") {
			topic += "#" // if it looks like a prefix, append "#" for MQTT
		}
		client.Subscribe([]proto.TopicQos{{
			Topic: topic,
			Qos:   proto.QosAtMostOnce,
		}})
	}

	for m := range client.Incoming {
		payload := []byte(m.Payload.(proto.BytesPayload))
		// try to decode as JSON, but leave as []byte if that fails
		var any interface{}
		if err = json.Unmarshal(payload, &any); err != nil {
			any = payload
		}
		w.Out.Send(flow.Tag{m.TopicName, any})
	}
}
开发者ID:x4rMa,项目名称:jeebus,代码行数:31,代码来源:mqtt.go

示例5: dbGet

func dbGet(key string) (any interface{}) {
	glog.V(3).Infoln("get", key)
	data, err := db.Get([]byte(key), nil)
	if err == leveldb.ErrNotFound {
		return nil
	}
	flow.Check(err)
	err = json.Unmarshal(data, &any)
	flow.Check(err)
	return
}
开发者ID:TheDistractor,项目名称:jeebus,代码行数:11,代码来源:database.go

示例6: ParseDescription

// Parse description into a map of strings, set the "$" entry to a []byte value.
func ParseDescription(desc string) Map {
	// expects mime-type header followed by optional empty line and description
	b := bufio.NewReader(bytes.NewBufferString(desc + "\n\n"))
	header, err := textproto.NewReader(b).ReadMIMEHeader()
	flow.Check(err)
	t, err := ioutil.ReadAll(b)
	flow.Check(err)
	result := Map{"$": bytes.TrimSpace(t)}
	for k, v := range header {
		result[k] = strings.Join(v, "\n")
	}
	return result
}
开发者ID:x4rMa,项目名称:jeebus,代码行数:14,代码来源:all.go

示例7: Run

// Start reading filenames and emit a <file> tag followed by the decoded JSON.
func (w *ReadFileJSON) Run() {
	for m := range w.In {
		if name, ok := m.(string); ok {
			data, err := ioutil.ReadFile(name)
			flow.Check(err)
			w.Out.Send(flow.Tag{"<file>", name})
			var any interface{}
			err = json.Unmarshal(data, &any)
			flow.Check(err)
			m = any
		}
		w.Out.Send(m)
	}
}
开发者ID:jcw,项目名称:flow,代码行数:15,代码来源:gadgets.go

示例8: Run

// Start decoding smaRelay packets.
func (w *SmaRelay) Run() {
	var vec, prev [7]uint16
	for m := range w.In {
		if v, ok := m.([]byte); ok && len(v) >= 12 {
			buf := bytes.NewBuffer(v[1:])
			err := binary.Read(buf, binary.LittleEndian, &vec)
			flow.Check(err)
			result := map[string]int{
				"<reading>": 1,
				"acw":       int(vec[2]),
				"dcv1":      int(vec[3]),
				"dcv2":      int(vec[4]),
			}
			if vec[0] != prev[0] {
				result["yield"] = int(vec[0])
			}
			if vec[1] != prev[1] {
				result["total"] = int(vec[1])
			}
			if vec[2] != 0 {
				result["dcw1"] = int(vec[5])
				result["dcw2"] = int(vec[6])
			}
			copy(prev[:], vec[:])
			m = result
		}

		w.Out.Send(m)
	}
}
开发者ID:jcw,项目名称:housemon,代码行数:31,代码来源:smaRelay.go

示例9: Run

// Start decoding homePower packets.
func (w *HomePower) Run() {
	var vec, prev [6]uint16
	for m := range w.In {
		if v, ok := m.([]byte); ok && len(v) >= 12 {
			buf := bytes.NewBuffer(v[1:])
			err := binary.Read(buf, binary.LittleEndian, &vec)
			flow.Check(err)
			result := map[string]int{"<reading>": 1}
			if vec[0] != prev[0] {
				result["c1"] = int(vec[0])
				result["p1"] = time2watt(int(vec[1]))
			}
			if vec[2] != prev[2] {
				result["c2"] = int(vec[2])
				result["p2"] = time2watt(int(vec[3]))
			}
			if vec[4] != prev[4] {
				result["c3"] = int(vec[4])
				result["p3"] = time2watt(int(vec[5]))
			}
			copy(prev[:], vec[:])
			if len(result) == 1 {
				continue
			}
			m = result
		}

		w.Out.Send(m)
	}
}
开发者ID:jcw,项目名称:housemon,代码行数:31,代码来源:homePower.go

示例10: Run

// Start running the JavaScript engine.
func (w *JavaScript) Run() {
	if cmd, ok := <-w.Cmd; ok {
		// initial setup
		engine := otto.New()

		// define a callback for sending messages to Out
		engine.Set("emitOut", func(call otto.FunctionCall) otto.Value {
			out, err := call.Argument(0).Export()
			flow.Check(err)
			w.Out.Send(out)
			return otto.UndefinedValue()
		})

		// process the command input
		if _, err := engine.Run(cmd.(string)); err != nil {
			glog.Fatal(err)
		}

		// only start the processing loop if the "onIn" handler exists
		value, err := engine.Get("onIn")
		if err == nil && value.IsFunction() {
			for in := range w.In {
				engine.Call("onIn", nil, in)
			}
		}
	}
}
开发者ID:x4rMa,项目名称:jeebus,代码行数:28,代码来源:javascript.go

示例11: Run

// Start looking up node ID's in the node map.
func (w *NodeMap) Run() {

	defaultBand := 868 //TODO:Change this to input parameter

	nodeMap := map[NodeMapKey]string{}
	locations := map[NodeMapKey]string{}
	for m := range w.Info {
		f := strings.Split(m.(string), ",")

		key := NodeMapKey{}
		if ok, err := key.Unmarshal(f[0]); !ok {
			flow.Check(err)
		}

		//for the case where the default data has not been changed as in:
		// { data: "RFg5i2,roomNode,boekenkast JC",  to: "nm.Info" }
		//this will automatically be incorporated into the defaultBand network.
		if key.band == 0 {
			key.band = defaultBand
		}

		nodeMap[key] = f[1]

		if len(f) > 2 {
			locations[key] = f[2]
		}
	}

	key := NodeMapKey{}
	for m := range w.In {
		w.Out.Send(m)

		if data, ok := m.(map[string]int); ok {

			switch {
			case data["<RF12demo>"] > 0:
				key.group = data["group"]
				key.band = data["band"]
			case data["<node>"] > 0:
				key.node = data["<node>"]
				if loc, ok := locations[key]; ok {
					w.Out.Send(flow.Tag{"<location>", loc})
				} else {
					w.Missing.Send(key)
					//fmt.Printf("Location NOT found:%+v", key)
				}
				if tag, ok := nodeMap[key]; ok {
					w.Out.Send(flow.Tag{"<dispatch>", tag})
				} else {
					//fmt.Printf("NodeMap NOT found:%+v", key)
					w.Missing.Send(key)
					w.Out.Send(flow.Tag{"<dispatch>", ""})
				}
			}
		}
	}
}
开发者ID:TheDistractor,项目名称:flow-ext,代码行数:58,代码来源:nodemap.go

示例12: dbPut

func dbPut(key string, value interface{}) {
	glog.V(2).Infoln("put", key, value)
	if value != nil {
		data, err := json.Marshal(value)
		flow.Check(err)
		db.Put([]byte(key), data, nil)
	} else {
		db.Delete([]byte(key), nil)
	}
}
开发者ID:TheDistractor,项目名称:jeebus,代码行数:10,代码来源:database.go

示例13: parseFbp

func (w *FbpParser) parseFbp(lines []string) {
	if len(lines) > 0 {
		fbp := &Fbp{Buffer: strings.Join(lines, "\n")}
		fbp.Init()
		err := fbp.Parse()
		flow.Check(err)
		// fbp.Execute()
		w.Out.Send(true)
		// fbp.PrintSyntaxTree()
	}
}
开发者ID:x4rMa,项目名称:jeebus,代码行数:11,代码来源:fbp.go

示例14: openDatabase

func openDatabase() {
	// opening the database takes time, make sure we don't re-enter this code
	once.Do(func() {
		dbPath := flow.Config["DATA_DIR"]
		if dbPath == "" {
			glog.Fatalln("cannot open database, DATA_DIR not set")
		}
		ldb, err := leveldb.OpenFile(dbPath, nil)
		flow.Check(err)
		db = ldb
	})
}
开发者ID:TheDistractor,项目名称:jeebus,代码行数:12,代码来源:database.go

示例15: Run

func (w *wsHead) Run() {
	for {
		var msg interface{}
		err := websocket.JSON.Receive(w.ws, &msg)
		if err == io.EOF {
			break
		}
		flow.Check(err)
		if s, ok := msg.(string); ok {
			id := w.ws.Request().Header.Get("Sec-Websocket-Key")
			fmt.Println("msg <"+id[:4]+">:", s)
		} else {
			w.Out.Send(msg)
		}
	}
}
开发者ID:TheDistractor,项目名称:jeebus,代码行数:16,代码来源:http.go


注:本文中的github.com/jcw/flow.Check函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。