mirror of
				https://github.com/fluffle/goirc
				synced 2025-11-04 03:58:03 +00:00 
			
		
		
		
	Syntax highlighting
Markdown knows about golang, so use that for the code sample
This commit is contained in:
		
							parent
							
								
									8be75dd9d4
								
							
						
					
					
						commit
						2feca0e68f
					
				
					 1 changed files with 39 additions and 38 deletions
				
			
		
							
								
								
									
										77
									
								
								README.md
									
										
									
									
									
								
							
							
						
						
									
										77
									
								
								README.md
									
										
									
									
									
								
							| 
						 | 
					@ -15,52 +15,53 @@ old `go1` API.
 | 
				
			||||||
### Using the framework
 | 
					### Using the framework
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Synopsis:
 | 
					Synopsis:
 | 
				
			||||||
 | 
					```go
 | 
				
			||||||
 | 
					package main
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	package main
 | 
					import (
 | 
				
			||||||
 | 
						"fmt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	import (
 | 
						irc "github.com/fluffle/goirc/client"
 | 
				
			||||||
		"fmt"
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		irc "github.com/fluffle/goirc/client"
 | 
					func main() {
 | 
				
			||||||
	)
 | 
						// Creating a simple IRC client is simple.
 | 
				
			||||||
 | 
						c := irc.SimpleClient("nick")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	func main() {
 | 
						// Or, create a config and fiddle with it first:
 | 
				
			||||||
		// Creating a simple IRC client is simple.
 | 
						cfg := irc.NewConfig("nick")
 | 
				
			||||||
		c := irc.SimpleClient("nick")
 | 
						cfg.SSL = true
 | 
				
			||||||
 | 
						cfg.Server = "irc.freenode.net:7000"
 | 
				
			||||||
 | 
						cfg.NewNick = func(n string) string { return n + "^" }
 | 
				
			||||||
 | 
						c = irc.Client(cfg)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Or, create a config and fiddle with it first:
 | 
						// Add handlers to do things here!
 | 
				
			||||||
		cfg := irc.NewConfig("nick")
 | 
						// e.g. join a channel on connect.
 | 
				
			||||||
		cfg.SSL = true
 | 
						c.HandleFunc(irc.CONNECTED,
 | 
				
			||||||
		cfg.Server = "irc.freenode.net:7000"
 | 
							func(conn *irc.Conn, line *irc.Line) { conn.Join("#channel") })
 | 
				
			||||||
		cfg.NewNick = func(n string) string { return n + "^" }
 | 
						// And a signal on disconnect
 | 
				
			||||||
		c = irc.Client(cfg)
 | 
						quit := make(chan bool)
 | 
				
			||||||
 | 
						c.HandleFunc(irc.DISCONNECTED,
 | 
				
			||||||
 | 
							func(conn *irc.Conn, line *irc.Line) { quit <- true })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// Add handlers to do things here!
 | 
						// Tell client to connect.
 | 
				
			||||||
		// e.g. join a channel on connect.
 | 
						if err := c.Connect(); err != nil {
 | 
				
			||||||
		c.HandleFunc(irc.CONNECTED,
 | 
							fmt.Printf("Connection error: %s\n", err.Error())
 | 
				
			||||||
			func(conn *irc.Conn, line *irc.Line) { conn.Join("#channel") })
 | 
					 | 
				
			||||||
		// And a signal on disconnect
 | 
					 | 
				
			||||||
		quit := make(chan bool)
 | 
					 | 
				
			||||||
		c.HandleFunc(irc.DISCONNECTED,
 | 
					 | 
				
			||||||
			func(conn *irc.Conn, line *irc.Line) { quit <- true })
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Tell client to connect.
 | 
					 | 
				
			||||||
		if err := c.Connect(); err != nil {
 | 
					 | 
				
			||||||
			fmt.Printf("Connection error: %s\n", err.Error())
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// With a "simple" client, set Server before calling Connect...
 | 
					 | 
				
			||||||
		c.Config().Server = "irc.freenode.net"
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// ... or, use ConnectTo instead.
 | 
					 | 
				
			||||||
		if err := c.ConnectTo("irc.freenode.net"); err != nil {
 | 
					 | 
				
			||||||
			fmt.Printf("Connection error: %s\n", err.Error())
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		// Wait for disconnect
 | 
					 | 
				
			||||||
		<-quit
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// With a "simple" client, set Server before calling Connect...
 | 
				
			||||||
 | 
						c.Config().Server = "irc.freenode.net"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// ... or, use ConnectTo instead.
 | 
				
			||||||
 | 
						if err := c.ConnectTo("irc.freenode.net"); err != nil {
 | 
				
			||||||
 | 
							fmt.Printf("Connection error: %s\n", err.Error())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Wait for disconnect
 | 
				
			||||||
 | 
						<-quit
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
The test client provides a good (if basic) example of how to use the framework.
 | 
					The test client provides a good (if basic) example of how to use the framework.
 | 
				
			||||||
Reading `client/handlers.go` gives a more in-depth look at how handlers can be
 | 
					Reading `client/handlers.go` gives a more in-depth look at how handlers can be
 | 
				
			||||||
written. Commands to be sent to the server (e.g. PRIVMSG) are methods of the
 | 
					written. Commands to be sent to the server (e.g. PRIVMSG) are methods of the
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue