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


Golang flow.NewCircuit函数代码示例

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


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

示例1: ExampleNestedCircuit

func ExampleNestedCircuit() {
	g1 := flow.NewCircuit()
	g1.Add("p", "Pipe")
	g1.Label("In", "p.In")
	g1.Label("Out", "p.Out")

	g2 := flow.NewCircuit()
	g2.Add("p", "Pipe")
	g2.Label("In", "p.In")
	g2.Label("Out", "p.Out")

	g3 := flow.NewCircuit()
	g3.AddCircuitry("g1", g1)
	g3.AddCircuitry("g2", g2)
	g3.Connect("g1.Out", "g2.In", 0)
	g3.Label("In", "g1.In")
	g3.Label("Out", "g2.Out")

	g := flow.NewCircuit()
	g.Add("p1", "Pipe")
	g.AddCircuitry("g", g3)
	g.Add("p2", "Pipe")
	g.Connect("p1.Out", "g.In", 0)
	g.Connect("g.Out", "p2.In", 0)
	g.Feed("p1.In", "abc")
	g.Feed("p1.In", "def")
	g.Feed("p1.In", "ghi")
	g.Run()
	// Output:
	// Lost string: abc
	// Lost string: def
	// Lost string: ghi
}
开发者ID:TheDistractor,项目名称:flow,代码行数:33,代码来源:flow_test.go

示例2: init

func init() {
	// Waiter can be defined in terms of other gadgets, but where to put this?
	flow.Registry["Waiter"] = func() flow.Circuitry {
		c := flow.NewCircuit()
		c.Add("s", "Sink")
		c.Add("c", "Concat3")
		c.Connect("s.Out", "c.In1", 0)
		c.Label("Gate", "s.In")
		c.Label("In", "c.In2")
		c.Label("Out", "c.Out")
		return c
	}
	// Attach returns items from a database range and follows up with updates.
	flow.Registry["Attach"] = func() flow.Circuitry {
		c := flow.NewCircuit()
		c.Add("fan", "FanOut")
		c.Add("sub", "DataSub")
		c.Add("tag", "AddTag")
		c.Add("db", "LevelDB")
		c.Add("cat", "Concat3")
		c.Connect("fan.Out:sub", "sub.In", 0)
		c.Connect("fan.Out:tag", "tag.In", 0)
		c.Connect("tag.Out", "db.In", 0)
		c.Connect("db.Out", "cat.In1", 0)
		c.Connect("sub.Out", "cat.In3", 100) // with buffering
		c.Feed("tag.Tag", "<range>")
		c.Feed("cat.In2", flow.Tag{"<sync>", "attach"})
		c.Label("In", "fan.In")
		c.Label("Out", "cat.Out")
		return c
	}

	flow.Registry["help"] = func() flow.Circuitry { return new(helpCmd) }
	Help["help"] = `Show this help text with a list of commands.`

	flow.Registry["info"] = func() flow.Circuitry { return new(infoCmd) }
	Help["info"] = `Show the list of registered gadgets and circuits.`

	// database
	Help["dbdump"] = `Dump (part of) the contents of the database to stdout.`
	Help["dbexport"] = `Export (part of) the database as JSON to stdout.`
	Help["dbimport"] = `Import a JSON file, as generated by "export".`
	Help["dbget"] = `Get one entry from the database.`
	Help["dbput"] = `Store or delete an entry in the database.`
	Help["dbkeys"] = `List the set of (sub-) keys in the database.`
	// network
	Help["mqttpub"] = `Publish a message on a topic using MQTT.`
	Help["mqttsub"] = `Subscribe to one or more topics using MQTT.`
}
开发者ID:x4rMa,项目名称:jeebus,代码行数:49,代码来源:all.go

示例3: handleRpcRequest

func (g *RpcHandler) handleRpcRequest(cmd string, seq int, args []interface{}) (reply []interface{}) {
	glog.Infoln("rpc", cmd, args)
	if cmd == "echo" {
		return []interface{}{seq, "", args}
	}

	defer func() {
		errMsg := ""
		switch v := recover().(type) {
		case nil:
			// no error
		case string:
			errMsg = v
		case error:
			errMsg = v.Error()
		default:
			errMsg = fmt.Sprintf("%T: %v", v, v)
		}
		if errMsg != "" {
			glog.Warningln("rpc-error", cmd, args, errMsg)
			reply = []interface{}{seq, errMsg}
		}
	}()

	// FIXME: hack alert, this is special-cased to deal with the database
	switch cmd {
	case "db-get":
		result := database.Get(args[0].(string))
		return []interface{}{seq, "", result}
	case "db-keys":
		result := database.Keys(args[0].(string))
		return []interface{}{seq, "", result}
	case "db-put":
		var value interface{}
		if len(args) > 1 {
			value = args[1]
		}
		database.Put(args[0].(string), value)
		return nil
	}

	// if there's registered circuit for cmd, set it up and return as a stream
	if _, ok := flow.Registry[cmd]; ok && len(args) == 1 {
		c := flow.NewCircuit()
		c.Add("x", cmd)
		c.AddCircuitry("y", &streamRpcResults{seqNum: seq, replies: g})
		c.Connect("x.Out", "y.In", 0)
		for k, v := range args[0].(map[string]interface{}) {
			c.Feed("x."+k, tryToConvertToTag(v))
		}
		go func() {
			defer flow.DontPanic()
			c.Run()
			g.Out.Send([]interface{}{seq, false}) // end streaming
		}()
		return []interface{}{seq, true} // start streaming
	}

	panic(cmd + "?")
}
开发者ID:x4rMa,项目名称:jeebus,代码行数:60,代码来源:rpc.go

示例4: ExampleLevelDB

func ExampleLevelDB() {
	g := flow.NewCircuit()
	g.Add("db", "LevelDB")
	g.Feed("db.In", flow.Tag{"a/b", "123"})
	g.Feed("db.In", flow.Tag{"a/c", "456"})
	g.Feed("db.In", flow.Tag{"<get>", "a/b"})
	g.Feed("db.In", flow.Tag{"<range>", "a/"})
	g.Feed("db.In", flow.Tag{"<keys>", "a/"})
	g.Feed("db.In", flow.Tag{"a/b", nil})
	g.Feed("db.In", flow.Tag{"<get>", "a/b"})
	g.Feed("db.In", flow.Tag{"<keys>", "a/"})
	g.Feed("db.In", flow.Tag{"a/c", nil})
	g.Run()
	// Output:
	// Lost flow.Tag: {<get> a/b}
	// Lost string: 123
	// Lost flow.Tag: {<range> a/}
	// Lost flow.Tag: {a/b 123}
	// Lost flow.Tag: {a/c 456}
	// Lost flow.Tag: {<keys> a/}
	// Lost string: b
	// Lost string: c
	// Lost flow.Tag: {<get> a/b}
	// Lost <nil>: <nil>
	// Lost flow.Tag: {<keys> a/}
	// Lost string: c
}
开发者ID:x4rMa,项目名称:jeebus,代码行数:27,代码来源:database_test.go

示例5: ExampleTimeStamp

func ExampleTimeStamp() {
	g := flow.NewCircuit()
	g.Add("t", "TimeStamp")
	g.Run()
	g.Feed("t.In", "abc")
	// produces two lines, the timestamp followed by the "abc" string
}
开发者ID:jcw,项目名称:flow,代码行数:7,代码来源:gadgets_test.go

示例6: wsHandler

//wsHandler now used ws.Config as protocol handshake now supported
func wsHandler(ws *websocket.Conn) {
	defer flow.DontPanic()
	defer ws.Close()

	hdr := ws.Request().Header

	// keep track of connected clients for reload broadcasting
	id := hdr.Get("Sec-Websocket-Key")
	wsClients[id] = ws
	defer delete(wsClients, id)

	// the protocol name is used as tag to locate the proper circuit
	//lightbulb: We use the protocol provided by ws, rather than header, as that contains server accepted value
	tag := ws.Config().Protocol[0]

	fmt.Println("WS Protocol Selected:", tag)

	if tag == "" { //no specific protocol, lets opt for 'default' which just echoes (or return with no circuit!)
		tag = "default"
	}

	g := flow.NewCircuit()
	g.AddCircuitry("head", &wsHead{ws: ws})
	g.Add("ws", "WebSocket-"+tag) //the client has negotiated this support
	g.AddCircuitry("tail", &wsTail{ws: ws})
	g.Connect("head.Out", "ws.In", 0)
	g.Connect("ws.Out", "tail.In", 0)
	g.Run()
}
开发者ID:TheDistractor,项目名称:jeebus,代码行数:30,代码来源:http.go

示例7: ExampleClock

func ExampleClock() {
	// The following example never ends.
	g := flow.NewCircuit()
	g.Add("c", "Clock")
	g.Feed("c.In", "1s")
	g.Run()
}
开发者ID:jcw,项目名称:flow,代码行数:7,代码来源:gadgets_test.go

示例8: ExampleMQTTSub

func ExampleMQTTSub() {
	// The following example requires an MQTT server running on std port 1883.
	g := flow.NewCircuit()
	g.Add("s", "MQTTSub")
	g.Feed("s.Port", ":1883")
	g.Feed("s.In", "#")
	g.Run()
}
开发者ID:x4rMa,项目名称:jeebus,代码行数:8,代码来源:mqtt_test.go

示例9: ExampleMQTTPub

func ExampleMQTTPub() {
	// The following example requires an MQTT server running on std port 1883.
	g := flow.NewCircuit()
	g.Add("p", "MQTTPub")
	g.Feed("p.Port", ":1883")
	g.Feed("p.In", flow.Tag{"Hello", "world"})
	g.Run()
}
开发者ID:x4rMa,项目名称:jeebus,代码行数:8,代码来源:mqtt_test.go

示例10: ExamplePrinter

func ExamplePrinter() {
	g := flow.NewCircuit()
	g.Add("p", "Printer")
	g.Feed("p.In", "hello")
	g.Run()
	// Output:
	// hello
}
开发者ID:jcw,项目名称:flow,代码行数:8,代码来源:gadgets_test.go

示例11: ExamplePipe

func ExamplePipe() {
	g := flow.NewCircuit()
	g.Add("p", "Pipe")
	g.Feed("p.In", 123)
	g.Run()
	// Output:
	// Lost int: 123
}
开发者ID:jcw,项目名称:flow,代码行数:8,代码来源:pipe_test.go

示例12: ExampleCounter

func ExampleCounter() {
	g := flow.NewCircuit()
	g.Add("c", "Counter")
	g.Feed("c.In", nil)
	g.Run()
	// Output:
	// Lost int: 1
}
开发者ID:jcw,项目名称:flow,代码行数:8,代码来源:gadgets_test.go

示例13: Run

func (g *pubCmd) Run() {
	c := flow.NewCircuit()
	c.Add("c", "CmdLine")
	c.Add("p", "MQTTPub")
	c.Connect("a.Out", "p.In", 0)
	c.Feed("c.Type", "skip,tags,json")
	c.Feed("p.Port", ":1883")
	c.Run()
}
开发者ID:x4rMa,项目名称:jeebus,代码行数:9,代码来源:mqttcmds.go

示例14: ExampleReadFileJSON

func ExampleReadFileJSON() {
	g := flow.NewCircuit()
	g.Add("r", "ReadFileJSON")
	g.Feed("r.In", "example.json")
	g.Run()
	// Output:
	// Lost flow.Tag: {<file> example.json}
	// Lost map[string]interface {}: map[a:123 b:[3 4 5] c:true]
}
开发者ID:jcw,项目名称:flow,代码行数:9,代码来源:gadgets_test.go

示例15: ExampleBinaryFill

func ExampleBinaryFill() {
	g := flow.NewCircuit()
	g.Add("f", "BinaryFill")
	g.Feed("f.In", []byte("abcdef"))
	g.Feed("f.Len", 5)
	g.Run()
	// Output:
	// Lost []uint8: [97 98 99 100 101 102 255 255 255 255]
}
开发者ID:TheDistractor,项目名称:housemon,代码行数:9,代码来源:utils_test.go


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